choria-mcorpc-support 2.21.1 → 2.23.1

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.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mcollective.rb +1 -2
  3. data/lib/mcollective/agent/bolt_tasks.ddl +253 -0
  4. data/lib/mcollective/agent/bolt_tasks.json +365 -0
  5. data/lib/mcollective/agent/bolt_tasks.rb +178 -0
  6. data/lib/mcollective/agent/choria_util.ddl +152 -0
  7. data/lib/mcollective/agent/choria_util.json +244 -0
  8. data/lib/mcollective/agent/rpcutil.ddl +8 -4
  9. data/lib/mcollective/agent/rpcutil.json +333 -0
  10. data/lib/mcollective/agent/scout.ddl +169 -0
  11. data/lib/mcollective/agent/scout.json +224 -0
  12. data/lib/mcollective/agents.rb +7 -6
  13. data/lib/mcollective/aggregate.rb +4 -4
  14. data/lib/mcollective/aggregate/average.rb +2 -2
  15. data/lib/mcollective/aggregate/base.rb +2 -2
  16. data/lib/mcollective/aggregate/result.rb +3 -3
  17. data/lib/mcollective/aggregate/result/collection_result.rb +2 -2
  18. data/lib/mcollective/aggregate/result/numeric_result.rb +2 -2
  19. data/lib/mcollective/aggregate/sum.rb +2 -2
  20. data/lib/mcollective/aggregate/summary.rb +3 -4
  21. data/lib/mcollective/application.rb +57 -21
  22. data/lib/mcollective/application/choria.rb +189 -0
  23. data/lib/mcollective/application/completion.rb +6 -6
  24. data/lib/mcollective/application/facts.rb +11 -11
  25. data/lib/mcollective/application/federation.rb +237 -0
  26. data/lib/mcollective/application/find.rb +4 -4
  27. data/lib/mcollective/application/help.rb +3 -3
  28. data/lib/mcollective/application/inventory.rb +3 -341
  29. data/lib/mcollective/application/ping.rb +5 -51
  30. data/lib/mcollective/application/playbook.rb +207 -0
  31. data/lib/mcollective/application/plugin.rb +106 -106
  32. data/lib/mcollective/application/rpc.rb +3 -108
  33. data/lib/mcollective/application/tasks.rb +425 -0
  34. data/lib/mcollective/applications.rb +11 -10
  35. data/lib/mcollective/audit/choria.rb +33 -0
  36. data/lib/mcollective/cache.rb +2 -4
  37. data/lib/mcollective/client.rb +11 -10
  38. data/lib/mcollective/config.rb +21 -34
  39. data/lib/mcollective/connector/base.rb +2 -1
  40. data/lib/mcollective/connector/nats.ddl +9 -0
  41. data/lib/mcollective/connector/nats.rb +450 -0
  42. data/lib/mcollective/data.rb +8 -3
  43. data/lib/mcollective/data/agent_data.rb +1 -1
  44. data/lib/mcollective/data/base.rb +6 -5
  45. data/lib/mcollective/data/bolt_task_data.ddl +90 -0
  46. data/lib/mcollective/data/bolt_task_data.rb +32 -0
  47. data/lib/mcollective/data/collective_data.rb +1 -1
  48. data/lib/mcollective/data/fact_data.rb +6 -6
  49. data/lib/mcollective/data/fstat_data.rb +2 -4
  50. data/lib/mcollective/data/result.rb +7 -2
  51. data/lib/mcollective/ddl/agentddl.rb +5 -17
  52. data/lib/mcollective/ddl/base.rb +10 -13
  53. data/lib/mcollective/discovery.rb +24 -39
  54. data/lib/mcollective/discovery/choria.ddl +11 -0
  55. data/lib/mcollective/discovery/choria.rb +223 -0
  56. data/lib/mcollective/discovery/flatfile.rb +7 -8
  57. data/lib/mcollective/discovery/mc.rb +2 -2
  58. data/lib/mcollective/discovery/stdin.rb +17 -18
  59. data/lib/mcollective/exceptions.rb +13 -0
  60. data/lib/mcollective/facts/base.rb +9 -9
  61. data/lib/mcollective/facts/yaml_facts.rb +12 -12
  62. data/lib/mcollective/generators.rb +3 -3
  63. data/lib/mcollective/generators/agent_generator.rb +3 -4
  64. data/lib/mcollective/generators/base.rb +14 -15
  65. data/lib/mcollective/generators/data_generator.rb +5 -6
  66. data/lib/mcollective/log.rb +2 -2
  67. data/lib/mcollective/logger/base.rb +3 -2
  68. data/lib/mcollective/logger/console_logger.rb +10 -10
  69. data/lib/mcollective/logger/file_logger.rb +7 -7
  70. data/lib/mcollective/logger/syslog_logger.rb +11 -15
  71. data/lib/mcollective/message.rb +8 -39
  72. data/lib/mcollective/monkey_patches.rb +2 -4
  73. data/lib/mcollective/optionparser.rb +2 -1
  74. data/lib/mcollective/pluginmanager.rb +3 -5
  75. data/lib/mcollective/pluginpackager.rb +1 -3
  76. data/lib/mcollective/pluginpackager/agent_definition.rb +3 -8
  77. data/lib/mcollective/pluginpackager/forge_packager.rb +7 -9
  78. data/lib/mcollective/pluginpackager/standard_definition.rb +1 -2
  79. data/lib/mcollective/registration/base.rb +18 -16
  80. data/lib/mcollective/rpc.rb +2 -4
  81. data/lib/mcollective/rpc/actionrunner.rb +16 -18
  82. data/lib/mcollective/rpc/agent.rb +26 -43
  83. data/lib/mcollective/rpc/audit.rb +1 -0
  84. data/lib/mcollective/rpc/client.rb +67 -85
  85. data/lib/mcollective/rpc/helpers.rb +55 -62
  86. data/lib/mcollective/rpc/progress.rb +2 -2
  87. data/lib/mcollective/rpc/reply.rb +17 -19
  88. data/lib/mcollective/rpc/request.rb +7 -5
  89. data/lib/mcollective/rpc/result.rb +6 -8
  90. data/lib/mcollective/rpc/stats.rb +49 -58
  91. data/lib/mcollective/security/base.rb +13 -56
  92. data/lib/mcollective/security/choria.rb +765 -0
  93. data/lib/mcollective/shell.rb +9 -4
  94. data/lib/mcollective/signer/base.rb +28 -0
  95. data/lib/mcollective/signer/choria.rb +185 -0
  96. data/lib/mcollective/ssl.rb +8 -6
  97. data/lib/mcollective/util.rb +58 -55
  98. data/lib/mcollective/util/bolt_support.rb +176 -0
  99. data/lib/mcollective/util/bolt_support/plan_runner.rb +167 -0
  100. data/lib/mcollective/util/bolt_support/task_result.rb +94 -0
  101. data/lib/mcollective/util/bolt_support/task_results.rb +128 -0
  102. data/lib/mcollective/util/choria.rb +946 -0
  103. data/lib/mcollective/util/indifferent_hash.rb +12 -0
  104. data/lib/mcollective/util/natswrapper.rb +242 -0
  105. data/lib/mcollective/util/playbook.rb +435 -0
  106. data/lib/mcollective/util/playbook/data_stores.rb +201 -0
  107. data/lib/mcollective/util/playbook/data_stores/base.rb +99 -0
  108. data/lib/mcollective/util/playbook/data_stores/consul_data_store.rb +88 -0
  109. data/lib/mcollective/util/playbook/data_stores/environment_data_store.rb +33 -0
  110. data/lib/mcollective/util/playbook/data_stores/etcd_data_store.rb +42 -0
  111. data/lib/mcollective/util/playbook/data_stores/file_data_store.rb +106 -0
  112. data/lib/mcollective/util/playbook/data_stores/shell_data_store.rb +103 -0
  113. data/lib/mcollective/util/playbook/inputs.rb +265 -0
  114. data/lib/mcollective/util/playbook/nodes.rb +207 -0
  115. data/lib/mcollective/util/playbook/nodes/mcollective_nodes.rb +86 -0
  116. data/lib/mcollective/util/playbook/nodes/pql_nodes.rb +40 -0
  117. data/lib/mcollective/util/playbook/nodes/shell_nodes.rb +55 -0
  118. data/lib/mcollective/util/playbook/nodes/terraform_nodes.rb +65 -0
  119. data/lib/mcollective/util/playbook/nodes/yaml_nodes.rb +47 -0
  120. data/lib/mcollective/util/playbook/playbook_logger.rb +47 -0
  121. data/lib/mcollective/util/playbook/puppet_logger.rb +51 -0
  122. data/lib/mcollective/util/playbook/report.rb +152 -0
  123. data/lib/mcollective/util/playbook/task_result.rb +55 -0
  124. data/lib/mcollective/util/playbook/tasks.rb +196 -0
  125. data/lib/mcollective/util/playbook/tasks/base.rb +45 -0
  126. data/lib/mcollective/util/playbook/tasks/graphite_event_task.rb +64 -0
  127. data/lib/mcollective/util/playbook/tasks/mcollective_task.rb +356 -0
  128. data/lib/mcollective/util/playbook/tasks/shell_task.rb +93 -0
  129. data/lib/mcollective/util/playbook/tasks/slack_task.rb +105 -0
  130. data/lib/mcollective/util/playbook/tasks/webhook_task.rb +136 -0
  131. data/lib/mcollective/util/playbook/template_util.rb +98 -0
  132. data/lib/mcollective/util/playbook/uses.rb +169 -0
  133. data/lib/mcollective/util/tasks_support.rb +751 -0
  134. data/lib/mcollective/util/tasks_support/cli.rb +260 -0
  135. data/lib/mcollective/util/tasks_support/default_formatter.rb +138 -0
  136. data/lib/mcollective/util/tasks_support/json_formatter.rb +108 -0
  137. data/lib/mcollective/validator.rb +6 -1
  138. data/lib/mcollective/validator/bolt_task_name_validator.ddl +7 -0
  139. data/lib/mcollective/validator/bolt_task_name_validator.rb +11 -0
  140. data/lib/mcollective/validator/length_validator.rb +1 -3
  141. metadata +65 -6
  142. data/lib/mcollective/application/describe_filter.rb +0 -87
  143. data/lib/mcollective/matcher.rb +0 -220
  144. data/lib/mcollective/matcher/parser.rb +0 -128
  145. data/lib/mcollective/matcher/scanner.rb +0 -241
