puppet-retrospec 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca1e5137298e9ae66d799a66eaf71a221e696379
4
- data.tar.gz: 707f87e0cb1f5fb001d16459a037f8055806f9ba
3
+ metadata.gz: 56ddee7e316cf7e2074a1f6ca6cdc34561baaa31
4
+ data.tar.gz: 7bc02f19562beb2981babe6bd17949b51901f942
5
5
  SHA512:
6
- metadata.gz: c72d4b82b2eec85b0c29194f33822b3fe135246206c135f99f6cfd8f86a8c155a071f5e7cd9057ce8aa100b3d6d99df05fe53a275a6bb45d39bfe3871baa095b
7
- data.tar.gz: 223c391870cedfb12b50dfc6246e91fbad7cbc667d4102dafa42d4e09c38b44b8a6f6be0e86b802cc78b8d9e91ac5cd068fe4807cb0d1067d6829a5505051639
6
+ metadata.gz: 79f92a3078d2456d98fa5be550700b9d4001862340ded0cf610ec1192c9e7613153f3099e229bb232d66390cc353d1d6de3f983d5df784c39fd5f507c686ad2b
7
+ data.tar.gz: c9acb7246d9bbecaa52e851333678f0e25a76fdb3ece6d2751e8bd2b418775ddcddcebc28c3a06b8830cb23c2e13226072ae03481f3499d1be3d909547c40564
@@ -1,3 +1,5 @@
1
+ ## 1.5.0
2
+ * Adds ability to generate bolt tasks for puppet modules
1
3
  ## 1.4.1
2
4
  * Adds real module data to common.yaml
3
5
  ## 1.4.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- puppet-retrospec (1.4.1)
4
+ puppet-retrospec (1.5.0)
5
5
  awesome_print
6
6
  facets
7
7
  retrospec (>= 0.6.2)
@@ -98,4 +98,4 @@ DEPENDENCIES
98
98
  yard (~> 0.7)
99
99
 
100
100
  BUNDLED WITH
