knife-azure 1.6.0.rc.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +304 -8
  3. data/lib/azure/azure_interface.rb +81 -0
  4. data/lib/azure/custom_errors.rb +35 -0
  5. data/lib/azure/helpers.rb +44 -0
  6. data/lib/azure/resource_management/ARM_base.rb +29 -0
  7. data/lib/azure/resource_management/ARM_deployment_template.rb +561 -0
  8. data/lib/azure/resource_management/ARM_interface.rb +795 -0
  9. data/lib/azure/resource_management/windows_credentials.rb +136 -0
  10. data/lib/azure/service_management/ASM_interface.rb +301 -0
  11. data/lib/azure/{ag.rb → service_management/ag.rb} +2 -2
  12. data/lib/azure/{certificate.rb → service_management/certificate.rb} +2 -2
  13. data/lib/azure/service_management/connection.rb +102 -0
  14. data/lib/azure/{deploy.rb → service_management/deploy.rb} +8 -2
  15. data/lib/azure/{disk.rb → service_management/disk.rb} +2 -2
  16. data/lib/azure/{host.rb → service_management/host.rb} +2 -2
  17. data/lib/azure/{image.rb → service_management/image.rb} +2 -2
  18. data/lib/azure/{loadbalancer.rb → service_management/loadbalancer.rb} +4 -18
  19. data/lib/azure/{rest.rb → service_management/rest.rb} +15 -10
  20. data/lib/azure/{role.rb → service_management/role.rb} +174 -6
  21. data/lib/azure/{storageaccount.rb → service_management/storageaccount.rb} +2 -2
  22. data/lib/azure/{utility.rb → service_management/utility.rb} +0 -0
  23. data/lib/azure/{vnet.rb → service_management/vnet.rb} +2 -2
  24. data/lib/chef/knife/azure_ag_create.rb +3 -6
  25. data/lib/chef/knife/azure_ag_list.rb +2 -16
  26. data/lib/chef/knife/azure_base.rb +89 -22
  27. data/lib/chef/knife/azure_image_list.rb +3 -7
  28. data/lib/chef/knife/azure_internal-lb_create.rb +2 -5
  29. data/lib/chef/knife/azure_internal-lb_list.rb +2 -16
  30. data/lib/chef/knife/azure_server_create.rb +122 -501
  31. data/lib/chef/knife/azure_server_delete.rb +15 -38
  32. data/lib/chef/knife/azure_server_list.rb +2 -27
  33. data/lib/chef/knife/azure_server_show.rb +4 -60
  34. data/lib/chef/knife/azure_vnet_create.rb +2 -7
  35. data/lib/chef/knife/azure_vnet_list.rb +2 -17
  36. data/lib/chef/knife/azurerm_base.rb +228 -0
  37. data/lib/chef/knife/azurerm_server_create.rb +393 -0
  38. data/lib/chef/knife/azurerm_server_delete.rb +121 -0
  39. data/lib/chef/knife/azurerm_server_list.rb +18 -0
  40. data/lib/chef/knife/azurerm_server_show.rb +37 -0
  41. data/lib/chef/knife/bootstrap/bootstrap_options.rb +105 -0
  42. data/lib/chef/knife/bootstrap/bootstrapper.rb +343 -0
  43. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +116 -0
  44. data/lib/chef/knife/bootstrap_azure.rb +110 -0
  45. data/lib/chef/knife/bootstrap_azurerm.rb +116 -0
  46. data/lib/knife-azure/version.rb +1 -2
  47. metadata +132 -16
  48. data/lib/azure/connection.rb +0 -99
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../azurerm_base', __FILE__)
2
+
3
+ class Chef
4
+ class Knife
5
+ class AzurermServerList < Knife
6
+
7
+ include Knife::AzurermBase
8
+
9
+ banner "knife azurerm server list (options)"
10
+
11
+ def run
12
+ $stdout.sync = true
13
+ validate_arm_keys!
14
+ service.list_servers(locate_config_value(:azure_resource_group_name))
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Meera Navale (meera.navale@msystechnologies.com)
3
+ # Copyright:: Copyright (c) 2010-2011 Opscode, 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 File.expand_path('../azurerm_base', __FILE__)
20
+
21
+ class Chef
22
+ class Knife
23
+ class AzurermServerShow < Knife
24
+
25
+ include Knife::AzurermBase
26
+
27
+ banner "knife azurerm server show SERVER (options)"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+ validate_arm_keys!(:azure_resource_group_name)
32
+ service.show_server(@name_args[0], locate_config_value(:azure_resource_group_name))
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,105 @@
1
+ #
2
+ # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
+ #
4
+ # Copyright:: Copyright (c) 2016 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/knife/winrm_base'
21
+ require 'chef/knife/bootstrap_windows_base'
22
+ class Chef
23
+ class Knife
24
+ class Bootstrap
25
+ module BootstrapOptions
26
+
27
+ def self.included(includer)
28
+ includer.class_eval do
29
+
30
+ include Knife::WinrmBase
31
+ include Knife::BootstrapWindowsBase
32
+ deps do
33
+ require 'chef/knife/bootstrap'
34
+ Chef::Knife::Bootstrap.load_deps
35
+ end
36
+
37
+ option :forward_agent,
38
+ :short => "-A",
39
+ :long => "--forward-agent",
40
+ :description => "Enable SSH agent forwarding",
41
+ :boolean => true
42
+
43
+ option :json_attributes,
44
+ :short => "-j JSON",
45
+ :long => "--json-attributes JSON",
46
+ :description => "A JSON string to be added to the first run of chef-client",
47
+ :proc => lambda { |o| JSON.parse(o) }
48
+
49
+ option :host_key_verify,
50
+ :long => "--[no-]host-key-verify",
51
+ :description => "Verify host key, enabled by default.",
52
+ :boolean => true,
53
+ :default => true
54
+
55
+ option :bootstrap_url,
56
+ :long => "--bootstrap-url URL",
57
+ :description => "URL to a custom installation script",
58
+ :proc => Proc.new { |u| Chef::Config[:knife][:bootstrap_url] = u }
59
+
60
+ option :bootstrap_wget_options,
61
+ :long => "--bootstrap-wget-options OPTIONS",
62
+ :description => "Add options to wget when installing chef-client",
63
+ :proc => Proc.new { |wo| Chef::Config[:knife][:bootstrap_wget_options] = wo }
64
+
65
+ option :bootstrap_curl_options,
66
+ :long => "--bootstrap-curl-options OPTIONS",
67
+ :description => "Add options to curl when install chef-client",
68
+ :proc => Proc.new { |co| Chef::Config[:knife][:bootstrap_curl_options] = co }
69
+
70
+ option :use_sudo_password,
71
+ :long => "--use-sudo-password",
72
+ :description => "Execute the bootstrap via sudo with password",
73
+ :boolean => false
74
+
75
+ option :auto_update_client,
76
+ :long => "--auto-update-client",
77
+ :boolean => true,
78
+ :default => false,
79
+ :description => "Set this flag to enable auto chef client update in azure chef extension. This flag should be used with cloud-api bootstrap protocol only"
80
+
81
+ option :delete_chef_extension_config,
82
+ :long => "--delete-chef-extension-config",
83
+ :boolean => true,
84
+ :default => false,
85
+ :description => "Determines whether Chef configuration files removed when Azure removes the Chef resource extension from the VM. This option is only valid for the 'cloud-api' bootstrap protocol. The default is false."
86
+
87
+ option :uninstall_chef_client,
88
+ :long => "--uninstall-chef-client",
89
+ :boolean => true,
90
+ :default => false,
91
+ :description => "Determines whether Chef Client will be un-installed from the VM or not. This option is only valid for the 'cloud-api' bootstrap protocol. The default value is false."
92
+
93
+ option :extended_logs,
94
+ :long => "--extended-logs",
95
+ :boolean => true,
96
+ :default => false,
97
+ :description => "Optional. Provide this option when --bootstrap-protocol is set to 'cloud-api'. It shows chef converge logs in detail."
98
+
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+
@@ -0,0 +1,343 @@
1
+ #
2
+ # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
+ #
4
+ # Copyright:: Copyright (c) 2016 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class Chef
21
+ class Knife
22
+ class Bootstrap
23
+ module Bootstrapper
24
+
25
+ def load_winrm_deps
26
+ require 'winrm'
27
+ require 'chef/knife/winrm'
28
+ require 'chef/knife/bootstrap_windows_winrm'
29
+ end
30
+
31
+ def default_bootstrap_template
32
+ is_image_windows? ? 'windows-chef-client-msi' : 'chef-full'
33
+ end
34
+
35
+ def tcp_test_ssh(fqdn, sshport)
36
+ tcp_socket = TCPSocket.new(fqdn, sshport)
37
+ readable = IO.select([tcp_socket], nil, nil, 5)
38
+ if readable
39
+ Chef::Log.debug("sshd accepting connections on #{fqdn}, banner is #{tcp_socket.gets}")
40
+ yield
41
+ true
42
+ else
43
+ false
44
+ end
45
+ rescue SocketError
46
+ sleep 2
47
+ false
48
+ rescue Errno::ETIMEDOUT
49
+ false
50
+ rescue Errno::EPERM
51
+ false
52
+ rescue Errno::ECONNREFUSED
53
+ sleep 2
54
+ false
55
+ rescue Errno::EHOSTUNREACH
56
+ sleep 2
57
+ false
58
+ ensure
59
+ tcp_socket && tcp_socket.close
60
+ end
61
+
62
+ def tcp_test_winrm(ip_addr, port)
63
+ hostname = ip_addr
64
+ socket = TCPSocket.new(hostname, port)
65
+ return true
66
+ rescue SocketError
67
+ sleep 2
68
+ false
69
+ rescue Errno::ETIMEDOUT
70
+ false
71
+ rescue Errno::EPERM
72
+ false
73
+ rescue Errno::ECONNREFUSED
74
+ sleep 2
75
+ false
76
+ rescue Errno::EHOSTUNREACH
77
+ sleep 2
78
+ false
79
+ rescue Errno::ENETUNREACH
80
+ sleep 2
81
+ false
82
+ end
83
+
84
+ def bootstrap_exec(server)
85
+ fqdn = server.publicipaddress
86
+
87
+ if is_image_windows?
88
+ if locate_config_value(:bootstrap_protocol) == 'ssh'
89
+ port = server.sshport
90
+ print "#{ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)}"
91
+
92
+ print(".") until tcp_test_ssh(fqdn,port) {
93
+ sleep @initial_sleep_delay ||= 10
94
+ puts("done")
95
+ }
96
+
97
+ elsif locate_config_value(:bootstrap_protocol) == 'winrm'
98
+ port = server.winrmport
99
+
100
+ print "#{ui.color("Waiting for winrm on #{fqdn}:#{port}", :magenta)}"
101
+
102
+ print(".") until tcp_test_winrm(fqdn,port) {
103
+ sleep @initial_sleep_delay ||= 10
104
+ puts("done")
105
+ }
106
+ end
107
+
108
+ puts("\n")
109
+ bootstrap_for_windows_node(server, fqdn, port).run
110
+ else
111
+ unless server && server.publicipaddress && server.sshport
112
+ Chef::Log.fatal("server not created")
113
+ exit 1
114
+ end
115
+
116
+ port = server.sshport
117
+
118
+ print ui.color("Waiting for sshd on #{fqdn}:#{port}", :magenta)
119
+
120
+ print(".") until tcp_test_ssh(fqdn,port) {
121
+ sleep @initial_sleep_delay ||= 10
122
+ puts("done")
123
+ }
124
+
125
+ puts("\n")
126
+ bootstrap_for_node(server, fqdn, port).run
127
+ end
128
+
129
+ msg_server_summary(server)
130
+ end
131
+
132
+ def load_cloud_attributes_in_hints(server)
133
+ # Modify global configuration state to ensure hint gets set by knife-bootstrap
134
+ # Query azure and load necessary attributes.
135
+ cloud_attributes = {}
136
+ cloud_attributes["public_ip"] = server.publicipaddress
137
+ cloud_attributes["vm_name"] = server.name
138
+ cloud_attributes["public_fqdn"] = server.hostedservicename.to_s + ".cloudapp.net"
139
+ cloud_attributes["public_ssh_port"] = server.sshport if server.sshport
140
+ cloud_attributes["public_winrm_port"] = server.winrmport if server.winrmport
141
+
142
+ Chef::Config[:knife][:hints] ||= {}
143
+ Chef::Config[:knife][:hints]["azure"] ||= cloud_attributes
144
+ end
145
+
146
+ def bootstrap_common_params(bootstrap, server)
147
+ bootstrap.config[:run_list] = locate_config_value(:run_list)
148
+ bootstrap.config[:prerelease] = locate_config_value(:prerelease)
149
+ bootstrap.config[:first_boot_attributes] = locate_config_value(:json_attributes) || {}
150
+ bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
151
+ bootstrap.config[:distro] = locate_config_value(:distro) || default_bootstrap_template
152
+ # setting bootstrap_template value to template_file for backward
153
+ bootstrap.config[:template_file] = locate_config_value(:template_file) || locate_config_value(:bootstrap_template)
154
+ bootstrap.config[:node_ssl_verify_mode] = locate_config_value(:node_ssl_verify_mode)
155
+ bootstrap.config[:node_verify_api_cert] = locate_config_value(:node_verify_api_cert)
156
+ bootstrap.config[:bootstrap_no_proxy] = locate_config_value(:bootstrap_no_proxy)
157
+ bootstrap.config[:bootstrap_url] = locate_config_value(:bootstrap_url)
158
+ bootstrap.config[:bootstrap_vault_file] = locate_config_value(:bootstrap_vault_file)
159
+ bootstrap.config[:bootstrap_vault_json] = locate_config_value(:bootstrap_vault_json)
160
+ bootstrap.config[:bootstrap_vault_item] = locate_config_value(:bootstrap_vault_item)
161
+
162
+ load_cloud_attributes_in_hints(server)
163
+ bootstrap
164
+ end
165
+
166
+ def bootstrap_for_windows_node(server, fqdn, port)
167
+ if locate_config_value(:bootstrap_protocol) == 'winrm'
168
+
169
+ load_winrm_deps
170
+ if not Chef::Platform.windows?
171
+ require 'gssapi'
172
+ end
173
+
174
+ bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
175
+
176
+ bootstrap.config[:winrm_user] = locate_config_value(:winrm_user) || 'Administrator'
177
+ bootstrap.config[:winrm_password] = locate_config_value(:winrm_password)
178
+ bootstrap.config[:winrm_transport] = locate_config_value(:winrm_transport)
179
+ bootstrap.config[:winrm_authentication_protocol] = locate_config_value(:winrm_authentication_protocol)
180
+ bootstrap.config[:winrm_port] = port
181
+ bootstrap.config[:auth_timeout] = locate_config_value(:auth_timeout)
182
+ # Todo: we should skip cert generate in case when winrm_ssl_verify_mode=verify_none
183
+ bootstrap.config[:winrm_ssl_verify_mode] = locate_config_value(:winrm_ssl_verify_mode)
184
+ elsif locate_config_value(:bootstrap_protocol) == 'ssh'
185
+ bootstrap = Chef::Knife::BootstrapWindowsSsh.new
186
+ bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
187
+ bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
188
+ bootstrap.config[:forward_agent] = locate_config_value(:forward_agent)
189
+ bootstrap.config[:ssh_port] = port
190
+ bootstrap.config[:identity_file] = locate_config_value(:identity_file)
191
+ bootstrap.config[:host_key_verify] = locate_config_value(:host_key_verify)
192
+ else
193
+ ui.error("Unsupported Bootstrapping Protocol. Supported : winrm, ssh")
194
+ exit 1
195
+ end
196
+ bootstrap.name_args = [fqdn]
197
+ bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.name
198
+ bootstrap.config[:encrypted_data_bag_secret] = locate_config_value(:encrypted_data_bag_secret)
199
+ bootstrap.config[:encrypted_data_bag_secret_file] = locate_config_value(:encrypted_data_bag_secret_file)
200
+ bootstrap.config[:msi_url] = locate_config_value(:msi_url)
201
+ bootstrap.config[:install_as_service] = locate_config_value(:install_as_service)
202
+ bootstrap_common_params(bootstrap, server)
203
+ end
204
+
205
+ def bootstrap_for_node(server, fqdn, port)
206
+ bootstrap = Chef::Knife::Bootstrap.new
207
+ bootstrap.name_args = [fqdn]
208
+ bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
209
+ bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
210
+ bootstrap.config[:ssh_port] = port
211
+ bootstrap.config[:identity_file] = locate_config_value(:identity_file)
212
+ bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server.name
213
+ bootstrap.config[:use_sudo] = true unless locate_config_value(:ssh_user) == 'root'
214
+ bootstrap.config[:use_sudo_password] = true if bootstrap.config[:use_sudo]
215
+ bootstrap.config[:environment] = locate_config_value(:environment)
216
+ # may be needed for vpc_mode
217
+ bootstrap.config[:host_key_verify] = config[:host_key_verify]
218
+ Chef::Config[:knife][:secret] = config[:encrypted_data_bag_secret] if config[:encrypted_data_bag_secret]
219
+ Chef::Config[:knife][:secret_file] = config[:encrypted_data_bag_secret_file] if config[:encrypted_data_bag_secret_file]
220
+ bootstrap.config[:secret] = locate_config_value(:secret) || locate_config_value(:encrypted_data_bag_secret)
221
+ bootstrap.config[:secret_file] = locate_config_value(:secret_file) || locate_config_value(:encrypted_data_bag_secret_file)
222
+ bootstrap.config[:bootstrap_install_command] = locate_config_value(:bootstrap_install_command)
223
+ bootstrap.config[:bootstrap_wget_options] = locate_config_value(:bootstrap_wget_options)
224
+ bootstrap.config[:bootstrap_curl_options] = locate_config_value(:bootstrap_curl_options)
225
+ bootstrap_common_params(bootstrap, server)
226
+ end
227
+
228
+ def get_chef_extension_name
229
+ is_image_windows? ? "ChefClient" : "LinuxChefClient"
230
+ end
231
+
232
+ def get_chef_extension_publisher
233
+ "Chef.Bootstrap.WindowsAzure"
234
+ end
235
+
236
+ # get latest version
237
+ def get_chef_extension_version(chef_extension_name = nil)
238
+ if locate_config_value(:azure_chef_extension_version)
239
+ Chef::Config[:knife][:azure_chef_extension_version]
240
+ else
241
+ chef_extension_name = chef_extension_name.nil? ? get_chef_extension_name : chef_extension_name
242
+ extensions = service.get_extension(chef_extension_name, get_chef_extension_publisher)
243
+ extensions.css("Version").max.text.split(".").first + ".*"
244
+ end
245
+ end
246
+
247
+ def default_hint_options
248
+ [
249
+ 'vm_name',
250
+ 'public_fqdn',
251
+ 'platform'
252
+ ]
253
+ end
254
+
255
+ def ohai_hints
256
+ hint_values = locate_config_value(:ohai_hints)
257
+
258
+ if hint_values.casecmp('default').zero?
259
+ hints = default_hint_options
260
+ else
261
+ hints = hint_values.split(',')
262
+ end
263
+
264
+ hints
265
+ end
266
+
267
+ def get_chef_extension_public_params
268
+ pub_config = Hash.new
269
+ if(locate_config_value(:azure_extension_client_config))
270
+ pub_config[:client_rb] = File.read(locate_config_value(:azure_extension_client_config))
271
+ else
272
+ pub_config[:client_rb] = "chef_server_url \t #{Chef::Config[:chef_server_url].to_json}\nvalidation_client_name\t#{Chef::Config[:validation_client_name].to_json}"
273
+ end
274
+
275
+ pub_config[:runlist] = locate_config_value(:run_list).empty? ? "" : locate_config_value(:run_list).join(",").to_json
276
+ pub_config[:autoUpdateClient] = locate_config_value(:auto_update_client) ? "true" : "false"
277
+ pub_config[:deleteChefConfig] = locate_config_value(:delete_chef_extension_config) ? "true" : "false"
278
+ pub_config[:uninstallChefClient] = locate_config_value(:uninstall_chef_client) ? "true" : "false"
279
+ pub_config[:custom_json_attr] = locate_config_value(:json_attributes) || {}
280
+ pub_config[:extendedLogs] = locate_config_value(:extended_logs) ? "true" : "false"
281
+ pub_config[:hints] = ohai_hints if @service.instance_of? Azure::ResourceManagement::ARMInterface
282
+
283
+ # bootstrap attributes
284
+ pub_config[:bootstrap_options] = {}
285
+ pub_config[:bootstrap_options][:environment] = locate_config_value(:environment) if locate_config_value(:environment)
286
+ pub_config[:bootstrap_options][:chef_node_name] = locate_config_value(:chef_node_name) if locate_config_value(:chef_node_name)
287
+
288
+ if ( locate_config_value(:secret_file) || locate_config_value(:encrypted_data_bag_secret_file) ) && ( !locate_config_value(:secret) || !locate_config_value(:encrypted_data_bag_secret) )
289
+ pub_config[:bootstrap_options][:encrypted_data_bag_secret] = Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
290
+ elsif locate_config_value(:encrypted_data_bag_secret) || locate_config_value(:secret)
291
+ pub_config[:bootstrap_options][:encrypted_data_bag_secret] = locate_config_value(:encrypted_data_bag_secret) || locate_config_value(:secret)
292
+ end
293
+
294
+ pub_config[:bootstrap_options][:chef_server_url] = Chef::Config[:chef_server_url] if Chef::Config[:chef_server_url]
295
+ pub_config[:bootstrap_options][:validation_client_name] = Chef::Config[:validation_client_name] if Chef::Config[:validation_client_name]
296
+ pub_config[:bootstrap_options][:node_verify_api_cert] = locate_config_value(:node_verify_api_cert) ? "true" : "false" if config.key?(:node_verify_api_cert)
297
+ pub_config[:bootstrap_options][:bootstrap_version] = locate_config_value(:bootstrap_version) if locate_config_value(:bootstrap_version)
298
+ pub_config[:bootstrap_options][:node_ssl_verify_mode] = locate_config_value(:node_ssl_verify_mode) if locate_config_value(:node_ssl_verify_mode)
299
+ pub_config[:bootstrap_options][:bootstrap_proxy] = locate_config_value(:bootstrap_proxy) if locate_config_value(:bootstrap_proxy)
300
+
301
+ pub_config
302
+ end
303
+
304
+ def get_chef_extension_private_params
305
+ pri_config = Hash.new
306
+
307
+ # validator less bootstrap support for bootstrap protocol cloud-api
308
+ if (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key])))
309
+
310
+ if Chef::VERSION.split('.').first.to_i == 11
311
+ ui.error('Unable to find validation key. Please verify your configuration file for validation_key config value.')
312
+ exit 1
313
+ end
314
+
315
+ client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(
316
+ chef_config: Chef::Config,
317
+ knife_config: config,
318
+ ui: ui,
319
+ )
320
+
321
+ client_builder.run
322
+ key_path = client_builder.client_path
323
+ pri_config[:client_pem] = File.read(key_path)
324
+ else
325
+ pri_config[:validation_key] = File.read(Chef::Config[:validation_key])
326
+ end
327
+
328
+ # SSL cert bootstrap support
329
+ if locate_config_value(:cert_path)
330
+ if File.exist?(File.expand_path(locate_config_value(:cert_path)))
331
+ pri_config[:chef_server_crt] = File.read(locate_config_value(:cert_path))
332
+ else
333
+ ui.error('Specified SSL certificate does not exist.')
334
+ exit 1
335
+ end
336
+ end
337
+
338
+ pri_config
339
+ end
340
+ end
341
+ end
342
+ end
343
+ end