@@ -0,0 +1,207 @@
1
+ module MCollective
2
+ class Application
3
+ class Playbook < Application
4
+ description "Choria Playbook Runner"
5
+
6
+ usage <<-USAGE
7
+ mco playbook [OPTIONS] <ACTION> <PLAYBOOK>
8
+
9
+ The ACTION can be one of the following:
10
+
11
+ run - run the playbook as your local user
12
+
13
+ The PLAYBOOK Puppet Plan describing the tasks to perform
14
+
15
+ Passing --help as well as a PLAYBOOK argument will show
16
+ flags and help related to the specific playbook.
17
+
18
+ Any inputs to the playbook should be given on the CLI.
19
+ USAGE
20
+
21
+ exclude_argument_sections "common", "filter", "rpc"
22
+
23
+ def pre_parse_modulepath
24
+ words = Shellwords.shellwords(ARGV.join(" "))
25
+ words.each_with_index do |word, idx|
26
+ if word == "--modulepath"
27
+ configuration[:__modulepath] = words[idx + 1]
28
+ break
29
+ end
30
+ end
31
+ end
32
+
33
+ # Playbook should be given right after the command, this finds the value after the command
34
+ #
35
+ # @return [String,nil]
36
+ def pre_parse_find_playbook
37
+ commands = Regexp.union(valid_commands)
38
+
39
+ cmd_idx = ARGV.index {|a| a.match(commands)}
40
+ return nil unless cmd_idx
41
+
42
+ pb = ARGV[cmd_idx + 1]
43
+
44
+ pb if pb =~ /\A([a-z][a-z0-9_]*)?(::[a-z][a-z0-9_]*)*\Z/
45
+ end
46
+
47
+ # Creates an instance of the plan runner
48
+ #
49
+ # @param plan [String] the name of a plan
50
+ # @return [Util::BoltSupport::PlanRunner]
51
+ def runner(plan, loglevel=nil)
52
+ require "mcollective/util/bolt_support"
53
+ plan_runner = Util::BoltSupport::PlanRunner.new(
54
+ plan,
55
+ configuration[:__tmpdir],
56
+ configuration[:__modulepath],
57
+ configuration[:__loglevel] || "info"
58
+ )
59
+
60
+ unless plan_runner.exist?
61
+ warn("Cannot find supplied Playbook %s" % plan)
62
+ $stderr.puts
63
+ warn("Module Path:")
64
+ $stderr.puts
65
+
66
+ if configuration[:__modulepath]
67
+ warn(Util.align_text(configuration[:__modulepath].split(":").join("\n")))
68
+ else
69
+ warn(Util.align_text("Puppet Default"))
70
+ end
71
+
72
+ exit(1)
73
+ end
74
+
75
+ plan_runner
76
+ end
77
+
78
+ # Adds the playbook inputs as CLI options before starting the app
79
+ def run
80
+ pre_parse_modulepath
81
+
82
+ Dir.mktmpdir("choria") do |dir|
83
+ configuration[:__tmpdir] = dir
84
+
85
+ if playbook_name = pre_parse_find_playbook
86
+ configuration[:__playbook] = playbook_name
87
+ runner(playbook_name).add_cli_options(self, false)
88
+ end
89
+
90
+ # Hackily done here to force it below the playbook options
91
+ self.class.option :__json_input,
92
+ :arguments => ["--input INPUT"],
93
+ :description => "JSON input to pass to the task",
94
+ :required => false,
95
+ :type => String
96
+
97
+ self.class.option :__modulepath,
98
+ :arguments => ["--modulepath PATH"],
99
+ :description => "Path to find Puppet module when using the Playbook DSL",
100
+ :type => String
101
+
102
+ self.class.option :__loglevel,
103
+ :arguments => ["--loglevel LEVEL"],
104
+ :description => "Override the loglevel set in the playbook (emerg alert crit err warning notice info verbose debug)",
105
+ :type => String,
106
+ :validate => ->(level) { %w[emerg alert crit err warning notice info verbose debug].include?(level) }
107
+
108
+ super
109
+ end
110
+ end
111
+
112
+ def post_option_parser(configuration)
113
+ if ARGV.length >= 1
114
+ configuration[:__command] = ARGV.shift
115
+ else
116
+ abort("Please specify a command, valid commands are: %s" % valid_commands.join(", "))
117
+ end
118
+
119
+ if input = configuration[:__json_input]
120
+ result = {}
121
+
122
+ if input.start_with?("@")
123
+ input.sub!("@", "")
124
+ result = JSON.parse(File.read(input)) if input.end_with?("json")
125
+ result = YAML.safe_load(File.read(input)) if input.end_with?("yaml")
126
+ else
127
+ result = JSON.parse(input)
128
+ end
129
+
130
+ configuration.merge!(result)
131
+ end
132
+ end
133
+
134
+ # Validates the configuration
135
+ #
136
+ # @return [void]
137
+ def validate_configuration(configuration)
138
+ abort("Please specify a playbook to run") unless configuration[:__playbook]
139
+
140
+ configuration[:__loglevel] = "debug" if options[:verbose] && !configuration.include?(:loglevel)
141
+ end
142
+
143
+ # List of valid commands this application respond to
144
+ #
145
+ # @return [Array<String>] like `plan` and `run`
146
+ def valid_commands
147
+ methods.grep(/_command$/).map {|c| c.to_s.gsub("_command", "")}
148
+ end
149
+
150
+ def run_command
151
+ pb_config = configuration.clone
152
+ pb_config.delete_if {|k, _| k.to_s.start_with?("__")}
153
+
154
+ pb = runner(configuration[:__playbook], configuration[:__loglevel])
155
+
156
+ run_plan(pb, pb_config)
157
+ end
158
+
159
+ def run_plan(playbook, pb_config)
160
+ startime = Time.now
161
+
162
+ success = true
163
+
164
+ result = playbook.run!(pb_config)
165
+ rescue
166
+ success = false
167
+ ensure
168
+ disconnect
169
+
170
+ endtime = Time.now
171
+
172
+ color = :green
173
+ msg = "OK"
174
+
175
+ unless success
176
+ color = :red
177
+ msg = "FAILED"
178
+ end
179
+
180
+ puts
181
+ puts "Playbook %s ran in %.2f seconds: %s" % [
182
+ Util.colorize(:bold, configuration[:__playbook]),
183
+ endtime - startime,
184
+ Util.colorize(color, msg)
185
+ ]
186
+
187
+ if result
188
+ puts
189
+ puts "Result: "
190
+ puts
191
+ if result.instance_of?(String)
192
+ puts result
193
+ else
194
+ puts Util.align_text(JSON.pretty_generate(result), 10000)
195
+ end
196
+ puts
197
+ end
198
+
199
+ success ? exit(0) : exit(1)
200
+ end
201
+
202
+ def main
203
+ send("%s_command" % configuration[:__command])
204
+ end
205
+ end
206
+ end
207
+ end
@@ -1,6 +1,5 @@
1
1
  module MCollective
