chef 12.3.0 → 12.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +86 -7
  3. data/distro/common/markdown/man1/chef-shell.mkd +4 -4
  4. data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
  5. data/distro/common/markdown/man1/knife-client.mkd +1 -1
  6. data/distro/common/markdown/man1/knife-configure.mkd +1 -1
  7. data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
  8. data/distro/common/markdown/man1/knife-cookbook.mkd +4 -4
  9. data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
  10. data/distro/common/markdown/man1/knife-environment.mkd +3 -3
  11. data/distro/common/markdown/man1/knife-exec.mkd +1 -1
  12. data/distro/common/markdown/man1/knife-index.mkd +1 -1
  13. data/distro/common/markdown/man1/knife-node.mkd +1 -1
  14. data/distro/common/markdown/man1/knife-role.mkd +3 -3
  15. data/distro/common/markdown/man1/knife-search.mkd +2 -2
  16. data/distro/common/markdown/man1/knife-ssh.mkd +1 -1
  17. data/distro/common/markdown/man1/knife-status.mkd +1 -1
  18. data/distro/common/markdown/man1/knife-tag.mkd +1 -1
  19. data/distro/common/markdown/man1/knife.mkd +2 -2
  20. data/distro/common/markdown/man8/chef-client.mkd +1 -2
  21. data/distro/common/markdown/man8/chef-expander.mkd +1 -2
  22. data/distro/common/markdown/man8/chef-expanderctl.mkd +1 -2
  23. data/distro/common/markdown/man8/chef-server-webui.mkd +1 -1
  24. data/distro/common/markdown/man8/chef-server.mkd +1 -2
  25. data/distro/common/markdown/man8/chef-solo.mkd +2 -2
  26. data/distro/common/markdown/man8/chef-solr.mkd +1 -1
  27. data/lib/chef/client.rb +2 -2
  28. data/lib/chef/config.rb +17 -709
  29. data/lib/chef/cookbook/metadata.rb +9 -5
  30. data/lib/chef/cookbook_loader.rb +1 -1
  31. data/lib/chef/cookbook_site_streaming_uploader.rb +2 -18
  32. data/lib/chef/dsl/definitions.rb +44 -0
  33. data/lib/chef/dsl/recipe.rb +50 -35
  34. data/lib/chef/dsl/resources.rb +28 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +2 -0
  36. data/lib/chef/event_loggers/windows_eventlog.rb +1 -11
  37. data/lib/chef/exceptions.rb +4 -0
  38. data/lib/chef/file_access_control/unix.rb +5 -0
  39. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +17 -0
  40. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +21 -9
  41. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +2 -0
  42. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +2 -0
  43. data/lib/chef/formatters/error_inspectors/node_load_error_inspector.rb +2 -0
  44. data/lib/chef/formatters/error_inspectors/registration_error_inspector.rb +4 -0
  45. data/lib/chef/formatters/error_inspectors/resource_failure_inspector.rb +11 -1
  46. data/lib/chef/formatters/error_inspectors/run_list_expansion_error_inspector.rb +2 -0
  47. data/lib/chef/http/authenticator.rb +3 -0
  48. data/lib/chef/http/basic_client.rb +10 -6
  49. data/lib/chef/http/json_input.rb +6 -1
  50. data/lib/chef/key.rb +271 -0
  51. data/lib/chef/knife.rb +11 -1
  52. data/lib/chef/knife/bootstrap.rb +6 -0
  53. data/lib/chef/knife/bootstrap/templates/chef-full.erb +166 -23
  54. data/lib/chef/knife/client_key_create.rb +67 -0
  55. data/lib/chef/knife/client_key_delete.rb +76 -0
  56. data/lib/chef/knife/client_key_edit.rb +80 -0
  57. data/lib/chef/knife/client_key_list.rb +69 -0
  58. data/lib/chef/knife/client_key_show.rb +76 -0
  59. data/lib/chef/knife/key_create.rb +108 -0
  60. data/lib/chef/knife/key_create_base.rb +50 -0
  61. data/lib/chef/knife/key_delete.rb +55 -0
  62. data/lib/chef/knife/key_edit.rb +114 -0
  63. data/lib/chef/knife/key_edit_base.rb +55 -0
  64. data/lib/chef/knife/key_list.rb +88 -0
  65. data/lib/chef/knife/key_list_base.rb +45 -0
  66. data/lib/chef/knife/key_show.rb +53 -0
  67. data/lib/chef/knife/ssh.rb +26 -28
  68. data/lib/chef/knife/user_key_create.rb +69 -0
  69. data/lib/chef/knife/user_key_delete.rb +76 -0
  70. data/lib/chef/knife/user_key_edit.rb +80 -0
  71. data/lib/chef/knife/user_key_list.rb +69 -0
  72. data/lib/chef/knife/user_key_show.rb +76 -0
  73. data/lib/chef/log.rb +2 -0
  74. data/lib/chef/log/syslog.rb +46 -0
  75. data/lib/chef/log/winevt.rb +99 -0
  76. data/lib/chef/mixin/provides.rb +8 -1
  77. data/lib/chef/mixin/unformatter.rb +32 -0
  78. data/lib/chef/mixin/uris.rb +33 -0
  79. data/lib/chef/mixin/wstring.rb +31 -0
  80. data/lib/chef/node.rb +21 -2
  81. data/lib/chef/platform/provider_mapping.rb +8 -4
  82. data/lib/chef/platform/query_helpers.rb +1 -5
  83. data/lib/chef/platform/service_helpers.rb +21 -21
  84. data/lib/chef/provider.rb +33 -0
  85. data/lib/chef/provider/cron/unix.rb +1 -0
  86. data/lib/chef/provider/file.rb +5 -3
  87. data/lib/chef/provider/lwrp_base.rb +76 -58
  88. data/lib/chef/provider/ohai.rb +1 -0
  89. data/lib/chef/provider/package.rb +7 -4
  90. data/lib/chef/provider/package/aix.rb +1 -0
  91. data/lib/chef/provider/package/smartos.rb +5 -5
  92. data/lib/chef/provider/package/windows.rb +90 -6
  93. data/lib/chef/provider/package/yum.rb +102 -32
  94. data/lib/chef/provider/reboot.rb +1 -0
  95. data/lib/chef/provider/registry_key.rb +2 -0
  96. data/lib/chef/provider/remote_file.rb +1 -0
  97. data/lib/chef/provider/remote_file/content.rb +5 -1
  98. data/lib/chef/provider/remote_file/fetcher.rb +22 -8
  99. data/lib/chef/provider/remote_file/network_file.rb +48 -0
  100. data/lib/chef/provider/service/aix.rb +13 -12
  101. data/lib/chef/provider_resolver.rb +87 -0
  102. data/lib/chef/providers.rb +1 -0
  103. data/lib/chef/resource.rb +67 -8
  104. data/lib/chef/resource/bash.rb +1 -0
  105. data/lib/chef/resource/bff_package.rb +1 -2
  106. data/lib/chef/resource/breakpoint.rb +1 -0
  107. data/lib/chef/resource/csh.rb +1 -0
  108. data/lib/chef/resource/deploy.rb +1 -0
  109. data/lib/chef/resource/erl_call.rb +1 -0
  110. data/lib/chef/resource/execute.rb +1 -0
  111. data/lib/chef/resource/file.rb +18 -0
  112. data/lib/chef/resource/http_request.rb +1 -0
  113. data/lib/chef/resource/ifconfig.rb +1 -2
  114. data/lib/chef/resource/log.rb +1 -2
  115. data/lib/chef/resource/lwrp_base.rb +106 -87
  116. data/lib/chef/resource/ohai.rb +1 -0
  117. data/lib/chef/resource/package.rb +1 -0
  118. data/lib/chef/resource/perl.rb +1 -0
  119. data/lib/chef/resource/portage_package.rb +1 -0
  120. data/lib/chef/resource/python.rb +1 -0
  121. data/lib/chef/resource/reboot.rb +2 -0
  122. data/lib/chef/resource/registry_key.rb +1 -0
  123. data/lib/chef/resource/remote_file.rb +1 -1
  124. data/lib/chef/resource/route.rb +1 -2
  125. data/lib/chef/resource/ruby.rb +1 -0
  126. data/lib/chef/resource/ruby_block.rb +1 -0
  127. data/lib/chef/resource/scm.rb +1 -0
  128. data/lib/chef/resource/script.rb +1 -0
  129. data/lib/chef/resource/service.rb +1 -0
  130. data/lib/chef/resource/subversion.rb +1 -0
  131. data/lib/chef/resource/whyrun_safe_ruby_block.rb +1 -0
  132. data/lib/chef/resource/windows_package.rb +24 -2
  133. data/lib/chef/resource/windows_script.rb +1 -0
  134. data/lib/chef/resource/yum_package.rb +1 -1
  135. data/lib/chef/resource_definition.rb +1 -0
  136. data/lib/chef/resource_reporter.rb +3 -10
  137. data/lib/chef/resource_resolver.rb +20 -10
  138. data/lib/chef/run_context.rb +1 -0
  139. data/lib/chef/run_list/versioned_recipe_list.rb +18 -0
  140. data/lib/chef/run_status.rb +2 -4
  141. data/lib/chef/shell.rb +1 -1
  142. data/lib/chef/util/path_helper.rb +3 -204
  143. data/lib/chef/util/windows/net_user.rb +73 -118
  144. data/lib/chef/version.rb +8 -4
  145. data/lib/chef/win32/api.rb +2 -1
  146. data/lib/chef/win32/api/installer.rb +1 -1
  147. data/lib/chef/win32/api/net.rb +115 -2
  148. data/lib/chef/win32/api/security.rb +24 -0
  149. data/lib/chef/win32/api/unicode.rb +1 -1
  150. data/lib/chef/win32/eventlog.rb +31 -0
  151. data/lib/chef/win32/net.rb +190 -0
  152. data/lib/chef/win32/security.rb +51 -2
  153. data/lib/chef/win32/security/sid.rb +17 -0
  154. data/spec/data/lwrp/providers/buck_passer.rb +18 -2
  155. data/spec/data/lwrp/providers/buck_passer_2.rb +18 -2
  156. data/spec/data/lwrp/providers/embedded_resource_accesses_providers_scope.rb +14 -2
  157. data/spec/data/lwrp_override/resources/foo.rb +5 -0
  158. data/spec/functional/knife/ssh_spec.rb +2 -2
  159. data/spec/functional/rebooter_spec.rb +1 -1
  160. data/spec/functional/resource/aixinit_service_spec.rb +1 -1
  161. data/spec/functional/resource/user/windows_spec.rb +125 -0
  162. data/spec/functional/shell_spec.rb +25 -10
  163. data/spec/functional/win32/sid_spec.rb +55 -0
  164. data/spec/integration/client/client_spec.rb +53 -29
  165. data/spec/integration/knife/deps_spec.rb +8 -14
  166. data/spec/integration/knife/upload_spec.rb +18 -0
  167. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
  168. data/spec/integration/recipes/provider_choice.rb +41 -0
  169. data/spec/integration/recipes/recipe_dsl_spec.rb +259 -0
  170. data/spec/spec_helper.rb +6 -1
  171. data/spec/support/key_helpers.rb +104 -0
  172. data/spec/support/lib/chef/resource/cat.rb +1 -0
  173. data/spec/support/lib/chef/resource/one_two_three_four.rb +2 -0
  174. data/spec/support/lib/chef/resource/zen_follower.rb +1 -0
  175. data/spec/support/lib/chef/resource/zen_master.rb +2 -0
  176. data/spec/support/mock/platform.rb +1 -1
  177. data/spec/support/pedant/Gemfile.lock +67 -0
  178. data/spec/support/shared/functional/securable_resource.rb +34 -12
  179. data/spec/support/shared/integration/integration_helper.rb +6 -5
  180. data/spec/support/shared/unit/provider/file.rb +31 -8
  181. data/spec/unit/application/client_spec.rb +2 -2
  182. data/spec/unit/client_spec.rb +21 -4
  183. data/spec/unit/cookbook/cookbook_version_loader_spec.rb +1 -1
  184. data/spec/unit/cookbook/metadata_spec.rb +15 -0
  185. data/spec/unit/cookbook/syntax_check_spec.rb +1 -1
  186. data/spec/unit/cookbook_loader_spec.rb +1 -1
  187. data/spec/unit/cookbook_site_streaming_uploader_spec.rb +0 -21
  188. data/spec/unit/data_bag_spec.rb +1 -1
  189. data/spec/unit/event_dispatch/dispatcher_spec.rb +61 -0
  190. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +75 -0
  191. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +149 -112
  192. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +7 -0
  193. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +1 -1
  194. data/spec/unit/http/authenticator_spec.rb +69 -0
  195. data/spec/unit/http/basic_client_spec.rb +16 -0
  196. data/spec/unit/key_spec.rb +634 -0
  197. data/spec/unit/knife/bootstrap_spec.rb +14 -1
  198. data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -1
  199. data/spec/unit/knife/core/ui_spec.rb +1 -1
  200. data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
  201. data/spec/unit/knife/environment_from_file_spec.rb +1 -1
  202. data/spec/unit/knife/key_create_spec.rb +224 -0
  203. data/spec/unit/knife/key_delete_spec.rb +135 -0
  204. data/spec/unit/knife/key_edit_spec.rb +267 -0
  205. data/spec/unit/knife/key_helper.rb +74 -0
  206. data/spec/unit/knife/key_list_spec.rb +216 -0
  207. data/spec/unit/knife/key_show_spec.rb +126 -0
  208. data/spec/unit/knife/ssh_spec.rb +23 -26
  209. data/spec/unit/knife_spec.rb +33 -1
  210. data/spec/unit/log/syslog_spec.rb +53 -0
  211. data/spec/unit/log/winevt_spec.rb +55 -0
  212. data/spec/unit/lwrp_spec.rb +105 -51
  213. data/spec/unit/mixin/path_sanity_spec.rb +2 -2
  214. data/spec/unit/mixin/template_spec.rb +2 -2
  215. data/spec/unit/mixin/unformatter_spec.rb +61 -0
  216. data/spec/unit/mixin/uris_spec.rb +45 -0
  217. data/spec/unit/platform/query_helpers_spec.rb +1 -1
  218. data/spec/unit/policy_builder/policyfile_spec.rb +7 -3
  219. data/spec/unit/provider/deploy/revision_spec.rb +1 -1
  220. data/spec/unit/provider/deploy_spec.rb +1 -1
  221. data/spec/unit/provider/directory_spec.rb +1 -1
  222. data/spec/unit/provider/execute_spec.rb +1 -1
  223. data/spec/unit/provider/package/aix_spec.rb +20 -8
  224. data/spec/unit/provider/package/smartos_spec.rb +50 -40
  225. data/spec/unit/provider/package/windows_spec.rb +104 -25
  226. data/spec/unit/provider/package/yum_spec.rb +111 -1
  227. data/spec/unit/provider/package_spec.rb +6 -0
  228. data/spec/unit/provider/remote_file/fetcher_spec.rb +20 -1
  229. data/spec/unit/provider/remote_file/network_file_spec.rb +45 -0
  230. data/spec/unit/provider/service/aix_service_spec.rb +26 -11
  231. data/spec/unit/provider/user/dscl_spec.rb +1 -1
  232. data/spec/unit/provider_spec.rb +20 -0
  233. data/spec/unit/recipe_spec.rb +1 -1
  234. data/spec/unit/resource/batch_spec.rb +1 -0
  235. data/spec/unit/resource/powershell_spec.rb +1 -0
  236. data/spec/unit/resource/remote_file_spec.rb +10 -0
  237. data/spec/unit/resource/windows_package_spec.rb +16 -2
  238. data/spec/unit/resource_spec.rb +40 -24
  239. data/spec/unit/rest_spec.rb +10 -20
  240. data/spec/unit/role_spec.rb +1 -1
  241. data/spec/unit/run_context_spec.rb +31 -0
  242. data/spec/unit/shell_spec.rb +4 -4
  243. data/tasks/external_tests.rb +29 -0
  244. data/tasks/rspec.rb +14 -1
  245. metadata +105 -28
  246. data/spec/unit/config_spec.rb +0 -544
  247. data/spec/unit/util/path_helper_spec.rb +0 -255
