puppet_generator 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/.gitignore +17 -0
  2. data/.rdebugrc +7 -0
  3. data/.rspec +2 -0
  4. data/.simplecov +8 -0
  5. data/.travis.yml +6 -0
  6. data/.yardopts +5 -0
  7. data/CONTRIBUTING.md +8 -0
  8. data/Gemfile +34 -0
  9. data/LICENSE.md +22 -0
  10. data/README.DEVELOPER.md +11 -0
  11. data/README.md +477 -0
  12. data/Rakefile +3 -0
  13. data/TODO.md +2 -0
  14. data/bin/ppgen +16 -0
  15. data/cucumber.yml +2 -0
  16. data/features/generate_file_definition.feature +357 -0
  17. data/features/generate_module_directories.feature +36 -0
  18. data/features/generate_package_definition.feature +206 -0
  19. data/features/generate_role_definitions.feature +64 -0
  20. data/features/generate_user_definition.feature +193 -0
  21. data/features/list.feature +22 -0
  22. data/features/log_actions.feature +93 -0
  23. data/features/step_definitions.rb +3 -0
  24. data/features/support/env.rb +7 -0
  25. data/features/tasks.feature +25 -0
  26. data/gemfiles/Gemfile.default +34 -0
  27. data/gemfiles/Gemfile.travis +17 -0
  28. data/lib/puppet_generator/actions/copy_files_to_module_directory.rb +23 -0
  29. data/lib/puppet_generator/actions/null.rb +9 -0
  30. data/lib/puppet_generator/api.rb +108 -0
  31. data/lib/puppet_generator/definition.rb +10 -0
  32. data/lib/puppet_generator/entry_converters/file.rb +9 -0
  33. data/lib/puppet_generator/entry_converters/package.rb +9 -0
  34. data/lib/puppet_generator/entry_converters/role.rb +9 -0
  35. data/lib/puppet_generator/entry_converters/user.rb +9 -0
  36. data/lib/puppet_generator/exceptions.rb +104 -0
  37. data/lib/puppet_generator/export_filters/build_role_includes_for_directory.rb +35 -0
  38. data/lib/puppet_generator/export_filters/filesystem_attributes.rb +57 -0
  39. data/lib/puppet_generator/export_filters/null.rb +9 -0
  40. data/lib/puppet_generator/exporters/directory.rb +23 -0
  41. data/lib/puppet_generator/exporters/file.rb +17 -0
  42. data/lib/puppet_generator/exporters/stdout.rb +16 -0
  43. data/lib/puppet_generator/import_filters/null.rb +9 -0
  44. data/lib/puppet_generator/import_filters/passwd.rb +22 -0
  45. data/lib/puppet_generator/import_filters/yaml.rb +20 -0
  46. data/lib/puppet_generator/importers/directory.rb +21 -0
  47. data/lib/puppet_generator/importers/file.rb +17 -0
  48. data/lib/puppet_generator/importers/stdin.rb +16 -0
  49. data/lib/puppet_generator/logger.rb +62 -0
  50. data/lib/puppet_generator/main.rb +36 -0
  51. data/lib/puppet_generator/middleware/apply_export_filters.rb +33 -0
  52. data/lib/puppet_generator/middleware/check_for_empty_source.rb +16 -0
  53. data/lib/puppet_generator/middleware/configure_logging.rb +30 -0
  54. data/lib/puppet_generator/middleware/create_module_directories.rb +42 -0
  55. data/lib/puppet_generator/middleware/create_output.rb +46 -0
  56. data/lib/puppet_generator/middleware/create_puppet_object_from_entry.rb +24 -0
  57. data/lib/puppet_generator/middleware/enable_debugging_libraries.rb +15 -0
  58. data/lib/puppet_generator/middleware/execute_actions.rb +34 -0
  59. data/lib/puppet_generator/middleware/filter_imported_data.rb +22 -0
  60. data/lib/puppet_generator/middleware/handle_errors.rb +62 -0
  61. data/lib/puppet_generator/middleware/output_debug_information_for_models.rb +21 -0
  62. data/lib/puppet_generator/middleware/read_input.rb +27 -0
  63. data/lib/puppet_generator/models/action.rb +36 -0
  64. data/lib/puppet_generator/models/base.rb +115 -0
  65. data/lib/puppet_generator/models/class_based_model.rb +56 -0
  66. data/lib/puppet_generator/models/entry_converter.rb +39 -0
  67. data/lib/puppet_generator/models/error_message.rb +60 -0
  68. data/lib/puppet_generator/models/export_filter.rb +44 -0
  69. data/lib/puppet_generator/models/exporter.rb +51 -0
  70. data/lib/puppet_generator/models/filesystem_based_model.rb +63 -0
  71. data/lib/puppet_generator/models/import_filter.rb +44 -0
  72. data/lib/puppet_generator/models/importer.rb +52 -0
  73. data/lib/puppet_generator/models/logger.rb +11 -0
  74. data/lib/puppet_generator/models/template.rb +120 -0
  75. data/lib/puppet_generator/puppet_helper.rb +19 -0
  76. data/lib/puppet_generator/puppet_objects/file.rb +29 -0
  77. data/lib/puppet_generator/puppet_objects/package.rb +24 -0
  78. data/lib/puppet_generator/puppet_objects/role.rb +27 -0
  79. data/lib/puppet_generator/puppet_objects/user.rb +27 -0
  80. data/lib/puppet_generator/setup/bare.rb +25 -0
  81. data/lib/puppet_generator/setup/default_actions.rb +9 -0
  82. data/lib/puppet_generator/setup/default_entry_converter.rb +8 -0
  83. data/lib/puppet_generator/setup/default_error_messages.rb +10 -0
  84. data/lib/puppet_generator/setup/default_export_filter.rb +9 -0
  85. data/lib/puppet_generator/setup/default_exporter.rb +11 -0
  86. data/lib/puppet_generator/setup/default_import_filter.rb +10 -0
  87. data/lib/puppet_generator/setup/default_importer.rb +10 -0
  88. data/lib/puppet_generator/setup/file.rb +29 -0
  89. data/lib/puppet_generator/setup/module.rb +22 -0
  90. data/lib/puppet_generator/setup/package.rb +27 -0
  91. data/lib/puppet_generator/setup/role.rb +28 -0
  92. data/lib/puppet_generator/setup/user.rb +27 -0
  93. data/lib/puppet_generator/task.rb +39 -0
  94. data/lib/puppet_generator/ui/commandline_parser_helper.rb +31 -0
  95. data/lib/puppet_generator/ui/create.rb +59 -0
  96. data/lib/puppet_generator/ui/runner.rb +23 -0
  97. data/lib/puppet_generator/ui/tasks.rb +16 -0
  98. data/lib/puppet_generator/version.rb +4 -0
  99. data/lib/puppet_generator.rb +79 -0
  100. data/puppet_generator.gemspec +35 -0
  101. data/rakefiles/default.rake +3 -0
  102. data/rakefiles/travis.rake +3 -0
  103. data/script/console +8 -0
  104. data/script/terminal +16 -0
  105. data/spec/examples/actions/missing_method.rb +7 -0
  106. data/spec/examples/apply_export_filters/file.txt +0 -0
  107. data/spec/examples/entry_converters/missing_method.rb +7 -0
  108. data/spec/examples/execute_actions/file.txt +0 -0
  109. data/spec/examples/export_filter/invalid_filter_1.rb +8 -0
  110. data/spec/examples/export_filter/invalid_filter_2.rb +7 -0
  111. data/spec/examples/export_filter/missing_method.rb +7 -0
  112. data/spec/examples/exporter/missing_method.rb +7 -0
  113. data/spec/examples/exporter/test.d/.gitkeep +0 -0
  114. data/spec/examples/exporter/test_file.txt +1 -0
  115. data/spec/examples/import_filter/forbidden_keyword.rb +0 -0
  116. data/spec/examples/import_filter/invalid_filter_1.rb +8 -0
  117. data/spec/examples/import_filter/invalid_filter_2.rb +7 -0
  118. data/spec/examples/import_filter/missing_method.rb +7 -0
  119. data/spec/examples/importer/missing_method.rb +7 -0
  120. data/spec/examples/importer/test.d/.gitkeep +0 -0
  121. data/spec/examples/importer/test_file.txt +1 -0
  122. data/spec/examples/templates/invalid_template.pp.erb +1 -0
  123. data/spec/examples/templates/missing_method.rb +7 -0
  124. data/spec/export_filters/build_role_includes_for_directory_spec.rb +39 -0
  125. data/spec/middleware/apply_export_filters_spec.rb +45 -0
  126. data/spec/middleware/execute_actions_spec.rb +44 -0
  127. data/spec/middleware/handle_errors_spec.rb +12 -0
  128. data/spec/models/action_spec.rb +37 -0
  129. data/spec/models/entry_converter_spec.rb +59 -0
  130. data/spec/models/error_message_spec.rb +78 -0
  131. data/spec/models/export_filter_spec.rb +36 -0
  132. data/spec/models/exporter_spec.rb +71 -0
  133. data/spec/models/import_filter_spec.rb +33 -0
  134. data/spec/models/importer_spec.rb +66 -0
  135. data/spec/models/template_spec.rb +47 -0
  136. data/spec/puppet_generator_spec.rb +7 -0
  137. data/spec/setup/role_spec.rb +22 -0
  138. data/spec/spec_helper.rb +10 -0
  139. data/spec/support/filesystem_helper.rb +12 -0
  140. data/spec/support/libraries.rb +10 -0
  141. data/spec/support/rspec_configuration.rb +5 -0
  142. data/templates/puppet/many_per_file/file.pp.erb +16 -0
  143. data/templates/puppet/many_per_file/package.pp.erb +10 -0
  144. data/templates/puppet/many_per_file/role.pp.erb +7 -0
  145. data/templates/puppet/many_per_file/user.pp.erb +23 -0
  146. data/templates/puppet/one_per_file/file.pp.erb +14 -0
  147. data/templates/puppet/one_per_file/package.pp.erb +8 -0
  148. data/templates/puppet/one_per_file/role.pp.erb +5 -0
  149. data/templates/puppet/one_per_file/user.pp.erb +21 -0
  150. metadata +374 -0
