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,52 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import filter
4
+ class Importer < FeduxOrg::Stdlib::Models::BaseModel
5
+
6
+ include FeduxOrg::Stdlib::Models::FilesystemBasedModel
7
+ include FeduxOrg::Stdlib::Models::ClassBasedModel
8
+
9
+ extend Forwardable
10
+
11
+ #@!method convert
12
+ # converts an object using the convert method of
13
+ # the stored filter
14
+ def_delegator :@importer, :read, :read
15
+ def_delegator :@importer, :reads_from?, :reads_from?
16
+
17
+ #create new instance of filter model
18
+ def initialize( name , importer )
19
+ super(name)
20
+
21
+ @importer = importer
22
+ end
23
+
24
+ class << self
25
+
26
+ def existing_source?(source)
27
+ return true if find( reads_from: source )
28
+
29
+ false
30
+ end
31
+
32
+ def valid_source?(source)
33
+ return true if find( reads_from: source, enabled: true )
34
+
35
+ false
36
+ end
37
+
38
+ private
39
+
40
+ def check_method
41
+ :read
42
+ end
43
+
44
+ def path
45
+ __FILE__
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ def self.logger
4
+ @logger ||= PuppetGenerator::Logger.new
5
+ end
6
+
7
+ def self.logger=(logger)
8
+ @logger = logger
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,120 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ class Template < FeduxOrg::Stdlib::Models::BaseModel
4
+
5
+ include FeduxOrg::Stdlib::Models::FilesystemBasedModel
6
+
7
+ #create new instance of template model
8
+ def initialize( name , template_path, suitable_outputs=[], tags=[] )
9
+ super(name)
10
+
11
+ @template_path = template_path
12
+ @suitable_outputs = suitable_outputs
13
+ @tags = tags
14
+ end
15
+
16
+ #output path to template
17
+ def path
18
+ @template_path
19
+ end
20
+
21
+ #check if a template is suitable for
22
+ #a given output
23
+ def is_suitable_for?(output)
24
+ @suitable_outputs.include? output
25
+ end
26
+
27
+ #check if a template is tagged
28
+ def is_tagged_with?(asked_tags)
29
+ if asked_tags
30
+ return asked_tags.all? { |t| @tags.include? t }
31
+ else
32
+ return true
33
+ end
34
+ end
35
+
36
+ # render the template based on files
37
+ def render(items)
38
+
39
+ if @tags.include? :many_per_file
40
+ return [ Definition.new( nil , template.evaluate( items: items ) ) ]
41
+ elsif @tags.include? :one_per_file
42
+ return items.collect { |item| Definition.new( item.suggested_file_name, template.evaluate( item: item ) ) }
43
+ else
44
+ raise
45
+ end
46
+
47
+ rescue Exception => e
48
+ raise Exceptions::InvalidTemplate, "An invalid template \"#{@template_path}\" was used. Please check and correct the syntax and try again. The original error message was: #{e.message}."
49
+ end
50
+
51
+ private
52
+
53
+ def template
54
+ Erubis::Eruby.new( template_content )
55
+ rescue
56
+ raise Exceptions::InvalidTemplate, "An invalid template \"#{@template_path}\" was used. Please check and correct the syntax and try again."
57
+ end
58
+
59
+ def template_content
60
+ File.read( @template_path )
61
+ end
62
+
63
+ public
64
+
65
+ class << self
66
+
67
+ private
68
+
69
+ def suffix
70
+ '.pp.erb'
71
+ end
72
+
73
+ def path_to_instances
74
+ path = File.expand_path("../../../../#{model_name.downcase.pluralize}/puppet", __FILE__ )
75
+
76
+ File.join(path,'**', "*#{ suffix }")
77
+ end
78
+
79
+ def suffix
80
+ '.pp.erb'
81
+ end
82
+
83
+ def load_from_filesystem
84
+ files = Dir.glob( path_to_instances )
85
+
86
+ raise FeduxOrg::Stdlib::Models::Exceptions::NoImplementationsForModelFound, "You might need to store files at \"#{File.dirname(path_to_instances)}\" to make the library work." if files.blank?
87
+
88
+ files.each do |f|
89
+ create( name( f ) , f, suitable_outputs_for_path( f ), create_tags( f ) )
90
+ end
91
+
92
+ end
93
+
94
+ def create_tags(path)
95
+ return case path
96
+ when %r[one_per_file]
97
+ [ :one_per_file ]
98
+ when %r[many_per_file]
99
+ [ :many_per_file ]
100
+ end
101
+ end
102
+
103
+ def suitable_outputs_for_path(path)
104
+ return case path
105
+ when %r[one_per_file]
106
+ [ :directory, :dir, :stdout , :file ]
107
+ when %r[many_per_file]
108
+ [ :file , :stdout ]
109
+ else
110
+ [ :file , :stdout ]
111
+ end
112
+ end
113
+
114
+ def path
115
+ __FILE__
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,19 @@
1
+ module PuppetGenerator
2
+ module PuppetHelper
3
+ def puppet_class_name(string)
4
+ string.sub(/.pp$/, '' ).camelcase.downcase
5
+ end
6
+
7
+ def puppet_module_name(string)
8
+ string.sub(/.pp$/, '' ).camelcase.downcase
9
+ end
10
+
11
+ def puppet_module_path(string)
12
+ string.underscore
13
+ end
14
+
15
+ def puppet_manifest_path(string)
16
+ string.underscore + '.pp'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module PuppetGenerator
2
+ module PuppetObjects
3
+ class File
4
+
5
+ include PuppetHelper
6
+
7
+ attr_reader :path, :module_name, :class_name, :owner, :mode, :source, :type
8
+
9
+ def initialize(entry, module_name, class_name)
10
+ @path = entry[:name]
11
+ @module_name = module_name
12
+ @class_name = class_name
13
+
14
+ @owner = entry[:owner]
15
+ @mode = entry[:mode]
16
+ @type = entry.fetch( :type, 'file' )
17
+ @source = entry[:source]
18
+ end
19
+
20
+ def name
21
+ ::File.basename(path)
22
+ end
23
+
24
+ def suggested_file_name
25
+ puppet_manifest_path( name )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module PuppetGenerator
2
+ module PuppetObjects
3
+ class Package
4
+
5
+ include PuppetHelper
6
+
7
+ attr_reader :name, :provider, :version, :module_name, :class_name
8
+
9
+ def initialize(entry, module_name, class_name)
10
+ @name = entry[:name]
11
+ @module_name = module_name
12
+ @class_name = class_name
13
+
14
+ @version = entry.fetch( :version, 'installed' )
15
+ @provider = entry[:provider]
16
+ end
17
+
18
+ def suggested_file_name
19
+ puppet_manifest_path( name )
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module PuppetGenerator
2
+ module PuppetObjects
3
+ class Role
4
+
5
+ include PuppetHelper
6
+
7
+ attr_reader :name, :path, :module_name, :class_name, :includes
8
+
9
+ def initialize(entry, module_name, class_name)
10
+ @path = entry[:name]
11
+ @module_name = entry.fetch(:module_name, module_name )
12
+ @class_name = entry.fetch(:class_name, class_name )
13
+
14
+ @includes = entry[:includes] || []
15
+ end
16
+
17
+ def suggested_file_name
18
+ puppet_manifest_path( path )
19
+ end
20
+
21
+ def name
22
+ "#{module_name}::#{::File.basename( @path )}"
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module PuppetGenerator
2
+ module PuppetObjects
3
+ class User
4
+
5
+ include PuppetHelper
6
+
7
+ attr_reader :name, :userid, :homedir, :groupid, :shell, :provider, :module_name, :class_name
8
+
9
+ def initialize(entry, module_name, class_name)
10
+ @name = entry[:name]
11
+ @module_name = module_name
12
+ @class_name = class_name
13
+
14
+ @userid = entry[:userid]
15
+ @groupid = entry[:groupid]
16
+ @shell = entry[:shell]
17
+ @homedir = entry[:homedir]
18
+ @provider = entry[:provider]
19
+ end
20
+
21
+ def suggested_file_name
22
+ puppet_manifest_path( name )
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class Bare
4
+
5
+ def initialize(options)
6
+ @options = options
7
+
8
+ PuppetGenerator::Models.logger = PuppetGenerator.logger
9
+
10
+ Models::Template.init
11
+ Models::ImportFilter.init
12
+ Models::Action.init
13
+ Models::ErrorMessage.init
14
+ Models::Importer.init
15
+ Models::Exporter.init
16
+ Models::ExportFilter.init
17
+ Models::EntryConverter.init
18
+ end
19
+
20
+ def create_task
21
+ Task.new(@options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultActions
4
+ def self.use
5
+ Models::Action.enable :null
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module EntryConverters
4
+ def self.use
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultErrorMessages
4
+ def self.use
5
+ Models::ErrorMessage.all.each { |m| m.enable }
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,9 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultExportFilter
4
+ def self.use
5
+ Models::ExportFilter.enable :null
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultExporter
4
+ def self.use
5
+ Models::Exporter.enable :file
6
+ Models::Exporter.enable :stdout
7
+ Models::Exporter.enable :directory
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultImportFilter
4
+ def self.use
5
+ Models::ImportFilter.enable :null
6
+ Models::ImportFilter.enable :yaml
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ module DefaultImporter
4
+ def self.use
5
+ Models::Importer.enable :file
6
+ Models::Importer.enable :stdin
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class File < Bare
4
+
5
+ def initialize(options)
6
+ super
7
+ end
8
+
9
+ def setup_environment
10
+ DefaultErrorMessages.use
11
+ DefaultImportFilter.use
12
+ DefaultActions.use
13
+ DefaultImporter.use
14
+ DefaultExportFilter.use
15
+
16
+ Models::Action.enable :copy_files_to_module_directory
17
+ Models::Template.find_all(:file).collect { |t| t.enable }
18
+ Models::ExportFilter.enable :filesystem_attributes
19
+ Models::Importer.enable :directory
20
+ end
21
+
22
+ def create_task
23
+ Task.new(
24
+ HashWithIndifferentAccess.new( { command: :file } ).merge @options
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class Module < Bare
4
+
5
+
6
+ def initialize(options)
7
+ super
8
+ end
9
+
10
+ def setup_environment
11
+ DefaultErrorMessages.use
12
+ end
13
+
14
+ def create_task
15
+ Task.new(
16
+ HashWithIndifferentAccess.new( { command: :module } ).merge @options
17
+ )
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class Package < Bare
4
+
5
+
6
+ def initialize(options)
7
+ super
8
+ end
9
+
10
+ def setup_environment
11
+ DefaultErrorMessages.use
12
+ DefaultImportFilter.use
13
+ DefaultActions.use
14
+ DefaultImporter.use
15
+ DefaultExportFilter.use
16
+
17
+ Models::Template.find_all(:package).collect { |t| t.enable }
18
+ end
19
+
20
+ def create_task
21
+ Task.new(
22
+ HashWithIndifferentAccess.new( { command: :package } ).merge @options
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class Role < Bare
4
+
5
+ def initialize(options)
6
+ super
7
+ end
8
+
9
+ def setup_environment
10
+ DefaultErrorMessages.use
11
+ DefaultImportFilter.use
12
+ DefaultActions.use
13
+ DefaultImporter.use
14
+ DefaultExportFilter.use
15
+
16
+ Models::Template.find_all(:role).collect { |t| t.enable }
17
+ Models::Importer.enable :directory
18
+ Models::ExportFilter.enable :build_role_includes_for_directory
19
+ end
20
+
21
+ def create_task
22
+ Task.new(
23
+ HashWithIndifferentAccess.new( { command: :role } ).merge @options
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module PuppetGenerator
2
+ module Setup
3
+ class User < Bare
4
+ def initialize(options)
5
+ super
6
+ @task = Task.new(options)
7
+ end
8
+
9
+ def setup_environment
10
+ DefaultErrorMessages.use
11
+ DefaultImportFilter.use
12
+ DefaultActions.use
13
+ DefaultImporter.use
14
+ DefaultExportFilter.use
15
+
16
+ Models::ImportFilter.enable :passwd
17
+ Models::Template.find_all(:user).collect { |t| t.enable }
18
+ end
19
+
20
+ def create_task
21
+ Task.new(
22
+ HashWithIndifferentAccess.new( { command: :user } ).merge @options
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ module PuppetGenerator
2
+ class Task
3
+
4
+ include PuppetHelper
5
+
6
+ attr_reader :meta
7
+ attr_accessor :body
8
+
9
+ def initialize(options={})
10
+ @meta = {}
11
+ @body = nil
12
+
13
+ @meta[:source] = options[:source]
14
+ @meta[:destination] = options[:destination]
15
+ @meta[:module] = puppet_module_name( options[:module] )
16
+ @meta[:class] = puppet_class_name( options[:class] )
17
+ @meta[:requested_import_filter] = options[:import_filter]
18
+ @meta[:requested_export_filter] = options[:export_filter]
19
+ @meta[:requested_actions] = options[:action]
20
+ @meta[:logging_mode] = log_level(options)
21
+ @meta[:command] = options[:command]
22
+ @meta[:template_tagged_with] = options[:template_tagged_with].split(/:/).map(&:to_sym) if options[:template_tagged_with]
23
+ @meta[:debug] = true if options[:debug]
24
+ end
25
+
26
+ private
27
+
28
+ def log_level(options)
29
+ if options[:silent]
30
+ return :silent
31
+ elsif options[:debug]
32
+ return :debug
33
+ else
34
+ return :info
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module PuppetGenerator
2
+ module Ui
3
+ module CommandlineParserHelper
4
+
5
+ @runner_options = {}
6
+ @runner_options[:module] = { type: :string, default: 'mymodule', desc: 'the module prefix in puppet class name' }
7
+ @runner_options[:class] = { type: :string, default: 'myclass', desc: 'the class suffix in puppet class name' }
8
+ @runner_options[:debug] = { type: :boolean, default: false, desc: 'enable debug logging and debugging libraries' }
9
+ @runner_options[:silent] = { type: :boolean, default: false, desc: 'disable logging' }
10
+
11
+ @subcommand_options = {}
12
+ @subcommand_options[:source] = { type: :string, default: 'input.txt', desc: 'enter the source which should be used to generate the puppet output' }
13
+ @subcommand_options[:import_filter] = { type: :string, default: 'null', desc: 'make it possible to pipe structured data into command' }
14
+ @subcommand_options[:destination] = { type: :string, default: 'dir:out.d', desc: 'where should the information be stored. Valid input is "file|dir:<dest>" or "stdout"' }
15
+ @subcommand_options[:action] = { type: :array, default: [ :null ], desc: 'what action should be run after filtering the input: <action>( <action>)*' }
16
+ @subcommand_options[:template_tagged_with] = { type: :string, desc: 'use a template which is tagged with "<tag>(:<tag>)+"' }
17
+ @subcommand_options[:export_filter] = { type: :array, default: [ :null ], desc: 'modify the data before exporting it (to add some more value to it): <filter>( <filter>)*' }
18
+
19
+ class << self
20
+ attr_reader :runner_options
21
+ attr_reader :subcommand_options
22
+ end
23
+
24
+ def self.pretty_subcommands(cmds)
25
+ cmds.keys.join(', ')
26
+ end
27
+
28
+
29
+ end
30
+ end
31
+ end