2
- class Application::Plugin<Application
3
-
2
+ class Application::Plugin < Application # rubocop:disable Style/ClassAndModuleChildren
4
3
  exclude_argument_sections "common", "filter", "rpc"
5
4
 
6
5
  description "MCollective Plugin Application"
@@ -18,119 +17,119 @@ mco plugin package [options] <directory>
18
17
  END_OF_USAGE
19
18
 
20
19
  option :pluginname,
21
- :description => 'Plugin name',
22
- :arguments => ['-n', '--name NAME'],
23
- :type => String
20
+ :description => "Plugin name",
21
+ :arguments => ["-n", "--name NAME"],
22
+ :type => String
24
23
 
25
24
  option :postinstall,
26
- :description => 'Post install script',
27
- :arguments => ['--postinstall POSTINSTALL'],
28
- :type => String
25
+ :description => "Post install script",
26
+ :arguments => ["--postinstall POSTINSTALL"],
27
+ :type => String
29
28
 
30
29
  option :preinstall,
31
- :description => 'Pre install script',
32
- :arguments => ['--preinstall PREINSTALL'],
33
- :type => String
30
+ :description => "Pre install script",
31
+ :arguments => ["--preinstall PREINSTALL"],
32
+ :type => String
34
33
 
35
34
  option :revision,
