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,34 @@
1
+ module PuppetGenerator
2
+ module Middleware
3
+ class ExecuteActions
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(task)
10
+ PuppetGenerator.logger.debug(self.class.name){ "Execute action \"#{task.meta[:requested_actions].join(", ")}\" on output." }
11
+
12
+ task.body = execute_actions( task.meta[:requested_actions] , task )
13
+
14
+ @app.call(task)
15
+ end
16
+
17
+ private
18
+
19
+ def execute_actions(actions, task)
20
+
21
+ module_name = task.meta[:module]
22
+ data = task.body
23
+
24
+ actions.inject(data) do |data,action|
25
+ active_action = Models::Action.find action
26
+ raise Exceptions::UnknownAction unless active_action
27
+
28
+ data = active_action.run( task , data )
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ module PuppetGenerator
2
+ module Middleware
3
+ class FilterImportedData
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(task)
10
+ PuppetGenerator.logger.debug(self.class.name){ "Filter the input with filter \"#{task.meta[:requested_import_filter]}\"" }
11
+
12
+ active_filter = Models::ImportFilter.find task.meta[:requested_import_filter]
13
+ raise Exceptions::UnknownImportFilter unless active_filter
14
+
15
+ task.body = active_filter.convert(task.body)
16
+
17
+ @app.call(task)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,62 @@
1
+ module PuppetGenerator
2
+ module Middleware
3
+ class HandleErrors
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(t)
9
+ @task = t
10
+
11
+ PuppetGenerator.logger.debug(self.class.name){ "Waiting for errors to occure. ;-)" }
12
+
13
+ begin
14
+ @app.call(task)
15
+ rescue PuppetGenerator::Exceptions::InvalidSource
16
+ exit_with_error :invalid_source, source: task.meta[:source], command: task.meta[:command]
17
+ rescue PuppetGenerator::Exceptions::InvalidOutputChannel
18
+ exit_with_error :invalid_output_channel
19
+ rescue PuppetGenerator::Exceptions::EmptySource
20
+ exit_with_error :empty_source, source: task.meta[:source]
21
+ rescue PuppetGenerator::Exceptions::UnknownImportFilter
22
+ exit_with_error :unknown_import_filter, requested_import_filter: task.meta[:requested_import_filter],
23
+ available_import_filter: Models::ImportFilter.all_names_as_string
24
+ rescue PuppetGenerator::Exceptions::InvalidYamlInput
25
+ exit_with_error :invalid_yaml_input
26
+ rescue PuppetGenerator::Exceptions::InvalidPasswdInput
27
+ exit_with_error :invalid_passwd_input
28
+ rescue PuppetGenerator::Exceptions::UnknownAction
29
+ exit_with_error :unknown_action, requested_actions: task.meta[:requested_actions],
30
+ available_actions: Models::Action.all_names_as_string
31
+ rescue PuppetGenerator::Exceptions::FilesystemError
32
+ exit_with_error :filesystem_error, fs_object: task.meta[:source]
33
+ rescue PuppetGenerator::Exceptions::WrongTemplateChosen
34
+ exit_with_error :wrong_template_chosen, command: task.meta[:command], tags: task.meta[:template_tagged_with].to_a.join(", "), destination: task.meta[:destination]
35
+ rescue PuppetGenerator::Exceptions::InternalError => e
36
+ exit_with_error :internal_error, exception_message: e.message
37
+ rescue Interrupt
38
+ exit_with_error :interrupt
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :task
45
+
46
+ def exit_with_error(name, parameter={})
47
+ msg = Models::ErrorMessage.find(name)
48
+ raise Exceptions::UnknownErrorMessage unless msg
49
+
50
+ PuppetGenerator.logger.fatal msg.text(parameter)
51
+ exit msg.code
52
+ end
53
+
54
+ def postscript
55
+ end
56
+
57
+ def option_to_output(option)
58
+ option.keys.join(", ")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,21 @@
1
+ module PuppetGenerator
2
+ module Middleware
3
+ class OutputDebugInformationForModels
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(task)
9
+
10
+ PuppetGenerator.logger.debug(self.class.name){ "Available importer: " + Models::Importer.all_names_as_string }
11
+ PuppetGenerator.logger.debug(self.class.name){ "Available templates: " + Models::Template.all_names_as_string }
12
+ PuppetGenerator.logger.debug(self.class.name){ "Available import filter: " + Models::ImportFilter.all_names_as_string }
13
+ PuppetGenerator.logger.debug(self.class.name){ "Available export filter: " + Models::ExportFilter.all_names_as_string }
14
+ PuppetGenerator.logger.debug(self.class.name){ "Available actions: " + Models::Action.all_names_as_string }
15
+
16
+ @app.call(task)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module PuppetGenerator
2
+ module Middleware
3
+ class ReadInput
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(task)
10
+ PuppetGenerator.logger.debug(self.class.name){ "Read data from input \"#{task.meta[:source]}\"." }
11
+
12
+ raise Exceptions::FilesystemError unless PuppetGenerator::Models::Importer.existing_source?(task.meta[:source].to_s)
13
+ raise Exceptions::InvalidSource unless PuppetGenerator::Models::Importer.valid_source?(task.meta[:source].to_s)
14
+
15
+ importer = PuppetGenerator::Models::Importer.find( reads_from: task.meta[:source].to_s, enabled: true )
16
+ raise PuppetGenerator::Exceptions::InvalidSource unless importer
17
+ PuppetGenerator.logger.debug(self.class.name){ "Using importer \"#{importer.name}\" to read data." }
18
+
19
+ task.body = importer.read( task.meta[:source] )
20
+ PuppetGenerator.logger.debug(self.class.name) { "Count input lines: #{task.body.size}" }
21
+
22
+ @app.call(task)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import action
4
+ class Action < 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 action
14
+ def_delegator :@action, :run, :run
15
+
16
+ #create new instance of action model
17
+ def initialize( name , action )
18
+ super(name)
19
+
20
+ @action = action
21
+ end
22
+
23
+ class << self
24
+ private
25
+
26
+ def check_method
27
+ :run
28
+ end
29
+
30
+ def path
31
+ __FILE__
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,115 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ class Base
4
+
5
+ include Comparable
6
+
7
+ @instances = ::Set.new
8
+
9
+ attr_reader :name
10
+
11
+ def self.inherited(base)
12
+ base.instance_variable_set(:@instances, Set.new)
13
+ end
14
+
15
+ def initialize(name)
16
+ @name = name.to_sym
17
+ @enabled = false
18
+ end
19
+
20
+ #enable action
21
+ def enable
22
+ @enabled = true
23
+ end
24
+
25
+ #check if action is enabled
26
+ def enabled?(val=true)
27
+ @enabled == val
28
+ end
29
+
30
+ def name?(name)
31
+ @name == name
32
+ end
33
+
34
+ def <=>(other)
35
+ name <=> other.name
36
+ end
37
+
38
+ def eql?(other)
39
+ name == other.name
40
+ end
41
+
42
+ class << self
43
+ #attr_accessor :instances
44
+
45
+ def register(element)
46
+ @instances << element
47
+
48
+ element
49
+ end
50
+
51
+ def create( *args, &block )
52
+ if block_given?
53
+ register( new( *args, &block ) )
54
+ else
55
+ register( new( *args ) )
56
+ end
57
+ end
58
+
59
+ def find( val )
60
+ @instances.find { |i| i.name == val.to_s.to_sym }
61
+ end
62
+
63
+ def delete( val )
64
+ element = find( val.to_s.to_sym )
65
+ raise Exceptions::InstanceNotFound unless element
66
+ @instances.delete element
67
+
68
+ element
69
+ end
70
+
71
+ def clear
72
+ @instances = Set.new
73
+ end
74
+
75
+ def all
76
+ @instances.to_a
77
+ end
78
+
79
+ #return all names as string
80
+ def all_names_as_string(connector=", ")
81
+ find_all(enabled: true).map(&:name).sort.join(connector)
82
+ end
83
+
84
+ #enables a specific instance
85
+ def enable(name)
86
+ find(name: name).enable
87
+ end
88
+
89
+ #finds a single instance
90
+ def find( criteria={} )
91
+ find_all( criteria ).first
92
+ end
93
+
94
+ #finds all instances
95
+ def find_all( criteria={} )
96
+ PuppetGenerator::Models.logger.debug(self) { "Criteria for search: #{ criteria }" }
97
+ criteria = { name: criteria.to_sym } if criteria.kind_of? Symbol or criteria.kind_of? String
98
+
99
+ PuppetGenerator::Models.logger.debug(self) { "Instances to be searched for: #{ @instances.map { |i| "#{i.name} (#{i.class})" }.join(", ") }" }
100
+ @instances.find_all do |i|
101
+ criteria.all? do |c,v|
102
+
103
+ PuppetGenerator::Models.logger.debug(self) { "Check method for search: #{ c }" }
104
+ i.send( "#{c}?".to_sym , v )
105
+ end
106
+ end
107
+
108
+ rescue NameError => e
109
+ raise Exceptions::InvalidSearchCriteria, e.message
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,56 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import action
4
+ module ClassBasedModel
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def require_path(name)
13
+ File.join( PuppetGenerator.gem_load_path, model_name.pluralize.underscore , name.to_s )
14
+ end
15
+
16
+ def exception_for_model
17
+ "PuppetGenerator::Exceptions::Invalid#{model_name.singularize}".constantize
18
+ rescue
19
+ raise Exceptions::ExceptionNeedsToBeImplemented, "Exception \"Exceptions::Invalid#{model_name}\" does not exist."
20
+ end
21
+
22
+ def check_klass( klass , method)
23
+ raise exception_for_model, "A valid \"#{model_name}\"-class needs to respond to \"#{ method }\"." unless klass.new.respond_to? method
24
+ end
25
+
26
+ def build_class_constant(name)
27
+ "PuppetGenerator::#{model_name.pluralize}::#{name.to_s.camelcase}".constantize
28
+ rescue
29
+ raise exception_for_model , "The filename needs to be snakecase and needs to be convertible to the action class name: filename in camelcase."
30
+ end
31
+
32
+ def check_method
33
+ raise Exceptions::MethodNeedsToBeImplemented, "Method \"check_method\" does not exist."
34
+ end
35
+
36
+ def suffix
37
+ '.rb'
38
+ end
39
+
40
+ def load_from_filesystem
41
+ files = Dir.glob( path_to_instances )
42
+
43
+ files.each do |f|
44
+ instance_name = name( f )
45
+
46
+ require require_path( instance_name )
47
+
48
+ instance_klass = build_class_constant( instance_name )
49
+ check_klass( instance_klass, check_method )
50
+ create( instance_name , instance_klass.new )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for entry converter filter
4
+ class EntryConverter < 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 :@converter, :convert, :convert
15
+
16
+ #create new instance of filter model
17
+ def initialize( name , converter )
18
+ super(name)
19
+
20
+ @converter = converter
21
+ end
22
+
23
+ class << self
24
+
25
+ private
26
+
27
+ def check_method
28
+ :convert
29
+ end
30
+
31
+ def path
32
+ __FILE__
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,60 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ class ErrorMessage < Base
4
+
5
+ attr_accessor :preambel, :postscript, :code
6
+ class << self
7
+ attr_accessor :preambel, :postscript
8
+
9
+ def reset
10
+ self.clear
11
+
12
+ self.preambel = nil
13
+ self.postscript = nil
14
+ end
15
+
16
+ def init
17
+ Models::ErrorMessage.preambel = "Sorry, but I can't fullfill your request. "
18
+ Models::ErrorMessage.postscript = "\n\n=================\nPlease read the manual on \"http://github.com/maxmeyer/puppet_generator\" for more information on how to use the script."
19
+
20
+ Models::ErrorMessage.create :invalid_source, 1, "You entered an invalid source \"<%= @source %>\": it's not possible to use this source with \"<%= @command %>."
21
+ Models::ErrorMessage.create :invalid_output_channel, 2, "You entered an invalid output channel: file or directory can be used."
22
+ Models::ErrorMessage.create :empty_source, 3, "The source \"<%= @source %>\" you tell me to use does not contain any entries. Giving up."
23
+ Models::ErrorMessage.create :unknown_import_filter, 4, "There's no import filter \"<%= @requested_import_filter %>\". Available import filters: <%= @available_import_filter %>."
24
+ Models::ErrorMessage.create :invalid_yaml_input, 5, "The input is no YAML valid for this use case."
25
+ Models::ErrorMessage.create :invalid_passwd_input, 6, "The input is no passwd file valid for this use case."
26
+ Models::ErrorMessage.create :unknown_action, 7, "There's no action \"<%= @requested_actions %>\". Available actions: <%= @available_actions %>."
27
+ Models::ErrorMessage.create :filesystem_error, 8, "The file/directory \"<%= @fs_object %>\" does not exist."
28
+ Models::ErrorMessage.create :wrong_template_chosen, 9, "I was not able to find a suitable template for the given command \"<%= @command %>\", for the given tags \"<%= @tags %>\" and for the given destination \"<%= @destination %>\"."
29
+ Models::ErrorMessage.create :interrupt, 98, "You pressed \"CTRL-C\". Exiting."
30
+
31
+ m = Models::ErrorMessage.create :internal_error, 99, "Sorry, an internal error occured. This should not happen. Please send a bug report to the author and add the following output to that report:\n\n<%= @exception_message %>"
32
+ m.postscript = "\n\n=================\nPlease go to \"http://github.com/maxmeyer/puppet_generator\" to open the bug report. Thank you very much."
33
+
34
+ end
35
+ end
36
+
37
+ def initialize(name, code, template)
38
+ super(name)
39
+
40
+ @code = code
41
+ @template = template
42
+ end
43
+
44
+ def text(options={})
45
+ result = []
46
+ result << ( preambel ? preambel : self.class.preambel )
47
+ result << Erubis::Eruby.new(@template).evaluate(options)
48
+ result << ( postscript ? postscript : self.class.postscript )
49
+
50
+ result.join
51
+ end
52
+
53
+ private
54
+
55
+ def self.path
56
+ __FILE__
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,44 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import filter
4
+ class ExportFilter < 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 :@filter, :convert, :convert
15
+
16
+ public
17
+
18
+ #create new instance of filter model
19
+ def initialize( name , filter )
20
+ super(name)
21
+
22
+ @filter = filter
23
+ end
24
+
25
+ class << self
26
+ private
27
+
28
+ def check_method
29
+ :convert
30
+ end
31
+
32
+ def forbidden_keywords
33
+ [ :enabled ]
34
+ end
35
+
36
+ def path
37
+ __FILE__
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import filter
4
+ class Exporter < 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 :@exporter, :write, :write
15
+ def_delegator :@exporter, :writes_to?, :writes_to?
16
+
17
+ #create new instance of filter model
18
+ def initialize( name , exporter )
19
+ super(name)
20
+
21
+ @exporter = exporter
22
+ end
23
+
24
+ class << self
25
+
26
+ def existing_destination?(destination)
27
+ return true if File.exists? destination
28
+
29
+ false
30
+ end
31
+
32
+ def valid_destination?(destination)
33
+ return true if find( writes_to: destination, enabled: true )
34
+
35
+ false
36
+ end
37
+
38
+ private
39
+
40
+ def check_method
41
+ :write
42
+ end
43
+
44
+ def path
45
+ __FILE__
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,63 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import action
4
+ module FilesystemBasedModel
5
+
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ #initialize model
13
+ def init
14
+ load_from_filesystem
15
+ end
16
+
17
+ private
18
+
19
+ def module_name
20
+ name = fqcn
21
+ name.pop
22
+
23
+ name.join('::')
24
+ end
25
+
26
+ def fqcn
27
+ self.to_s.split(/::/)
28
+ end
29
+
30
+ def model_name
31
+ fqcn.last
32
+ end
33
+
34
+ def suffix
35
+ raise Exceptions::MethodNeedsToBeImplemented
36
+ end
37
+
38
+ def path_to_instances
39
+ path = File.expand_path("../../#{model_name.pluralize.underscore}", __FILE__ )
40
+
41
+ File.join(path,"*#{suffix}")
42
+ end
43
+
44
+ def name(path)
45
+ name = File.basename(path, suffix ).to_sym
46
+ raise Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name
47
+
48
+ name
49
+ end
50
+
51
+ def load_from_filesystem
52
+ raise Exceptions::MethodNeedsToBeImplemented
53
+ end
54
+
55
+ def forbidden_keywords
56
+ [ ]
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,44 @@
1
+ module PuppetGenerator
2
+ module Models
3
+ # model for import filter
4
+ class ImportFilter < 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 :@filter, :convert, :convert
15
+
16
+ public
17
+
18
+ #create new instance of filter model
19
+ def initialize( name , filter )
20
+ super(name)
21
+
22
+ @filter = filter
23
+ end
24
+
25
+ class << self
26
+ private
27
+
28
+ def check_method
29
+ :convert
30
+ end
31
+
32
+ def forbidden_keywords
33
+ [ :enabled ]
34
+ end
35
+
36
+ def path
37
+ __FILE__
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end