chef-winrm-fs 1.4.1 → 1.4.4

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.
data/bin/rwinrmcp CHANGED
@@ -1,87 +1,87 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # Copyright 2014 Shawn Neal <sneal@sneal.net>
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
- # TODO: refactor this
20
- # rubocop:disable all
21
-
22
- $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
23
-
24
- require 'io/console'
25
- require 'chef-winrm-fs'
26
-
27
- def help_msg
28
- puts 'Usage: rwinrmcp sourcefile user@host:directory/targetfile'
29
- puts ''
30
- end
31
-
32
- def parse_options
33
- options = {}
34
- fail 'Missing required options' unless ARGV.length == 2
35
-
36
- options[:source_path] = ARGV[0]
37
- fail "Cannot find source file: #{options[:source_path]}" unless \
38
- File.exist?(options[:source_path])
39
-
40
- m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/i.match(ARGV[1])
41
- fail "#{ARGV[1]} is an invalid destination" unless m
42
- options[:user] = m[:user]
43
- options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
44
- options[:dest_path] = m[:file]
45
-
46
- # Get the password
47
- print 'Password: '
48
- options[:pass] = STDIN.noecho(&:gets).chomp
49
- puts
50
-
51
- # Set some defaults required by WinRM WS
52
- options[:auth_type] = :plaintext
53
- options[:basic_auth_only] = true
54
-
55
- options
56
- rescue StandardError => e
57
- puts e.message
58
- help_msg
59
- exit 1
60
- end
61
-
62
- def file_manager(options)
63
- service = WinRM::WinRMWebService.new(
64
- options[:endpoint],
65
- options[:auth_type].to_sym,
66
- options)
67
- WinRM::FS::FileManager.new(service)
68
- end
69
-
70
- def run(options)
71
- bytes = file_manager(options).upload(options[:source_path], options[:dest_path])
72
- puts "#{bytes} total bytes transfered"
73
- exit 0
74
- rescue Interrupt
75
- puts 'exiting'
76
- # ctrl-c
77
- rescue WinRM::WinRMAuthorizationError
78
- puts 'Authentication failed, bad user name or password'
79
- exit 1
80
- rescue StandardError => e
81
- puts e.message
82
- exit 1
83
- end
84
-
85
- run(parse_options)
86
-
87
- # rubocop:enable all
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Copyright 2014 Shawn Neal <sneal@sneal.net>
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
+ # TODO: refactor this
20
+ # rubocop:disable all
21
+
22
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
23
+
24
+ require 'io/console'
25
+ require 'chef-winrm-fs'
26
+
27
+ def help_msg
28
+ puts 'Usage: rwinrmcp sourcefile user@host:directory/targetfile'
29
+ puts ''
30
+ end
31
+
32
+ def parse_options
33
+ options = {}
34
+ fail 'Missing required options' unless ARGV.length == 2
35
+
36
+ options[:source_path] = ARGV[0]
37
+ fail "Cannot find source file: #{options[:source_path]}" unless \
38
+ File.exist?(options[:source_path])
39
+
40
+ m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/i.match(ARGV[1])
41
+ fail "#{ARGV[1]} is an invalid destination" unless m
42
+ options[:user] = m[:user]
43
+ options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
44
+ options[:dest_path] = m[:file]
45
+
46
+ # Get the password
47
+ print 'Password: '
48
+ options[:pass] = STDIN.noecho(&:gets).chomp
49
+ puts
50
+
51
+ # Set some defaults required by WinRM WS
52
+ options[:auth_type] = :plaintext
53
+ options[:basic_auth_only] = true
54
+
55
+ options
56
+ rescue StandardError => e
57
+ puts e.message
58
+ help_msg
59
+ exit 1
60
+ end
61
+
62
+ def file_manager(options)
63
+ service = WinRM::WinRMWebService.new(
64
+ options[:endpoint],
65
+ options[:auth_type].to_sym,
66
+ options)
67
+ WinRM::FS::FileManager.new(service)
68
+ end
69
+
70
+ def run(options)
71
+ bytes = file_manager(options).upload(options[:source_path], options[:dest_path])
72
+ puts "#{bytes} total bytes transfered"
73
+ exit 0
74
+ rescue Interrupt
75
+ puts 'exiting'
76
+ # ctrl-c
77
+ rescue WinRM::WinRMAuthorizationError
78
+ puts 'Authentication failed, bad user name or password'
79
+ exit 1
80
+ rescue StandardError => e
81
+ puts e.message
82
+ exit 1
83
+ end
84
+
85
+ run(parse_options)
86
+
87
+ # rubocop:enable all