36
- :description => 'Revision number',
37
- :arguments => ['--revision REVISION'],
38
- :type => String
35
+ :description => "Revision number",
36
+ :arguments => ["--revision REVISION"],
37
+ :type => String
39
38
 
40
39
  option :iteration,
41
- :description => 'DEPRECATED - Use --revision instead',
42
- :arguments => ['--iteration ITERATION'],
43
- :type => String
40
+ :description => "DEPRECATED - Use --revision instead",
41
+ :arguments => ["--iteration ITERATION"],
42
+ :type => String
44
43
 
45
44
  option :vendor,
46
- :description => 'Vendor name',
47
- :arguments => ['--vendor VENDOR'],
48
- :type => String
45
+ :description => "Vendor name",
46
+ :arguments => ["--vendor VENDOR"],
47
+ :type => String
49
48
 
50
49
  option :pluginpath,
51
- :description => 'MCollective plugin path',
52
- :arguments => ['--pluginpath PATH'],
53
- :type => String
50
+ :description => "MCollective plugin path",
51
+ :arguments => ["--pluginpath PATH"],
52
+ :type => String
54
53
 
55
54
  option :mcname,
56
- :description => 'MCollective type (mcollective, pe-mcollective) that the packages depend on',
57
- :arguments => ['--mcname NAME'],
58
- :type => String
55
+ :description => "MCollective type (mcollective, pe-mcollective) that the packages depend on",
56
+ :arguments => ["--mcname NAME"],
57
+ :type => String
59
58
 