101
- 1.14.6
101
+ 1.15.4
data/README.md CHANGED
@@ -50,6 +50,14 @@ TOC Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
50
50
  [![Gem Version](https://badge.fury.io/rb/puppet-retrospec.svg)](http://badge.fury.io/rb/puppet-retrospec)
51
51
 
52
52
  ## News
53
+ ### 10/11/17
54
+ Adds the ability to generate puppet bolt tasks, parameters with some predefined language types
55
+
56
+ `retrospec puppet new_task -n reboot -t bash -p "name, count, amount"`
57
+
58
+ Generates the parameters file and task file.
59
+
60
+
53
61
  ### 5/10/17
54
62
  Adds ability to create module data. With the release of puppet 4.9 we can now use module data.
55
63
  Use the module_data generater to auto setup module data in your puppet module. `retrospec puppet module_data`
@@ -0,0 +1,116 @@
1
+ require 'json'
2
+
3
+ module Retrospec
4
+ module Puppet
5
+ module Generators
6
+ class TaskGenerator < Retrospec::Puppet::Generators::BaseGenerator
7
+ EXT_TYPES = {
8
+ 'ruby' => 'rb',
9
+ 'generic' => 'generic',
10
+ 'python' => 'py',
11
+ 'powershell' => 'ps1',
12
+ 'bash' => 'sh',
13
+ 'node' => 'js'
14
+ }
15
+
16
+ # retrospec will initilalize this class so its up to you
17
+ # to set any additional variables you need to get the job done.
18
+ def initialize(module_path, spec_object = {})
19
+ super
20
+ @plural_name = 'tasks'
21
+ @singular_name = 'task'
22
+ end
23
+
24
+ def shebang
25
+ "#!/usr/bin/env #{task_type}"
26
+ end
27
+
28
+ def task_params
29
+ config_data[:task_params].gsub(/\s/, '').split(",")
30
+ end
31
+
32
+ def task_params_output
33
+ params = {}
34
+ task_params.each_with_object({}) do |item, obj|
35
+ obj["description"] = "The description of the #{item} parameter"
36
+ obj["type"] = "String"
37
+ params[item] = obj
38
+ end
39
+ params
40
+ end
41
+
42
+ def task_type
43
+ config_data[:task_type]
44
+ end
45
+
46
+ def run
47
+ files = []
48
+ files << generate_task_files
49
+ files
50
+ end
51
+
52
+ def task_filepath
53
+ ext = EXT_TYPES.fetch(task_type, task_type)
54
+ File.join(module_path, 'tasks', "#{item_name}.#{ext}")
55
+ end
56
+
57
+ def task_params_filepath
58
+ File.join(module_path, 'tasks', "#{item_name}.json")
59
+ end
60
+
61
+ def item_spec_path
62
+ File.join(spec_path, plural_name, "#{item_name}_spec.rb")
63
+ end
64
+
65
+ def enable_beaker_tasks?
66
+ false
67
+ end
68
+
69
+ def generate_task_files
70
+ context.task_type = task_type
71
+ context.shebang = shebang
72
+ context.task_params_output = task_params_output
73
+ context.task_params = task_params
74
+ parameter_template = File.join(template_dir, 'task_parameters.json.retrospec.erb')
75
+ task_template = Dir.glob(File.join(template_dir, 'types', task_type, '*')).first
76
+ unless task_template
77
+ task_template = Dir.glob(File.join(template_dir, 'types', 'task.retrospec.erb')).first
78
+ end
79
+ files = []
80
+ files << safe_create_template_file(task_filepath, task_template, context)
81
+ files << safe_create_template_file(task_params_filepath, parameter_template, context)
82
+ files
83
+ end
84
+
85
+ # used to display subcommand options to the cli
86
+ # the global options are passed in for your usage
87
+ # http://trollop.rubyforge.org
88
+ # all options here are available in the config passed into config object
89
+ # returns the parameters
90
+ def self.run_cli(global_opts, args=ARGV)
91
+ task_types = %w(bash generic ruby python node powershell)
92
+ task_type = global_opts['plugins::puppet::default_task_type'] || 'bash'
93
+ sub_command_opts = Trollop.options(args) do
94
+ banner <<-EOS
95
+ Creates a new puppet bolt task for your module
96
+
97
+ Example: retrospec puppet new_task -n reboot -p "name, ttl, message"
98
+
99
+ EOS
100
+ opt :name, "The name of the task you wish to create", :type => :string, :required => true, :short => '-n'
101
+ opt :task_params, "The task parameter names separated by commas", :short => '-p', :type => :string, :required => false, default: "name"
102
+ opt :task_type, "The task type of the task (#{task_types.join(', ')})", :type => :string, :required => false, :short => '-t',
103
+ :default => task_type
104
+
105
+ end
106
+ unless sub_command_opts[:name]
107
+ Trollop.educate
108
+ exit 1
109
+ end
110
+ plugin_data = global_opts.merge(sub_command_opts)
111
+ plugin_data
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -92,7 +92,7 @@ module Retrospec
92
92
  scm_branch = ENV['RETROSPEC_PUPPET_SCM_BRANCH'] || plugin_config['plugins::puppet::templates::ref'] || 'master'
93
93
  beaker_tests = plugin_config['plugins::puppet::enable_beaker_tests'] || false
94
94
  # a list of subcommands for this plugin
95
- sub_commands = %w(new_module new_fact new_type new_provider new_function new_report module_data)
95
+ sub_commands = %w(new_module new_task new_fact new_type new_provider new_function new_report module_data)
96
96
  if sub_commands.count > 0
97
97
  sub_command_help = "Subcommands:\n #{sub_commands.join("\n ")}\n"
98
98
  else
@@ -106,7 +106,6 @@ Generates puppet rspec test code and puppet module components.
106
106
  #{sub_command_help}
107
107
 
108
108
  EOS
109
-
110
109
  opt :template_dir, 'Path to templates directory (only for overriding Retrospec templates)', :type => :string,
111
110
  :required => false, :default => template_dir
112
111
  opt :scm_url, 'SCM url for retrospec templates', :type => :string, :required => false,
@@ -135,6 +134,8 @@ Generates puppet rspec test code and puppet module components.
135
134
  plugin.new_type(plugin_data, args)
136
135
  when :new_function
137
136
  plugin.new_function(plugin_data, args)
137
+ when :new_task
138
+ plugin.new_task(plugin_data, args)
138
139
  when :new_fact
139
140
  plugin.new_fact(plugin_data, args)
140
141
  when :new_provider
@@ -165,6 +166,14 @@ Generates puppet rspec test code and puppet module components.
165
166
  plugin_data
166
167
  end
167
168
 
169
+ def new_task(config, args)
170
+ plugin_data = Retrospec::Puppet::Generators::TaskGenerator.run_cli(config, args)
171
+ plugin_data[:puppet_context] = context
172
+ t = Retrospec::Puppet::Generators::TaskGenerator.new(plugin_data[:module_path], plugin_data)
173
+ t.run
174
+ post_init
175
+ end
176
+
168
177
  def module_data(module_path, config, args=[])
169
178
  plugin_data = Retrospec::Puppet::Generators::ModuleDataGenerator.run_cli(config, args)
170
179
  plugin_data[:puppet_context] = context
@@ -1,5 +1,5 @@
1
1
  module Retrospec
2
2
  module Puppet
3
- VERSION = '1.4.1'
3
+ VERSION = '1.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-retrospec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
@@ -14,84 +14,84 @@ dependencies:
14
14
  name: trollop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: retrospec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.6.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.6.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: awesome_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: facets
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.12'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.12'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Retrofits and generates valid puppet rspec test code to existing modules
@@ -103,15 +103,15 @@ extra_rdoc_files:
103
103
  - LICENSE
104
104
  - README.md
105
105
  files:
106
- - .dockerignore
107
- - .document
108
- - .gitignore
109
- - .gitlab-ci.yml
110
- - .overcommit.yml
111
- - .release_me.yaml
112
- - .rspec
113
- - .rubocop.yml
114
- - .rubocop_todo.yml
106
+ - ".dockerignore"
107
+ - ".document"
108
+ - ".gitignore"
109
+ - ".gitlab-ci.yml"
110
+ - ".overcommit.yml"
111
+ - ".release_me.yaml"
112
+ - ".rspec"
113
+ - ".rubocop.yml"
114
+ - ".rubocop_todo.yml"
115
115
  - CHANGELOG.md
116
116
  - DEVELOPMENT.md
117
117
  - Dockerfile
@@ -143,6 +143,7 @@ files:
143
143
  - lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper.rb
144
144
  - lib/retrospec/plugins/v1/plugin/generators/serializers/rspec_dumper_full.rb
145
145
  - lib/retrospec/plugins/v1/plugin/generators/serializers/schema_dumper.rb
146
+ - lib/retrospec/plugins/v1/plugin/generators/task_generator.rb
146
147
  - lib/retrospec/plugins/v1/plugin/generators/type_generator.rb
147
148
  - lib/retrospec/plugins/v1/plugin/helpers.rb
148
149
  - lib/retrospec/plugins/v1/plugin/puppet.rb
@@ -1760,17 +1761,17 @@ require_paths:
1760
1761
  - lib
1761
1762
  required_ruby_version: !ruby/object:Gem::Requirement
1762
1763
  requirements:
1763
- - - '>='
1764
+ - - ">="
1764
1765
  - !ruby/object:Gem::Version
1765
1766
  version: '0'
1766
1767
  required_rubygems_version: !ruby/object:Gem::Requirement
1767
1768
  requirements:
1768
- - - '>='
1769
+ - - ">="
1769
1770
  - !ruby/object:Gem::Version
1770
1771
  version: '0'
1771
1772
  requirements: []
1772
1773
  rubyforge_project:
1773
- rubygems_version: 2.0.14.1
1774
+ rubygems_version: 2.6.11
1774
1775
  signing_key:
1775
1776
  specification_version: 4
1776
1777
  summary: Generates puppet rspec test code based on the classes and defines inside