@@ -160,6 +160,31 @@ class Chef
160
160
  session_from_list(list)
161
161
  end
162
162
 
163
+ def get_ssh_attribute(node)
164
+ # Order of precedence for ssh target
165
+ # 1) command line attribute
166
+ # 2) configuration file
167
+ # 3) cloud attribute
168
+ # 4) fqdn
169
+ if config[:attribute]
170
+ Chef::Log.debug("Using node attribute '#{config[:attribute]}' as the ssh target")
171
+ attribute = config[:attribute]
172
+ elsif Chef::Config[:knife][:ssh_attribute]
173
+ Chef::Log.debug("Using node attribute #{Chef::Config[:knife][:ssh_attribute]}")
174
+ attribute = Chef::Config[:knife][:ssh_attribute]
175
+ elsif node[:cloud] &&
176
+ node[:cloud][:public_hostname] &&
177
+ !node[:cloud][:public_hostname].empty?
178
+ Chef::Log.debug("Using node attribute 'cloud[:public_hostname]' automatically as the ssh target")
179
+ attribute = 'cloud.public_hostname'
180
+ else
181
+ # falling back to default of fqdn
182
+ Chef::Log.debug("Using node attribute 'fqdn' as the ssh target")
183
+ attribute = "fqdn"
184
+ end
185
+ attribute
186
+ end
187
+
163
188
  def search_nodes