60
59
  option :mcversion,
61
- :description => 'Version of MCollective that the packages depend on',
62
- :arguments => ['--mcversion MCVERSION'],
63
- :type => String
60
+ :description => "Version of MCollective that the packages depend on",
61
+ :arguments => ["--mcversion MCVERSION"],
62
+ :type => String
64
63
 
65
64
  option :dependency,
66
- :description => 'Adds a dependency to the plugin',
67
- :arguments => ['--dependency DEPENDENCIES'],
68
- :type => :array
65
+ :description => "Adds a dependency to the plugin",
66
+ :arguments => ["--dependency DEPENDENCIES"],
67
+ :type => :array
69
68
 
70
69
  option :format,
71
- :description => 'Package output format. Defaults to rpmpackage or debpackage',
72
- :arguments => ['--format OUTPUTFORMAT'],
73
- :type => String
70
+ :description => "Package output format. Defaults to rpmpackage or debpackage",
71
+ :arguments => ["--format OUTPUTFORMAT"],
72
+ :type => String
74
73
 
75
74
  option :sign,
76
- :description => 'Embed a signature in the package',
77
- :arguments => ['--sign'],
78
- :type => :boolean
75
+ :description => "Embed a signature in the package",
76
+ :arguments => ["--sign"],
77
+ :type => :boolean
79
78
 