@@ -0,0 +1,193 @@
1
+ Feature: Generate user definitions
2
+
3
+ As a administrator
4
+ I need to write users definitions for puppet
5
+ In order to get those things up and running via puppet
6
+
7
+ Background: Process environment
8
+ Given I set the environment variables to:
9
+ | variable | value |
10
+ | PUPPET_GENERATOR_ENV | test |
11
+
12
+ Scenario: Existing Input File
13
+ Given a file named "input.txt" with:
14
+ """
15
+ asdf
16
+ """
17
+ When I successfully run `ppgen create user`
18
+ Then the file "out.d/asdf.pp" should contain:
19
+ """
20
+ class mymodule::asdf {
21
+ user {'asdf':
22
+ ensure => present,
23
+ managehome => true,
24
+ }
25
+ }
26
+
27
+ """
28
+
29
+ Scenario: Non Existing Input File
30
+ When I run `ppgen create user`
31
+ Then the exit status should be 8
32
+ And the stderr should contain "The file/directory \"input.txt\" does not exist."
33
+
34
+ Scenario: Input via Stdin
35
+ When I run `ppgen create user --source stdin` interactively
36
+ And I type "asdf"
37
+ And I close the stdin stream
38
+ Then the file "out.d/asdf.pp" should contain:
39
+ """
40
+ class mymodule::asdf {
41
+ user {'asdf':
42
+ ensure => present,
43
+ managehome => true,
44
+ }
45
+ }
46
+
47
+ """
48
+
49
+ Scenario: Multiple lines in input file
50
+ Given a file named "input.txt" with:
51
+ """
52
+ asdf
53
+ test123
54
+ """
55
+ When I successfully run `ppgen create user`
56
+ Then the file "out.d/asdf.pp" should contain:
57
+ """
58
+ class mymodule::asdf {
59
+ user {'asdf':
60
+ ensure => present,
61
+ managehome => true,
62
+ }
63
+ }
64
+
65
+ """
66
+ And the file "out.d/test123.pp" should contain:
67
+ """
68
+ class mymodule::test123 {
69
+ user {'test123':
70
+ ensure => present,
71
+ managehome => true,
72
+ }
73
+ }
74
+
75
+ """
76
+
77
+ Scenario: Module name given
78
+ Given a file named "input.txt" with:
79
+ """
80
+ asdf
81
+ """
82
+ When I successfully run `ppgen create user --module string1::string2`
83
+ Then the file "out.d/asdf.pp" should contain:
84
+ """
85
+ class string1::string2::asdf {
86
+ user {'asdf':
87
+ ensure => present,
88
+ managehome => true,
89
+ }
90
+ }
91
+
92
+ """
93
+
94
+ Scenario: Multiple lines in input file with one output file
95
+ Given a file named "input.txt" with:
96
+ """
97
+ asdf
98
+ test123
99
+ """
100
+ When I successfully run `ppgen create user --destination file:out.txt`
101
+ Then the file "out.txt" should contain:
102
+ """
103
+ class mymodule::myclass {
104
+ user {'asdf':
105
+ ensure => present,
106
+ managehome => true,
107
+ }
108
+ user {'test123':
109
+ ensure => present,
110
+ managehome => true,
111
+ }
112
+ }
113
+
114
+ """
115
+
116
+ Scenario: Output to stdout
117
+ Given a file named "input.txt" with:
118
+ """
119
+ asdf
120
+ """
121
+ When I successfully run `ppgen create user --destination stdout`
122
+ Then the stdout should contain:
123
+ """
124
+ class mymodule::myclass {
125
+ user {'asdf':
126
+ ensure => present,
127
+ managehome => true,
128
+ }
129
+ }
130
+
131
+ """
132
+
133
+ Scenario: Multiple lines in input file with one output file and one module definition
134
+ Given a file named "input.txt" with:
135
+ """
136
+ asdf
137
+ test123
138
+ """
139
+ When I successfully run `ppgen create user --destination file:out.txt --class test`
140
+ Then the file "out.txt" should contain:
141
+ """
142
+ class mymodule::test {
143
+ user {'asdf':
144
+ ensure => present,
145
+ managehome => true,
146
+ }
147
+ user {'test123':
148
+ ensure => present,
149
+ managehome => true,
150
+ }
151
+ }
152
+
153
+ """
154
+
155
+ Scenario: Using passwd
156
+ Given a file named "etc_passwd" with:
157
+ """
158
+ root:x:0:0:root:/root:/bin/bash
159
+ mail:x:8:12:mail:/var/spool/mail:/bin/false
160
+ """
161
+ When I successfully run `ppgen create user --source etc_passwd --destination file:out.txt --import-filter passwd`
162
+ Then the file "out.txt" should contain:
163
+ """
164
+ class mymodule::myclass {
165
+ user {'root':
166
+ ensure => present,
167
+ managehome => true,
168
+ uid => '0',
169
+ gid => '0',
170
+ home => '/root',
171
+ shell => '/bin/bash',
172
+ }
173
+ user {'mail':
174
+ ensure => present,
175
+ managehome => true,
176
+ uid => '8',
177
+ gid => '12',
178
+ home => '/var/spool/mail',
179
+ shell => '/bin/false',
180
+ }
181
+ }
182
+
183
+ """
184
+
185
+ Scenario: Using passwd with error
186
+ Given a file named "etc_passwd" with:
187
+ """
188
+ root:x:0:0:root:/root:/bin/bash
189
+ mail:
190
+ """
191
+ When I run `ppgen create user --source etc_passwd --destination file:out.txt --import-filter passwd`
192
+ Then the exit status should be 6
193
+ And the stderr should contain "The input is no passwd file valid for this use case"
@@ -0,0 +1,22 @@
1
+ Feature: List things
2
+
3
+ As a administrator
4
+ I want to get a list of available <resources>
5
+ In order to start in using the puppet generator
6
+
7
+ Background: Process environment
8
+ Given I set the environment variables to:
9
+ | variable | value |
10
+ | PUPPET_GENERATOR_ENV | test |
11
+
12
+ Scenario: List available ressources
13
+ When I successfully run `ppgen help list`
14
+ Then the output contains:
15
+ """
16
+ resources
17
+ exporter
18
+ importer
19
+ import_filter
20
+ export_filter
21
+ """
22
+
@@ -0,0 +1,93 @@
1
+ Feature: Logging
2
+
3
+ As a software developer
4
+ I need more feedback during development
5
+ In order to get those things up and running
6
+
7
+ Background: Process environment
8
+ Given I set the environment variables to:
9
+ | variable | value |
10
+ | PUPPET_GENERATOR_ENV | test |
11
+
12
+ Scenario: Plain Input File with verbose information
13
+ Given a file named "input.txt" with:
14
+ """
15
+ asdf
16
+ """
17
+ When I successfully run `ppgen create file --debug`
18
+ Then the stderr should contain:
19
+ """
20
+ Logging is configured with mode "debug".
21
+ """
22
+ Then the stderr should contain:
23
+ """
24
+ Available templates: file, file
25
+ """
26
+ Then the stderr should contain:
27
+ """
28
+ Available import filter: null, yaml
29
+ """
30
+ Then the stderr should contain:
31
+ """
32
+ Available export filter: filesystem_attributes, null
33
+ """
34
+ Then the stderr should contain:
35
+ """
36
+ Available actions: copy_files_to_module_directory, null
37
+ """
38
+ Then the stderr should contain:
39
+ """
40
+ Waiting for errors to occure. ;-)
41
+ """
42
+ Then the stderr should contain:
43
+ """
44
+ Read data from input "input.txt".
45
+ """
46
+ Then the stderr should contain:
47
+ """
48
+ Using importer "file" to read data.
49
+ """
50
+ Then the stderr should contain:
51
+ """
52
+ Count input lines: 1
53
+ """
54
+ Then the stderr should contain:
55
+ """
56
+ Checking if given source "input.txt" is empty.
57
+ """
58
+ Then the stderr should contain:
59
+ """
60
+ Filter the input with filter "null"
61
+ """
62
+ Then the stderr should contain:
63
+ """
64
+ Execute action "null" on output.
65
+ """
66
+ Then the stderr should contain:
67
+ """
68
+ Convert entries for command "file"
69
+ """
70
+ Then the stderr should contain:
71
+ """
72
+ Render template for channel "dir" and sink "out.d".
73
+ """
74
+
75
+ Scenario: Silent action
76
+ Given a file named "input.txt" with:
77
+ """
78
+ asdf
79
+ """
80
+ When I successfully run `ppgen create file --silent`
81
+ Then the output should contain:
82
+ """
83
+ """
84
+
85
+ Scenario: Normal action
86
+ Given a file named "input.txt" with:
87
+ """
88
+ asdf
89
+ """
90
+ When I successfully run `ppgen create file`
91
+ Then the output should contain:
92
+ """
93
+ """
@@ -0,0 +1,3 @@
1
+ Before do
2
+ @aruba_timeout_seconds = 6
3
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH << File.expand_path( '../../../lib' , __FILE__ )
2
+
3
+ require 'pry' unless ENV['TRAVIS_CI'] == 'true'
4
+ require 'aruba/cucumber'
5
+
6
+ #require 'simplecov'
7
+ #SimpleCov.start
@@ -0,0 +1,25 @@
1
+ Feature: Use tasks to make usage easier
2
+
3
+ As a administrator
4
+ I need to use the puppet_generator a lot
5
+ In order to get those things up and running via puppet
6
+
7
+ Background: Process environment
8
+ Given I set the environment variables to:
9
+ | variable | value |
10
+ | PUPPET_GENERATOR_ENV | test |
11
+
12
+ Scenario: Scan module
13
+ Given a directory named "test"
14
+ And a directory named "test/dir1"
15
+ And an empty file named "test/dir1/file1.pp"
16
+ And an empty file named "test/dir1/file2.pp"
17
+ When I successfully run `ppgen tasks create_roles_in_directory --source test --destination dir:./`
18
+ Then the file "test/dir1.pp" should contain:
19
+ """
20
+ class mymodule::dir1 {
21
+ include mymodule::dir1::file1
22
+ include mymodule::dir1::file2
23
+ }
24
+
25
+ """
@@ -0,0 +1,34 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'fedux_org-stdlib', branch: 'master'
4
+
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'simplecov'
11
+ gem 'aruba', git: 'https://github.com/maxmeyer/aruba.git', branch: 'puppet_generator'
12
+ gem 'fuubar'
13
+ gem 'ffaker'
14
+ gem 'cucumber'
15
+ end
16
+
17
+ group :documentation do
18
+ gem 'yard'
19
+ gem 'redcarpet'
20
+ gem 'github-markup'
21
+ end
22
+
23
+ group :development do
24
+ gem 'tmrb'
25
+ gem 'debugger'
26
+ gem 'pry'
27
+ gem 'pry-doc'
28
+ gem 'pry-debugger'
29
+ gem 'debugger-completion'
30
+ gem 'awesome_print'
31
+ gem 'travis-lint'
32
+ gem 'fuubar'
33
+ gem 'churn'
34
+ end
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ gem 'fuubar'
9
+ gem 'aruba', git: 'https://github.com/maxmeyer/aruba.git', branch: 'puppet_generator'
10
+ gem 'cucumber'
11
+ end
12
+
13
+ group :documentation do
14
+ gem 'yard'
15
+ gem 'redcarpet'
16
+ gem 'github-markup'
17
+ end
@@ -0,0 +1,23 @@
1
+ module PuppetGenerator
2
+ module Actions
3
+ class CopyFilesToModuleDirectory
4
+ def run( task , data )
5
+ src = data.collect { |e| e[:name] }
6
+ dst = File.join( task.meta[:module] , 'files')
7
+
8
+ FileUtils.mkdir_p dst
9
+ FileUtils.cp_r src , dst
10
+
11
+ data.collect { |e| e[:source] = make_source( task.meta[:module] , e[:name]) ; e }
12
+ rescue
13
+ raise Exceptions::ErrorDuringCopyFiles
14
+ end
15
+
16
+ private
17
+
18
+ def make_source(module_name, src)
19
+ "puppet:///modules/#{module_name}/#{ src.sub( %r[^/], '' ) }"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module Actions
3
+ class Null
4
+ def run( task , data )
5
+ data
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,108 @@
1
+ module PuppetGenerator
2
+ class Api
3
+
4
+ private
5
+
6
+ def pre_stack
7
+ ::Middleware::Builder.new do
8
+ use PuppetGenerator::Middleware::EnableDebuggingLibraries
9
+ use PuppetGenerator::Middleware::ConfigureLogging
10
+ end
11
+ end
12
+
13
+ def default_creator_stack
14
+ ::Middleware::Builder.new do
15
+ use PuppetGenerator::Middleware::OutputDebugInformationForModels
16
+ use PuppetGenerator::Middleware::HandleErrors
17
+ use PuppetGenerator::Middleware::ReadInput
18
+ use PuppetGenerator::Middleware::CheckForEmptySource
19
+ use PuppetGenerator::Middleware::FilterImportedData
20
+ use PuppetGenerator::Middleware::ApplyExportFilters
21
+ use PuppetGenerator::Middleware::ExecuteActions
22
+ use PuppetGenerator::Middleware::CreatePuppetObjectFromEntry
23
+ use PuppetGenerator::Middleware::CreateOutput
24
+ end
25
+ end
26
+
27
+ def _generate_definition(options, setup_klass, startup_message)
28
+ task = _setup options, setup_klass
29
+ pre_stack.call(task)
30
+
31
+ run_with_messages startup_message: startup_message do
32
+ default_creator_stack.call(task)
33
+ end
34
+ end
35
+
36
+ def _setup(options, klass)
37
+ s = klass.new(options)
38
+ s.setup_environment
39
+
40
+ s.create_task
41
+ end
42
+
43
+ public
44
+
45
+ def generate_package_definition(options)
46
+ _generate_definition options, Setup::Package, "Generating puppet definitions for type \"package\"."
47
+ end
48
+
49
+ def generate_file_definition(options)
50
+ _generate_definition options, Setup::File, "Generating puppet definitions for type \"file\"."
51
+ end
52
+
53
+ def generate_user_definition(options)
54
+ _generate_definition options, Setup::User, "Generating puppet definitions for type \"user\"."
55
+ end
56
+
57
+ def generate_role_definition(options)
58
+ _generate_definition options, Setup::Role, "Generating puppet definitions for type \"role\"."
59
+ end
60
+
61
+ def generate_module(options)
62
+ task = _setup options, Setup::Module
63
+
64
+ stack = ::Middleware::Builder.new do
65
+ use PuppetGenerator::Middleware::OutputDebugInformationForModels
66
+ use PuppetGenerator::Middleware::HandleErrors
67
+ use PuppetGenerator::Middleware::CreateModuleDirectories
68
+ end
69
+
70
+ pre_stack.call(task)
71
+
72
+ run_with_messages startup_message: "Generating files and directories to build a module." do
73
+ stack.call(task)
74
+ end
75
+ end
76
+
77
+ def output_error_messages(options)
78
+ task = Task.new(options, :error_message)
79
+
80
+ stack = ::Middleware::Builder.new do
81
+ use PuppetGenerator::Middleware::OutputDebugInformationForModels
82
+ use PuppetGenerator::Middleware::HandleErrors
83
+ use PuppetGenerator::Middleware::CreateOutput
84
+ end
85
+
86
+ pre_stack.call(task)
87
+
88
+ run_with_messages do
89
+ stack.call(task)
90
+ end
91
+ end
92
+
93
+
94
+ private
95
+
96
+ def run_with_messages(opts, &block)
97
+ options = {
98
+ startup_message: "Operation successfully started.",
99
+ teardown_message: "Operation successfully ended."
100
+ }.merge opts
101
+
102
+ PuppetGenerator.logger.info(self.class.name) { options[:startup_message] }
103
+ block.call
104
+ PuppetGenerator.logger.info(self.class.name) { options[:teardown_message] }
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,10 @@
1
+ module PuppetGenerator
2
+ class Definition
3
+ attr_reader :file_name, :text
4
+
5
+ def initialize( file_name, text )
6
+ @file_name = file_name
7
+ @text = text
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module EntryConverters
3
+ class File
4
+ def convert(entries, module_name, class_name)
5
+ entries.collect { |e| PuppetObjects::File.new( e, module_name , class_name ) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module EntryConverters
3
+ class Package
4
+ def convert(entries, module_name, class_name)
5
+ entries.collect { |e| PuppetObjects::Package.new( e, module_name , class_name ) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module EntryConverters
3
+ class Role
4
+ def convert(entries, module_name, class_name)
5
+ entries.collect { |e| PuppetObjects::Role.new( e, module_name , class_name ) }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module EntryConverters
3
+ class User
4
+ def convert(entries, module_name, class_name)
5
+ entries.collect { |e| PuppetObjects::User.new( e, module_name , class_name ) }
6
+ end
7
+ end
8
+ end
9
+ end