164
189
  list = Array.new
165
190
  query = Chef::Search::Query.new
@@ -168,25 +193,9 @@ class Chef
168
193
  # we should skip the loop to next iteration if the item
169
194
  # returned by the search is nil
170
195
  next if item.nil?
171
- # if a command line attribute was not passed, and we have a
172
- # cloud public_hostname, use that. see #configure_attribute
173
- # for the source of config[:attribute] and
174
- # config[:attribute_from_cli]
175
- if config[:attribute_from_cli]
176
- Chef::Log.debug("Using node attribute '#{config[:attribute_from_cli]}' from the command line as the ssh target")
177
- host = extract_nested_value(item, config[:attribute_from_cli])
178
- elsif item[:cloud] &&
179
- item[:cloud][:public_hostname] &&
180
- !item[:cloud][:public_hostname].empty?
181
- Chef::Log.debug("Using node attribute 'cloud[:public_hostname]' automatically as the ssh target")
182
- host = item[:cloud][:public_hostname]
183
- else
184
- # ssh attribute from a configuration file or the default will land here
185
- Chef::Log.debug("Using node attribute '#{config[:attribute]}' as the ssh target")
186
- host = extract_nested_value(item, config[:attribute])
187
- end
188
196
  # next if we couldn't find the specified attribute in the