80
79
  option :rpctemplate,
81
- :description => 'Template to use.',
82
- :arguments => ['--template HELPTEMPLATE'],
83
- :type => String
80
+ :description => "Template to use.",
81
+ :arguments => ["--template HELPTEMPLATE"],
82
+ :type => String
84
83
 
85
84
  option :description,
86
- :description => 'Plugin description',
87
- :arguments => ['--description DESCRIPTION'],
88
- :type => String
85
+ :description => "Plugin description",
86
+ :arguments => ["--description DESCRIPTION"],
87
+ :type => String
89
88
 
90
89
  option :author,
91
- :description => 'The author of the plugin',
92
- :arguments => ['--author AUTHOR'],
93
- :type => String
90
+ :description => "The author of the plugin",
91
+ :arguments => ["--author AUTHOR"],
92
+ :type => String
94
93
 
95
94
  option :license,
96
- :description => 'The license under which the plugin is distributed',
97
- :arguments => ['--license LICENSE'],
98
- :type => String
95
+ :description => "The license under which the plugin is distributed",
96
+ :arguments => ["--license LICENSE"],
97
+ :type => String
99
98
 
100
99
  option :version,
101
- :description => 'The version of the plugin',
102
- :arguments => ['--pluginversion VERSION'],
103
- :type => String
100
+ :description => "The version of the plugin",
101
+ :arguments => ["--pluginversion VERSION"],
102
+ :type => String
104
103
 
105
104
  option :url,
106
- :description => 'Url at which information about the plugin can be found',
107
- :arguments => ['--url URL'],
108
- :type => String
105
+ :description => "Url at which information about the plugin can be found",
106
+ :arguments => ["--url URL"],
107
+ :type => String
109
108
 
110
109
  option :timeout,
111
110
  :description => "The plugin's timeout",
112
- :arguments => ['--timeout TIMEOUT'],
113
- :type => Integer
111
+ :arguments => ["--timeout TIMEOUT"],
112
+ :type => Integer
114
113
 
115
114
  option :actions,
116
- :description => 'Actions to be generated for an Agent Plugin',
117
- :arguments => ['--actions [ACTIONS]'],
118
- :type => Array
115
+ :description => "Actions to be generated for an Agent Plugin",
116
+ :arguments => ["--actions [ACTIONS]"],
117
+ :type => Array
119
118
 
120
119
  option :outputs,
121
- :description => 'Outputs to be generated for an Data Plugin',
122
- :arguments => ['--outputs [OUTPUTS]'],
123
- :type => Array
120
+ :description => "Outputs to be generated for an Data Plugin",
121
+ :arguments => ["--outputs [OUTPUTS]"],
122
+ :type => Array
124
123
 
125
124
  option :keep_artifacts,
126
125
  :description => "Don't remove artifacts after building packages",
127
- :arguments => ['--keep-artifacts'],
128
- :type => :boolean
126
+ :arguments => ["--keep-artifacts"],
127
+ :type => :boolean
129
128
 
130
129
  option :module_template,
131
130
  :description => "Path to the template used by the modulepackager",
132
- :arguments => ['--module-template PATH'],
133
- :type => String
131
+ :arguments => ["--module-template PATH"],
132
+ :type => String
134
133
 
135
134
  # Handle alternative format that optparser can't parse.
136
135
  def post_option_parser(configuration)
@@ -141,16 +140,16 @@ mco plugin package [options] <directory>
141
140
 
142
141
  if configuration[:action] == "generate"
143
142
  unless ARGV[0] && ARGV[0].match(/(actions|outputs)=(.+)/i)
144
- unless configuration[:pluginname]
145
- configuration[:pluginname] = ARGV.delete_at(0)
146
- else
143
+ if configuration[:pluginname] # rubocop:disable Metrics/BlockNesting
147
144
  ARGV.delete_at(0)
145
+ else
146
+ configuration[:pluginname] = ARGV.delete_at(0)
148
147
  end
149
148
  end
150
149
 
151
150
  ARGV.each do |argument|
152
151
  if argument.match(/(actions|outputs)=(.+)/i)
153
- configuration[$1.downcase.to_sym]= $2.split(",")
152
+ configuration[$1.downcase.to_sym] = $2.split(",")
154
153
  else
155
154
  raise "Could not parse --arg '#{argument}'"
