knife-windows 3.0.13 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/knife/bootstrap_windows_ssh.rb +5 -16
- data/lib/chef/knife/bootstrap_windows_winrm.rb +3 -15
- data/lib/chef/knife/{bootstrap_windows_base.rb → helpers/bootstrap_windows_base.rb} +14 -24
- data/lib/chef/knife/{winrm_base.rb → helpers/winrm_base.rb} +10 -23
- data/lib/chef/knife/{winrm_knife_base.rb → helpers/winrm_knife_base.rb} +23 -22
- data/lib/chef/knife/{winrm_session.rb → helpers/winrm_session.rb} +0 -0
- data/lib/chef/knife/{winrm_shared_options.rb → helpers/winrm_shared_options.rb} +0 -0
- data/lib/chef/knife/{wsman_endpoint.rb → helpers/wsman_endpoint.rb} +0 -0
- data/lib/chef/knife/windows_cert_generate.rb +1 -1
- data/lib/chef/knife/windows_cert_install.rb +1 -1
- data/lib/chef/knife/windows_listener_create.rb +1 -1
- data/lib/chef/knife/winrm.rb +3 -5
- data/lib/chef/knife/wsman_test.rb +2 -2
- data/lib/knife-windows/version.rb +1 -1
- data/spec/spec_helper.rb +16 -1
- data/spec/unit/knife/winrm_session_spec.rb +1 -1
- data/spec/unit/knife/winrm_spec.rb +7 -9
- data/spec/unit/knife/wsman_test_spec.rb +2 -1
- metadata +11 -13
- data/lib/chef/knife/knife_windows_base.rb +0 -34
- data/lib/chef/knife/windows_helper.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00669322920507bee3df2da47e879305c6bce383935885fd36975738ea83e50b'
|
4
|
+
data.tar.gz: 8663a57c66f81c31d9664e3c4345adea612db89ca876f8b951f3d75391861a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eabd372f0cf3fb8b82dcebef93fbaa51fae7b6417bbf3eb2d6b2d76a00c1dc25e1bb9c0f3242cc280c55fb20c6b1bb2a9ab32e0f16468f39ae88b3974ae3439
|
7
|
+
data.tar.gz: f5e0794d88d5e57bb0aee87212959fe3944b3d124cea70871693b2ccabdf7b980ac3ac5a8ca0c3ea1ecf1160e848de3e22ff0af113dc9e2caee6c4ffb46a3b52
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,7 +17,7 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "chef/knife"
|
20
|
-
require_relative "bootstrap_windows_base"
|
20
|
+
require_relative "helpers/bootstrap_windows_base"
|
21
21
|
|
22
22
|
class Chef
|
23
23
|
class Knife
|
@@ -25,17 +25,7 @@ class Chef
|
|
25
25
|
|
26
26
|
include Chef::Knife::BootstrapWindowsBase
|
27
27
|
|
28
|
-
|
29
|
-
require "chef/json_compat"
|
30
|
-
require "tempfile"
|
31
|
-
require "highline"
|
32
|
-
require "net/ssh"
|
33
|
-
require "net/ssh/multi"
|
34
|
-
Chef::Knife::Ssh.load_deps
|
35
|
-
Chef::Knife::Bootstrap.load_deps
|
36
|
-
end
|
37
|
-
|
38
|
-
banner "knife bootstrap windows ssh FQDN (options)"
|
28
|
+
banner "knife bootstrap windows ssh FQDN (options) DEPRECATED"
|
39
29
|
|
40
30
|
option :ssh_user,
|
41
31
|
short: "-x USERNAME",
|
@@ -52,13 +42,12 @@ class Chef
|
|
52
42
|
short: "-p PORT",
|
53
43
|
long: "--ssh-port PORT",
|
54
44
|
description: "The ssh port",
|
55
|
-
proc: Proc.new { |key|
|
45
|
+
proc: Proc.new { |key| key.strip }
|
56
46
|
|
57
47
|
option :ssh_gateway,
|
58
48
|
short: "-G GATEWAY",
|
59
49
|
long: "--ssh-gateway GATEWAY",
|
60
|
-
description: "The ssh gateway"
|
61
|
-
proc: Proc.new { |key| Chef::Config[:knife][:ssh_gateway] = key }
|
50
|
+
description: "The ssh gateway"
|
62
51
|
|
63
52
|
option :forward_agent,
|
64
53
|
short: "-A",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
-
# Copyright:: Copyright (c) 2011-
|
3
|
+
# Copyright:: Copyright (c) 2011-2020 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,27 +17,15 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "chef/knife"
|
20
|
-
require_relative "bootstrap_windows_base"
|
21
|
-
require_relative "winrm_base"
|
22
|
-
require_relative "winrm_knife_base" # WinrmCommandSharedFunctions
|
20
|
+
require_relative "helpers/bootstrap_windows_base"
|
23
21
|
|
24
22
|
class Chef
|
25
23
|
class Knife
|
26
24
|
class BootstrapWindowsWinrm < Bootstrap
|
27
25
|
|
28
26
|
include Chef::Knife::BootstrapWindowsBase
|
29
|
-
include Chef::Knife::WinrmBase
|
30
|
-
include Chef::Knife::WinrmCommandSharedFunctions
|
31
|
-
|
32
|
-
deps do
|
33
|
-
require_relative "winrm"
|
34
|
-
require "chef/json_compat"
|
35
|
-
require "tempfile"
|
36
|
-
Chef::Knife::Winrm.load_deps
|
37
|
-
Chef::Knife::Bootstrap.load_deps
|
38
|
-
end
|
39
27
|
|
40
|
-
banner "knife bootstrap windows winrm FQDN (options)"
|
28
|
+
banner "knife bootstrap windows winrm FQDN (options) DEPRECATED"
|
41
29
|
|
42
30
|
def run
|
43
31
|
Chef::Application.fatal!(<<~EOM
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -32,13 +32,6 @@ class Chef
|
|
32
32
|
def self.included(includer)
|
33
33
|
includer.class_eval do
|
34
34
|
|
35
|
-
deps do
|
36
|
-
require "chef/knife/bootstrap"
|
37
|
-
require "chef/encrypted_data_bag_item"
|
38
|
-
require "readline"
|
39
|
-
require "chef/json_compat"
|
40
|
-
end
|
41
|
-
|
42
35
|
option :chef_node_name,
|
43
36
|
short: "-N NAME",
|
44
37
|
long: "--node-name NAME",
|
@@ -50,23 +43,19 @@ class Chef
|
|
50
43
|
|
51
44
|
option :bootstrap_version,
|
52
45
|
long: "--bootstrap-version VERSION",
|
53
|
-
description: "The version of Chef to install"
|
54
|
-
proc: Proc.new { |v| Chef::Config[:knife][:bootstrap_version] = v }
|
46
|
+
description: "The version of Chef to install"
|
55
47
|
|
56
48
|
option :bootstrap_proxy,
|
57
49
|
long: "--bootstrap-proxy PROXY_URL",
|
58
|
-
description: "The proxy server for the node being bootstrapped"
|
59
|
-
proc: Proc.new { |p| Chef::Config[:knife][:bootstrap_proxy] = p }
|
50
|
+
description: "The proxy server for the node being bootstrapped"
|
60
51
|
|
61
52
|
option :bootstrap_no_proxy,
|
62
53
|
long: "--bootstrap-no-proxy [NO_PROXY_URL|NO_PROXY_IP]",
|
63
|
-
description: "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode"
|
64
|
-
proc: Proc.new { |np| Chef::Config[:knife][:bootstrap_no_proxy] = np }
|
54
|
+
description: "Do not proxy locations for the node being bootstrapped; this option is used internally by Opscode"
|
65
55
|
|
66
56
|
option :bootstrap_install_command,
|
67
57
|
long: "--bootstrap-install-command COMMANDS",
|
68
|
-
description: "Custom command to install chef-client"
|
69
|
-
proc: Proc.new { |ic| Chef::Config[:knife][:bootstrap_install_command] = ic }
|
58
|
+
description: "Custom command to install chef-client"
|
70
59
|
|
71
60
|
option :bootstrap_template,
|
72
61
|
short: "-t TEMPLATE",
|
@@ -83,10 +72,11 @@ class Chef
|
|
83
72
|
option :hint,
|
84
73
|
long: "--hint HINT_NAME[=HINT_FILE]",
|
85
74
|
description: "Specify Ohai Hint to be set on the bootstrap target. Use multiple --hint options to specify multiple hints.",
|
86
|
-
proc: Proc.new { |h|
|
87
|
-
|
75
|
+
proc: Proc.new { |h, accumulator|
|
76
|
+
accumulator ||= {}
|
88
77
|
name, path = h.split("=")
|
89
|
-
|
78
|
+
accumulator[name] = path ? Chef::JSONCompat.parse(::File.read(path)) : {}
|
79
|
+
accumulator
|
90
80
|
}
|
91
81
|
|
92
82
|
option :first_boot_attributes,
|
@@ -158,12 +148,12 @@ class Chef
|
|
158
148
|
option :bootstrap_vault_item,
|
159
149
|
long: "--bootstrap-vault-item VAULT_ITEM",
|
160
150
|
description: 'A single vault and item to update as "vault:item"',
|
161
|
-
proc: Proc.new { |i|
|
151
|
+
proc: Proc.new { |i, accumulator|
|
162
152
|
(vault, item) = i.split(/:/)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
153
|
+
accumulator ||= {}
|
154
|
+
accumulator[vault] ||= []
|
155
|
+
accumulator[vault].push(item)
|
156
|
+
accumulator
|
167
157
|
}
|
168
158
|
|
169
159
|
option :policy_name,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -42,14 +42,12 @@ class Chef
|
|
42
42
|
short: "-x USERNAME",
|
43
43
|
long: "--winrm-user USERNAME",
|
44
44
|
description: "The WinRM username",
|
45
|
-
default: "Administrator"
|
46
|
-
proc: Proc.new { |key| Chef::Config[:knife][:winrm_user] = key }
|
45
|
+
default: "Administrator"
|
47
46
|
|
48
47
|
option :winrm_password,
|
49
48
|
short: "-P PASSWORD",
|
50
49
|
long: "--winrm-password PASSWORD",
|
51
|
-
description: "The WinRM password"
|
52
|
-
proc: Proc.new { |key| Chef::Config[:knife][:winrm_password] = key }
|
50
|
+
description: "The WinRM password"
|
53
51
|
|
54
52
|
option :winrm_shell,
|
55
53
|
long: "--winrm-shell SHELL",
|
@@ -61,42 +59,32 @@ class Chef
|
|
61
59
|
short: "-w TRANSPORT",
|
62
60
|
long: "--winrm-transport TRANSPORT",
|
63
61
|
description: "The WinRM transport type. Valid choices are [ssl, plaintext]",
|
64
|
-
default: "plaintext"
|
65
|
-
proc: Proc.new { |transport|
|
66
|
-
Chef::Config[:knife][:winrm_port] = "5986" if transport == "ssl"
|
67
|
-
Chef::Config[:knife][:winrm_transport] = transport
|
68
|
-
}
|
62
|
+
default: "plaintext"
|
69
63
|
|
70
64
|
option :winrm_port,
|
71
65
|
short: "-p PORT",
|
72
66
|
long: "--winrm-port PORT",
|
73
|
-
description: "The WinRM port, by default this is '5985' for 'plaintext' and '5986' for 'ssl' winrm transport"
|
74
|
-
default: "5985",
|
75
|
-
proc: Proc.new { |key| Chef::Config[:knife][:winrm_port] = key }
|
67
|
+
description: "The WinRM port, by default this is '5985' for 'plaintext' and '5986' for 'ssl' winrm transport"
|
76
68
|
|
77
69
|
option :kerberos_keytab_file,
|
78
70
|
short: "-T KEYTAB_FILE",
|
79
71
|
long: "--keytab-file KEYTAB_FILE",
|
80
|
-
description: "The Kerberos keytab file used for authentication"
|
81
|
-
proc: Proc.new { |keytab| Chef::Config[:knife][:kerberos_keytab_file] = keytab }
|
72
|
+
description: "The Kerberos keytab file used for authentication"
|
82
73
|
|
83
74
|
option :kerberos_realm,
|
84
75
|
short: "-R KERBEROS_REALM",
|
85
76
|
long: "--kerberos-realm KERBEROS_REALM",
|
86
|
-
description: "The Kerberos realm used for authentication"
|
87
|
-
proc: Proc.new { |realm| Chef::Config[:knife][:kerberos_realm] = realm }
|
77
|
+
description: "The Kerberos realm used for authentication"
|
88
78
|
|
89
79
|
option :kerberos_service,
|
90
80
|
short: "-S KERBEROS_SERVICE",
|
91
81
|
long: "--kerberos-service KERBEROS_SERVICE",
|
92
|
-
description: "The Kerberos service used for authentication"
|
93
|
-
proc: Proc.new { |service| Chef::Config[:knife][:kerberos_service] = service }
|
82
|
+
description: "The Kerberos service used for authentication"
|
94
83
|
|
95
84
|
option :ca_trust_file,
|
96
85
|
short: "-f CA_TRUST_FILE",
|
97
86
|
long: "--ca-trust-file CA_TRUST_FILE",
|
98
|
-
description: "The Certificate Authority (CA) trust file used for SSL transport"
|
99
|
-
proc: Proc.new { |trust| Chef::Config[:knife][:ca_trust_file] = trust }
|
87
|
+
description: "The Certificate Authority (CA) trust file used for SSL transport"
|
100
88
|
|
101
89
|
option :winrm_ssl_verify_mode,
|
102
90
|
long: "--winrm-ssl-verify-mode SSL_VERIFY_MODE",
|
@@ -111,8 +99,7 @@ class Chef
|
|
111
99
|
option :winrm_authentication_protocol,
|
112
100
|
long: "--winrm-authentication-protocol AUTHENTICATION_PROTOCOL",
|
113
101
|
description: "The authentication protocol used during WinRM communication. The supported protocols are #{WINRM_AUTH_PROTOCOL_LIST.join(",")}. Default is 'negotiate'.",
|
114
|
-
default: "negotiate"
|
115
|
-
proc: Proc.new { |protocol| Chef::Config[:knife][:winrm_authentication_protocol] = protocol }
|
102
|
+
default: "negotiate"
|
116
103
|
|
117
104
|
option :session_timeout,
|
118
105
|
long: "--session-timeout Minutes",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Steven Murawski (<smurawski@chef.io)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -19,7 +19,7 @@
|
|
19
19
|
require "chef/knife"
|
20
20
|
require_relative "winrm_base"
|
21
21
|
require_relative "winrm_shared_options"
|
22
|
-
require_relative "
|
22
|
+
require_relative "winrm_session"
|
23
23
|
|
24
24
|
class Chef
|
25
25
|
class Knife
|
@@ -39,10 +39,9 @@ class Chef
|
|
39
39
|
|
40
40
|
include Chef::Knife::WinrmBase
|
41
41
|
include Chef::Knife::WinrmSharedOptions
|
42
|
-
include Chef::Knife::KnifeWindowsBase
|
43
42
|
|
44
43
|
def validate_winrm_options!
|
45
|
-
winrm_auth_protocol =
|
44
|
+
winrm_auth_protocol = config[:winrm_authentication_protocol]
|
46
45
|
|
47
46
|
unless Chef::Knife::WinrmBase::WINRM_AUTH_PROTOCOL_LIST.include?(winrm_auth_protocol)
|
48
47
|
ui.error "Invalid value '#{winrm_auth_protocol}' for --winrm-authentication-protocol option."
|
@@ -120,7 +119,7 @@ class Chef
|
|
120
119
|
@session_results = []
|
121
120
|
queue = Queue.new
|
122
121
|
@winrm_sessions.each { |s| queue << s }
|
123
|
-
num_sessions =
|
122
|
+
num_sessions = config[:concurrency]
|
124
123
|
num_targets = @winrm_sessions.length
|
125
124
|
num_sessions = (num_sessions.nil? || num_sessions == 0) ? num_targets : [num_sessions, num_targets].min
|
126
125
|
|
@@ -146,7 +145,7 @@ class Chef
|
|
146
145
|
if authorization_error?(e)
|
147
146
|
unless config[:suppress_auth_failure]
|
148
147
|
# Display errors if the caller hasn't opted to retry
|
149
|
-
ui.error "Failed to authenticate to #{s.host} as #{
|
148
|
+
ui.error "Failed to authenticate to #{s.host} as #{config[:winrm_user]}"
|
150
149
|
ui.info "Response: #{e.message}"
|
151
150
|
ui.info get_failed_authentication_hint
|
152
151
|
raise e
|
@@ -202,33 +201,35 @@ class Chef
|
|
202
201
|
end
|
203
202
|
|
204
203
|
def resolve_session_options
|
204
|
+
config[:winrm_port] ||= ( config[:winrm_transport] == "ssl" ) ? "5986" : "5985"
|
205
|
+
|
205
206
|
@session_opts = {
|
206
207
|
user: resolve_winrm_user,
|
207
|
-
password:
|
208
|
-
port:
|
208
|
+
password: config[:winrm_password],
|
209
|
+
port: config[:winrm_port],
|
209
210
|
operation_timeout: resolve_winrm_session_timeout,
|
210
211
|
basic_auth_only: resolve_winrm_basic_auth,
|
211
212
|
disable_sspi: resolve_winrm_disable_sspi,
|
212
213
|
transport: resolve_winrm_transport,
|
213
214
|
no_ssl_peer_verification: resolve_no_ssl_peer_verification,
|
214
215
|
ssl_peer_fingerprint: resolve_ssl_peer_fingerprint,
|
215
|
-
shell:
|
216
|
-
codepage:
|
216
|
+
shell: config[:winrm_shell],
|
217
|
+
codepage: config[:winrm_codepage],
|
217
218
|
}
|
218
219
|
|
219
220
|
if @session_opts[:user] && (not @session_opts[:password])
|
220
|
-
@session_opts[:password] =
|
221
|
+
@session_opts[:password] = config[:winrm_password] = get_password
|
221
222
|
end
|
222
223
|
|
223
224
|
if @session_opts[:transport] == :kerberos
|
224
225
|
@session_opts.merge!(resolve_winrm_kerberos_options)
|
225
226
|
end
|
226
227
|
|
227
|
-
@session_opts[:ca_trust_path] =
|
228
|
+
@session_opts[:ca_trust_path] = config[:ca_trust_file] if config[:ca_trust_file]
|
228
229
|
end
|
229
230
|
|
230
231
|
def resolve_winrm_user
|
231
|
-
user =
|
232
|
+
user = config[:winrm_user]
|
232
233
|
|
233
234
|
# Prefixing with '.\' when using negotiate
|
234
235
|
# to auth user against local machine domain
|
@@ -244,23 +245,23 @@ class Chef
|
|
244
245
|
|
245
246
|
def resolve_winrm_session_timeout
|
246
247
|
# 30 min (Default) OperationTimeout for long bootstraps fix for KNIFE_WINDOWS-8
|
247
|
-
|
248
|
+
config[:session_timeout].to_i * 60 if config[:session_timeout]
|
248
249
|
end
|
249
250
|
|
250
251
|
def resolve_winrm_basic_auth
|
251
|
-
|
252
|
+
config[:winrm_authentication_protocol] == "basic"
|
252
253
|
end
|
253
254
|
|
254
255
|
def resolve_winrm_kerberos_options
|
255
256
|
kerberos_opts = {}
|
256
|
-
kerberos_opts[:keytab] =
|
257
|
-
kerberos_opts[:realm] =
|
258
|
-
kerberos_opts[:service] =
|
257
|
+
kerberos_opts[:keytab] = config[:kerberos_keytab_file] if config[:kerberos_keytab_file]
|
258
|
+
kerberos_opts[:realm] = config[:kerberos_realm] if config[:kerberos_realm]
|
259
|
+
kerberos_opts[:service] = config[:kerberos_service] if config[:kerberos_service]
|
259
260
|
kerberos_opts
|
260
261
|
end
|
261
262
|
|
262
263
|
def resolve_winrm_transport
|
263
|
-
transport =
|
264
|
+
transport = config[:winrm_transport].to_sym
|
264
265
|
if config.any? { |k, v| k.to_s =~ /kerberos/ && !v.nil? }
|
265
266
|
transport = :kerberos
|
266
267
|
elsif transport != :ssl && negotiate_auth?
|
@@ -271,11 +272,11 @@ class Chef
|
|
271
272
|
end
|
272
273
|
|
273
274
|
def resolve_no_ssl_peer_verification
|
274
|
-
|
275
|
+
config[:ca_trust_file].nil? && config[:winrm_ssl_verify_mode] == :verify_none && resolve_winrm_transport == :ssl
|
275
276
|
end
|
276
277
|
|
277
278
|
def resolve_ssl_peer_fingerprint
|
278
|
-
|
279
|
+
config[:ssl_peer_fingerprint]
|
279
280
|
end
|
280
281
|
|
281
282
|
def resolve_winrm_disable_sspi
|
@@ -287,7 +288,7 @@ class Chef
|
|
287
288
|
end
|
288
289
|
|
289
290
|
def negotiate_auth?
|
290
|
-
|
291
|
+
config[:winrm_authentication_protocol] == "negotiate"
|
291
292
|
end
|
292
293
|
|
293
294
|
def warn_no_ssl_peer_verification
|
File without changes
|
File without changes
|
File without changes
|
data/lib/chef/knife/winrm.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,21 +17,19 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "chef/knife"
|
20
|
-
require_relative "winrm_knife_base" # WinrmCommandSharedFunctions
|
21
|
-
require_relative "winrm_session"
|
22
|
-
require_relative "knife_windows_base"
|
20
|
+
require_relative "helpers/winrm_knife_base" # WinrmCommandSharedFunctions
|
23
21
|
|
24
22
|
class Chef
|
25
23
|
class Knife
|
26
24
|
class Winrm < Knife
|
27
25
|
|
28
26
|
include Chef::Knife::WinrmCommandSharedFunctions
|
29
|
-
include Chef::Knife::KnifeWindowsBase
|
30
27
|
|
31
28
|
deps do
|
32
29
|
require_relative "windows_cert_generate"
|
33
30
|
require_relative "windows_cert_install"
|
34
31
|
require_relative "windows_listener_create"
|
32
|
+
require_relative "helpers/winrm_session"
|
35
33
|
require "readline"
|
36
34
|
require "chef/search/query"
|
37
35
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
# Author:: Adam Edwards (<adamed@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -22,7 +22,22 @@ def sample_data(file_name)
|
|
22
22
|
File.read(file)
|
23
23
|
end
|
24
24
|
|
25
|
+
class UnexpectedSystemExit < RuntimeError
|
26
|
+
def self.from(system_exit)
|
27
|
+
new(system_exit.message).tap { |e| e.set_backtrace(system_exit.backtrace) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
25
31
|
RSpec.configure do |config|
|
32
|
+
config.raise_on_warning = true
|
33
|
+
config.raise_errors_for_deprecations!
|
26
34
|
config.run_all_when_everything_filtered = true
|
27
35
|
config.filter_run focus: true
|
36
|
+
config.around(:example) do |ex|
|
37
|
+
begin
|
38
|
+
ex.run
|
39
|
+
rescue SystemExit => e
|
40
|
+
raise UnexpectedSystemExit.from(e)
|
41
|
+
end
|
42
|
+
end
|
28
43
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Bryan McLellan <btm@chef.io>
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -250,7 +250,7 @@ describe Chef::Knife::Winrm do
|
|
250
250
|
end
|
251
251
|
|
252
252
|
it "sets the user specified winrm port" do
|
253
|
-
|
253
|
+
winrm_command_http.config[:knife] = { winrm_port: "5988" }
|
254
254
|
expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(transport: :plaintext)).and_call_original
|
255
255
|
expect(WinRM::Connection).to receive(:new).with(hash_including(transport: :plaintext)).and_return(winrm_connection)
|
256
256
|
winrm_command_http.configure_chef
|
@@ -269,7 +269,7 @@ describe Chef::Knife::Winrm do
|
|
269
269
|
let(:winrm_command_https) { Chef::Knife::Winrm.new(["-m", "localhost", "-x", "testuser", "-P", "testpassword", "--winrm-transport", "ssl", "echo helloworld"]) }
|
270
270
|
|
271
271
|
it "uses the https uri scheme if the ssl transport is specified" do
|
272
|
-
|
272
|
+
winrm_command_http.config[:winrm_transport] = "ssl"
|
273
273
|
expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(transport: :ssl)).and_call_original
|
274
274
|
expect(WinRM::Connection).to receive(:new).with(hash_including(endpoint: "https://localhost:5986/wsman")).and_return(winrm_connection)
|
275
275
|
winrm_command_https.configure_chef
|
@@ -277,7 +277,7 @@ describe Chef::Knife::Winrm do
|
|
277
277
|
end
|
278
278
|
|
279
279
|
it "uses the winrm port '5986' by default for ssl transport" do
|
280
|
-
|
280
|
+
winrm_command_http.config[:winrm_transport] = "ssl"
|
281
281
|
expect(Chef::Knife::WinrmSession).to receive(:new).with(hash_including(transport: :ssl)).and_call_original
|
282
282
|
expect(WinRM::Connection).to receive(:new).with(hash_including(endpoint: "https://localhost:5986/wsman")).and_return(winrm_connection)
|
283
283
|
winrm_command_https.configure_chef
|
@@ -361,8 +361,8 @@ describe Chef::Knife::Winrm do
|
|
361
361
|
|
362
362
|
before(:each) do
|
363
363
|
allow(Chef::Knife::WinrmSession).to receive(:new).and_return(session)
|
364
|
-
Chef::Config[:knife] = { winrm_transport: "plaintext" }
|
365
364
|
@winrm = Chef::Knife::Winrm.new(["-m", "localhost", "-x", "testuser", "-P", "testpassword", "--winrm-authentication-protocol", "basic", "echo helloworld"])
|
365
|
+
@winrm.config[:winrm_transport] = "plaintext"
|
366
366
|
end
|
367
367
|
|
368
368
|
it "returns with 0 if the command succeeds" do
|
@@ -375,7 +375,6 @@ describe Chef::Knife::Winrm do
|
|
375
375
|
command_status = 510
|
376
376
|
|
377
377
|
@winrm.config[:returns] = "0"
|
378
|
-
Chef::Config[:knife][:returns] = [0]
|
379
378
|
|
380
379
|
allow(@winrm).to receive(:relay_winrm_command)
|
381
380
|
allow(@winrm.ui).to receive(:error)
|
@@ -386,7 +385,6 @@ describe Chef::Knife::Winrm do
|
|
386
385
|
it "exits with non-zero status if the command fails and returns config is set to 0" do
|
387
386
|
command_status = 1
|
388
387
|
@winrm.config[:returns] = "0,53"
|
389
|
-
Chef::Config[:knife][:returns] = [0, 53]
|
390
388
|
allow(@winrm).to receive(:relay_winrm_command).and_return(command_status)
|
391
389
|
allow(@winrm.ui).to receive(:error)
|
392
390
|
allow(session).to receive(:exit_code).and_return(command_status)
|
@@ -395,7 +393,7 @@ describe Chef::Knife::Winrm do
|
|
395
393
|
|
396
394
|
it "exits with a zero status if the command returns an expected non-zero status" do
|
397
395
|
command_status = 53
|
398
|
-
|
396
|
+
@winrm.config[:returns] = "0,53"
|
399
397
|
allow(@winrm).to receive(:relay_winrm_command).and_return(command_status)
|
400
398
|
allow(session).to receive(:exit_codes).and_return({ "thishost" => command_status })
|
401
399
|
exit_code = @winrm.run
|
@@ -448,7 +446,7 @@ describe Chef::Knife::Winrm do
|
|
448
446
|
|
449
447
|
context "when winrm_authentication_protocol specified" do
|
450
448
|
before do
|
451
|
-
|
449
|
+
@winrm.config[:winrm_transport] = "plaintext"
|
452
450
|
allow(@winrm).to receive(:relay_winrm_command).and_return(0)
|
453
451
|
end
|
454
452
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Steven Murawski (<smurawski@chef.io>)
|
3
|
-
# Copyright:: Copyright (c)
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -37,6 +37,7 @@ describe Chef::Knife::WsmanTest do
|
|
37
37
|
allow(Chef::HTTP::DefaultSSLPolicy).to receive(:new)
|
38
38
|
.with(http_client_mock.ssl_config)
|
39
39
|
.and_return(ssl_policy)
|
40
|
+
subject.merge_configs
|
40
41
|
end
|
41
42
|
|
42
43
|
subject { Chef::Knife::WsmanTest.new(["-m", "localhost"]) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-windows
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Chisamore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '15.
|
19
|
+
version: '15.11'
|
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
|
-
version: '15.
|
26
|
+
version: '15.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: winrm
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,20 +75,18 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- LICENSE
|
78
|
-
- lib/chef/knife/bootstrap_windows_base.rb
|
79
78
|
- lib/chef/knife/bootstrap_windows_ssh.rb
|
80
79
|
- lib/chef/knife/bootstrap_windows_winrm.rb
|
81
|
-
- lib/chef/knife/
|
80
|
+
- lib/chef/knife/helpers/bootstrap_windows_base.rb
|
81
|
+
- lib/chef/knife/helpers/winrm_base.rb
|
82
|
+
- lib/chef/knife/helpers/winrm_knife_base.rb
|
83
|
+
- lib/chef/knife/helpers/winrm_session.rb
|
84
|
+
- lib/chef/knife/helpers/winrm_shared_options.rb
|
85
|
+
- lib/chef/knife/helpers/wsman_endpoint.rb
|
82
86
|
- lib/chef/knife/windows_cert_generate.rb
|
83
87
|
- lib/chef/knife/windows_cert_install.rb
|
84
|
-
- lib/chef/knife/windows_helper.rb
|
85
88
|
- lib/chef/knife/windows_listener_create.rb
|
86
89
|
- lib/chef/knife/winrm.rb
|
87
|
-
- lib/chef/knife/winrm_base.rb
|
88
|
-
- lib/chef/knife/winrm_knife_base.rb
|
89
|
-
- lib/chef/knife/winrm_session.rb
|
90
|
-
- lib/chef/knife/winrm_shared_options.rb
|
91
|
-
- lib/chef/knife/wsman_endpoint.rb
|
92
90
|
- lib/chef/knife/wsman_test.rb
|
93
91
|
- lib/knife-windows/version.rb
|
94
92
|
- spec/assets/fake_trusted_certs/excluded.txt
|
@@ -124,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
122
|
requirements:
|
125
123
|
- - ">="
|
126
124
|
- !ruby/object:Gem::Version
|
127
|
-
version: 2.
|
125
|
+
version: 2.6.0
|
128
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
127
|
requirements:
|
130
128
|
- - ">="
|
@@ -1,34 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Aliasgar Batterywala (<aliasgar.batterywala@clogeny.com>)
|
3
|
-
# Copyright:: Copyright (c) 2015-2016 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
|
-
module KnifeWindowsBase
|
24
|
-
|
25
|
-
def locate_config_value(key)
|
26
|
-
key = key.to_sym
|
27
|
-
value = config[key] || Chef::Config[:knife][key] || default_config[key]
|
28
|
-
Chef::Log.debug("Looking for key #{key} and found value #{value}")
|
29
|
-
value
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Chirag Jog (<chirag@clogeny.com>)
|
3
|
-
# Copyright:: Copyright (c) 2013-2016 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_relative "bootstrap_windows_ssh"
|
21
|
-
require_relative "bootstrap_windows_winrm"
|
22
|
-
require_relative "winrm"
|
23
|
-
require_relative "wsman_test"
|
24
|
-
class Chef
|
25
|
-
class Knife
|
26
|
-
class WindowsHelper < Knife
|
27
|
-
banner "#{BootstrapWindowsWinrm.banner}\n" \
|
28
|
-
"#{BootstrapWindowsSsh.banner}\n" \
|
29
|
-
"#{Winrm.banner}\n" \
|
30
|
-
"#{WsmanTest.banner}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|