189
197
  # returned node object
198
+ host = extract_nested_value(item,get_ssh_attribute(item))
190
199
  next if host.nil?
191
200
  ssh_port = item[:cloud].nil? ? nil : item[:cloud][:public_ssh_port]
192
201
  srv = [host, ssh_port]
@@ -416,16 +425,6 @@ class Chef
416
425
  end
417
426
  end
418
427
 
419
- def configure_attribute
420
- # Setting 'knife[:ssh_attribute] = "foo"' in knife.rb => Chef::Config[:knife][:ssh_attribute] == 'foo'
421
- # Running 'knife ssh -a foo' => both Chef::Config[:knife][:ssh_attribute] && config[:attribute] == foo
422
- # Thus we can differentiate between a config file value and a command line override at this point by checking config[:attribute]
423
- # We can tell here if fqdn was passed from the command line, rather than being the default, by checking config[:attribute]
424
- # However, after here, we cannot tell these things, so we must preserve config[:attribute]
425
- config[:attribute_from_cli] = config[:attribute]
426
- config[:attribute] = (config[:attribute_from_cli] || Chef::Config[:knife][:ssh_attribute] || "fqdn").strip
427
- end
428
-
429
428
  def cssh
430
429
  cssh_cmd = nil
431
430
  %w[csshX cssh].each do |cmd|