156
155
  end
@@ -168,7 +167,7 @@ mco plugin package [options] <directory>
168
167
 
169
168
  # Generate a plugin skeleton
170
169
  def generate_command
171
- raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] == '.'
170
+ raise "undefined plugin type. cannot generate plugin. valid types are 'agent' and 'data'" if configuration["target"] == "."
172
171
 
173
172
  unless configuration[:pluginname]
174
173
  puts "No plugin name specified. Using 'new_plugin'"
@@ -178,15 +177,16 @@ mco plugin package [options] <directory>
178
177
  load_plugin_config_values
179
178
 
180
179
  case configuration[:target].downcase
181
- when 'agent'
180
+ when "agent"
182
181
  Generators::AgentGenerator.new(configuration[:pluginname], configuration[:actions], configuration[:pluginname],
183
182
  configuration[:description], configuration[:author], configuration[:license],
184
183
  configuration[:version], configuration[:url], configuration[:timeout])
185
- when 'data'
184
+ when "data"
186
185
  raise "data plugin must have at least one output" unless configuration[:outputs]
186
+
187
187
  Generators::DataGenerator.new(configuration[:pluginname], configuration[:outputs], configuration[:pluginname],
188
- configuration[:description], configuration[:author], configuration[:license],
189
- configuration[:version], configuration[:url], configuration[:timeout])
188
+ configuration[:description], configuration[:author], configuration[:license],
189
+ configuration[:version], configuration[:url], configuration[:timeout])
190
190
  else
191
191
  raise "invalid plugin type. cannot generate plugin '#{configuration[:target]}'"
192
192
  end
@@ -196,11 +196,11 @@ mco plugin package [options] <directory>
196
196
  def package_command
197
197
  if configuration[:sign] && Config.instance.pluginconf.include?("debian_packager.keyname")
198
198
  configuration[:sign] = Config.instance.pluginconf["debian_packager.keyname"]