@@ -499,7 +498,6 @@ class Chef
499
498
 
500
499
  @longest = 0
501
500
 
502
- configure_attribute
503
501
  configure_user
504
502
  configure_password
505
503
  configure_identity_file
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Tyler Cloke (tyler@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+ require 'chef/knife/key_create_base'
21
+
22
+ class Chef
23
+ class Knife
24
+ # Implements knife user key create using Chef::Knife::KeyCreate
25
+ # as a service class.
26
+ #
27
+ # @author Tyler Cloke
28
+ #
29
+ # @attr_reader [String] actor the name of the user that this key is for
30
+ class UserKeyCreate < Knife
31
+ include Chef::Knife::KeyCreateBase
32
+
33
+ banner 'knife user key create USER (options)'
34
+
35
+ attr_reader :actor
36
+
37
+ def initialize(argv=[])
38
+ super(argv)
39
+ @service_object = nil
40
+ end
41
+
42
+ def run
43
+ apply_params!(@name_args)
44
+ service_object.run
45
+ end
46
+
47
+ def actor_field_name
48
+ 'user'
49
+ end
50
+
51
+ def service_object
52
+ @service_object ||= Chef::Knife::KeyCreate.new(@actor, actor_field_name, ui, config)
53
+ end
54
+
55
+ def actor_missing_error
56
+ 'You must specify a user name'
57
+ end
58
+
59
+ def apply_params!(params)
60
+ @actor = params[0]
61
+ if @actor.nil?
62
+ show_usage
63
+ ui.fatal(actor_missing_error)
64
+ exit 1
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Author:: Tyler Cloke (tyler@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+
21
+ class Chef
22
+ class Knife
23
+ # Implements knife user key delete using Chef::Knife::KeyDelete
24
+ # as a service class.
25
+ #
26
+ # @author Tyler Cloke
27
+ #
28
+ # @attr_reader [String] actor the name of the client that this key is for
29
+ class UserKeyDelete < Knife
30
+ banner "knife user key delete USER KEYNAME (options)"
31
+
32
+ attr_reader :actor
33
+
34
+ def initialize(argv=[])
35
+ super(argv)
36
+ @service_object = nil
37
+ end
38
+
39
+ def run
40
+ apply_params!(@name_args)
41
+ service_object.run
42
+ end
43
+
44
+ def actor_field_name
45
+ 'user'
46
+ end
47
+
48
+ def actor_missing_error
49
+ 'You must specify a user name'
50
+ end
51
+
52
+ def keyname_missing_error
53
+ 'You must specify a key name'
54
+ end
55
+
56
+ def service_object
57
+ @service_object ||= Chef::Knife::KeyDelete.new(@name, @actor, actor_field_name, ui)
58
+ end
59
+
60
+ def apply_params!(params)
61
+ @actor = params[0]
62
+ if @actor.nil?
63
+ show_usage
64
+ ui.fatal(actor_missing_error)
65
+ exit 1
66
+ end
67
+ @name = params[1]
68
+ if @name.nil?
69
+ show_usage
70
+ ui.fatal(keyname_missing_error)
71
+ exit 1
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Tyler Cloke (tyler@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+ require 'chef/knife/key_edit_base'
21
+
22
+ class Chef
23
+ class Knife
24
+ # Implements knife user key edit using Chef::Knife::KeyEdit
25
+ # as a service class.
26
+ #
27
+ # @author Tyler Cloke
28
+ #
29
+ # @attr_reader [String] actor the name of the user that this key is for
30
+ class UserKeyEdit < Knife
31
+ include Chef::Knife::KeyEditBase
32
+
33
+ banner 'knife user key edit USER KEYNAME (options)'
34
+
35
+ attr_reader :actor
36
+
37
+ def initialize(argv=[])
38
+ super(argv)
39
+ @service_object = nil
40
+ end
41
+
42
+ def run
43
+ apply_params!(@name_args)
44
+ service_object.run
45
+ end
46
+
47
+ def actor_field_name
48
+ 'user'
49
+ end
50
+
51
+ def service_object
52
+ @service_object ||= Chef::Knife::KeyEdit.new(@name, @actor, actor_field_name, ui, config)
53
+ end
54
+
55
+ def actor_missing_error
56
+ 'You must specify a user name'
57
+ end
58
+
59
+ def keyname_missing_error
60
+ 'You must specify a key name'
61
+ end
62
+
63
+ def apply_params!(params)
64
+ @actor = params[0]
65
+ if @actor.nil?
66
+ show_usage
67
+ ui.fatal(actor_missing_error)
68
+ exit 1
69
+ end
70
+ @name = params[1]
71
+ if @name.nil?
72
+ show_usage
73
+ ui.fatal(keyname_missing_error)
74
+ exit 1
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Tyler Cloke (tyler@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+ require 'chef/knife/key_list_base'
21
+
22
+ class Chef
23
+ class Knife
24
+ # Implements knife user key list using Chef::Knife::KeyList
25
+ # as a service class.
26
+ #
27
+ # @author Tyler Cloke
28
+ #
29
+ # @attr_reader [String] actor the name of the client that this key is for
30
+ class UserKeyList < Knife
31
+ include Chef::Knife::KeyListBase
32
+
33
+ banner "knife user key list USER (options)"
34
+
35
+ attr_reader :actor
36
+
37
+ def initialize(argv=[])
38
+ super(argv)
39
+ @service_object = nil
40
+ end
41
+
42
+ def run
43
+ apply_params!(@name_args)
44
+ service_object.run
45
+ end
46
+
47
+ def list_method
48
+ :list_by_user
49
+ end
50
+
51
+ def actor_missing_error
52
+ 'You must specify a user name'
53
+ end
54
+
55
+ def service_object
56
+ @service_object ||= Chef::Knife::KeyList.new(@actor, list_method, ui, config)
57
+ end
58
+
59
+ def apply_params!(params)
60
+ @actor = params[0]
61
+ if @actor.nil?
62
+ show_usage
63
+ ui.fatal(actor_missing_error)
64
+ exit 1
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Author:: Tyler Cloke (tyler@chef.io)
3
+ # Copyright:: Copyright (c) 2015 Chef Software, Inc
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife'
20
+
21
+ class Chef
22
+ class Knife
23
+ # Implements knife user key show using Chef::Knife::KeyShow
24
+ # as a service class.
25
+ #
26
+ # @author Tyler Cloke
27
+ #
28
+ # @attr_reader [String] actor the name of the client that this key is for
29
+ class UserKeyShow < Knife
30
+ banner "knife user key show USER KEYNAME (options)"
31
+
32
+ attr_reader :actor
33
+
34
+ def initialize(argv=[])
35
+ super(argv)
36
+ @service_object = nil
37
+ end
38
+
39
+ def run
40
+ apply_params!(@name_args)
41
+ service_object.run
42
+ end
43
+
44
+ def load_method
45
+ :load_by_user
46
+ end
47
+
48
+ def actor_missing_error
49
+ 'You must specify a user name'
50
+ end
51
+
52
+ def keyname_missing_error
53
+ 'You must specify a key name'
54
+ end
55
+
56
+ def service_object
57
+ @service_object ||= Chef::Knife::KeyShow.new(@name, @actor, load_method, ui)
58
+ end
59
+
60
+ def apply_params!(params)
61
+ @actor = params[0]
62
+ if @actor.nil?
63
+ show_usage
64
+ ui.fatal(actor_missing_error)
65
+ exit 1
66
+ end
67
+ @name = params[1]
68
+ if @name.nil?
69
+ show_usage
70
+ ui.fatal(keyname_missing_error)
71
+ exit 1
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end