199
- configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(/\".*\"/)
199
+ configuration[:sign] = "\"#{configuration[:sign]}\"" unless configuration[:sign].match(/".*"/)
200
200
  end
201
201
 
202
202
  plugin = prepare_plugin
203
- (configuration[:pluginpath] = configuration[:pluginpath] + "/") if (configuration[:pluginpath] && !configuration[:pluginpath].match(/^.*\/$/))
203
+ (configuration[:pluginpath] = "#{configuration[:pluginpath]}/") if configuration[:pluginpath] && !configuration[:pluginpath].match(/^.*\/$/)
204
204
  packager = PluginPackager["#{configuration[:format].capitalize}Packager"]
205
205
  packager.new(plugin, configuration[:pluginpath], configuration[:sign],
206
206
  options[:verbose], configuration[:keep_artifacts],
@@ -219,11 +219,11 @@ mco plugin package [options] <directory>
219
219
  end
220
220
  end
221
221
 
222
- return nil
222
+ nil
223
223
  end
224
224
 
225
225
  # Show application list and plugin help
226
- def doc_command
226
+ def doc_command # rubocop:disable Metrics/MethodLength
227
227
  known_plugin_types = [
228
228
  ["Agents", :agent],
229
229
  ["Aggregate", :aggregate],
@@ -240,12 +240,12 @@ mco plugin package [options] <directory>
240
240
  found_plugin_type = nil
241
241
 
242
242
  known_plugin_types.each do |plugin_type|
243
- PluginManager.find(plugin_type[1], "ddl").each do |ddl|
244
- pluginname = ddl.gsub(/_#{plugin_type[1]}$/, "")
245
- if pluginname == configuration[:target]
246
- abort "Duplicate plugin name found, please specify a full path like agent/rpcutil" if found_plugin_type
247
- found_plugin_type = plugin_type[1]
248
- end
243
+ PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
244
+ pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
245
+
246
+ abort "Duplicate plugin name found, please specify a full path like agent/rpcutil" if pluginname == configuration[:target] && found_plugin_type
247
+
248
+ found_plugin_type = plugin_type[1] if pluginname == configuration[:target]
249
249
  end
250
250
  end
251
251
 
@@ -256,7 +256,7 @@ mco plugin package [options] <directory>
256
256
  if ddl
257
257
  puts ddl.help(configuration[:rpctemplate])
258
258
  else
259
- abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split('/')
259
+ abort "Could not find a '%s' plugin named '%s'" % configuration[:target].split("/")
260
260
  end
261
261
 
262
262
  else
@@ -268,17 +268,17 @@ mco plugin package [options] <directory>
268
268
  known_plugin_types.each do |plugin_type|
269
269
  puts "%s:" % plugin_type[0]
270
270
 
271
- PluginManager.find(plugin_type[1], "ddl").each do |ddl|
271
+ PluginManager.find(plugin_type[1], "ddl").each do |ddlf|
272
272
  begin
273
- help = DDL.new(ddl, plugin_type[1], false)
273
+ help = DDL.new(ddlf, plugin_type[1], false)
274
274
 
275
275
  next unless help.client_activated?
276
276
 
277
277
  help.loadddlfile
278
- pluginname = ddl.gsub(/_#{plugin_type[1]}$/, "")
278
+ pluginname = ddlf.gsub(/_#{plugin_type[1]}$/, "")
279
279
  puts " %-25s %s" % [pluginname, help.meta[:description]]
280
280
  rescue => e
281
- load_errors << [plugin_type[1], ddl, e]
281
+ load_errors << [plugin_type[1], ddlf, e]
282
282
  end
283
283
  end
284
284
 
@@ -305,7 +305,7 @@ mco plugin package [options] <directory>
305
305
  if configuration[:dependency] && configuration[:dependency].size == 1
306
306
  configuration[:dependency] = configuration[:dependency][0].split(" ")
307
307
  elsif configuration[:dependency]
308
- configuration[:dependency].map!{|dep| {:name => dep, :version => nil}}
308
+ configuration[:dependency].map! {|dep| {:name => dep, :version => nil}}
309
309
  end
310
310
 
311
311
  mcdependency = {
@@ -315,7 +315,7 @@ mco plugin package [options] <directory>
315
315
 
316
316
  # Deprecation warning for --iteration
317
317
  if configuration[:iteration]
318
- puts 'Warning. The --iteration flag has been deprecated. Please use --revision instead.'
318
+ puts "Warning. The --iteration flag has been deprecated. Please use --revision instead."
319
319
  configuration[:revision] = configuration[:iteration] unless configuration[:revision]
320
320
  end
321
321
 
@@ -330,12 +330,12 @@ mco plugin package [options] <directory>
330
330
  def set_plugin_type
331
331
  if plugin_directory_exists?("agent") || plugin_directory_exists?("application")
332
332
  configuration[:plugintype] = "AgentDefinition"
333
- return "Agent"
333
+ "Agent"
334
334
  elsif plugin_directory_exists?(plugintype = identify_plugin)
335
335
  configuration[:plugintype] = "StandardDefinition"
336
- return plugintype
336
+ plugintype
337
337
  else
338
- raise RuntimeError, "target directory is not a valid mcollective plugin"
338
+ raise "target directory is not a valid mcollective plugin"
339
339
  end
340
340
  end
341
341
 
@@ -348,8 +348,8 @@ mco plugin package [options] <directory>
348
348
  File.directory?(file) && file.match(/(connector|facts|registration|security|audit|pluginpackager|data|discovery|validator)/)
349
349
  end
350
350
 
351
- raise RuntimeError, "more than one plugin type detected in directory" if plugintype.size > 1
352
- raise RuntimeError, "no plugins detected in directory" if plugintype.size < 1
351
+ raise "more than one plugin type detected in directory" if plugintype.size > 1
352
+ raise "no plugins detected in directory" if plugintype.empty?
353
353
 
354
354
  File.basename(plugintype[0])
355
355
  end
@@ -367,15 +367,15 @@ mco plugin package [options] <directory>
367
367
  end
368
368
 
369
369
  def main
370
- abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action)
370
+ abort "No action specified, please run 'mco help plugin' for help" unless configuration.include?(:action)
371
371
 
372
- cmd = "#{configuration[:action]}_command"
372
+ cmd = "#{configuration[:action]}_command"
373
373
 
374
- if respond_to? cmd
375
- send cmd
376
- else
377
- abort "Invalid action #{configuration[:action]}, please run 'mco help plugin' for help."
378
- end
374
+ if respond_to? cmd
375
+ send cmd
376
+ else
377
+ abort "Invalid action #{configuration[:action]}, please run 'mco help plugin' for help."
378
+ end
379
379
  end
380
380
  end
381
381
  end