remotus 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d07fd3936fbe26fea5629acc43238c698f735f3d6814f0733c3b5b81d638f340
4
- data.tar.gz: fd028ed4fe407c5f4b9dc82ecdc7ec3371c4605cc19997227287df08badcaa9b
3
+ metadata.gz: 34953ce4b1c254e31a40b7b3ff3795124fe98b712722862a35813cceba686759
4
+ data.tar.gz: 3d342087b707b3078cedf38038b3ba21c1a1db6ed7c7d189f5912d9cd5adf4e7
5
5
  SHA512:
6
- metadata.gz: 143e87065eb71702504a6773c74e68bc4a6efff6f08cbc8b812ed0c84db7a994719b578e4eb6a345a0f2369a11c1f4b05e1a9531a015cee345f958186ee06860
7
- data.tar.gz: 54ce478b43f70a989d8103f659da7ae61723794da6ef1918eee33ff73ee1d363dfb772da8297a4b8428712f639291d481c1df3112d5d09ba1bbbb3c2fd58883b
6
+ metadata.gz: c884fbb30a585899e840ab9e3dddd3b3d6ac052d4b10745bc9c582f9e67ca445aa9ef98af7ac8cbba551cc6594f23a9583d3f54cfba6202f3b8595804bd60641
7
+ data.tar.gz: 166f8cb4e3e633a79f1f28ddba9a3ff8793cc2927873bdd349e035870273c81ad6a9688f37d2f871413f43451604f64a06631e0813f8e111f7d36c701a168b05
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2022-06-02
4
+ * Added winrm-elevated gem to solve wirnrm AuthenticationError
5
+
3
6
  ## [0.3.0] - 2022-02-18
4
7
  * Add retries to SSH SCP transactions
5
8
 
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remotus (0.3.0)
4
+ remotus (0.4.0)
5
5
  connection_pool (~> 2.2)
6
6
  net-scp (~> 3.0)
7
7
  net-ssh (~> 6.1)
8
8
  winrm (~> 2.3)
9
+ winrm-elevated (~> 1.2)
9
10
  winrm-fs (~> 1.3)
10
11
 
11
12
  GEM
@@ -19,11 +20,12 @@ GEM
19
20
  ffi (1.15.5)
20
21
  gssapi (1.3.1)
21
22
  ffi (>= 1.0.1)
22
- gyoku (1.3.1)
23
+ gyoku (1.4.0)
23
24
  builder (>= 2.1.2)
25
+ rexml (~> 3.0)
24
26
  httpclient (2.8.3)
25
27
  little-plugger (1.1.4)
26
- logging (2.3.0)
28
+ logging (2.3.1)
27
29
  little-plugger (~> 1.1)
28
30
  multi_json (~> 1.14)
29
31
  multi_json (1.15.0)
@@ -80,6 +82,10 @@ GEM
80
82
  logging (>= 1.6.1, < 3.0)
81
83
  nori (~> 2.0)
82
84
  rubyntlm (~> 0.6.0, >= 0.6.3)
85
+ winrm-elevated (1.2.3)
86
+ erubi (~> 1.8)
87
+ winrm (~> 2.0)
88
+ winrm-fs (~> 1.0)
83
89
  winrm-fs (1.3.5)
84
90
  erubi (~> 1.8)
85
91
  logging (>= 1.6.1, < 3.0)
data/README.md CHANGED
@@ -54,6 +54,9 @@ result.exit_code
54
54
  # Run a command on the remote host with sudo (Linux only, requires password to be specified)
55
55
  result = connection.run("ls /root", sudo: true)
56
56
 
57
+ # Run a command on the remote host with elevated shell privilege
58
+ result = connection.run("ipconfig", shell: :elevated)
59
+
57
60
  # Run a script on the remote host
58
61
  connection.run_script("/local/script.sh", "/remote/path/script.sh")
59
62
 
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "winrm-elevated"
4
+
5
+ module Remotus
6
+ # Core Ruby extensions
7
+ module CoreExt
8
+ # WinRM Elevated extension module
9
+ module Elevated
10
+ unless method_defined?(:connection_opts)
11
+ #
12
+ # Returns a hash for the connection options from the interal
13
+ # WinRM::Shells::Powershell object
14
+ #
15
+ # @return [Hash] internal WinRM::Shells::Powershell connection options
16
+ #
17
+ def connection_opts
18
+ @shell.connection_opts
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # @api private
26
+ # Main WinRM module
27
+ module WinRM
28
+ # Shells module (contains PowerShell, Elevated, etc.)
29
+ module Shells
30
+ # Elevated PowerShell class from winrm-elevated
31
+ class Elevated
32
+ include Remotus::CoreExt::Elevated
33
+ end
34
+ end
35
+ end
@@ -24,4 +24,8 @@ module Remotus
24
24
  end
25
25
  end
26
26
 
27
- String.include(Remotus::CoreExt::String)
27
+ # @api private
28
+ # Core ruby string class
29
+ class String
30
+ include Remotus::CoreExt::String
31
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Remotus
4
4
  # Remotus gem version
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
@@ -4,7 +4,9 @@ require "forwardable"
4
4
  require "remotus"
5
5
  require "remotus/result"
6
6
  require "remotus/auth"
7
+ require "remotus/core_ext/elevated"
7
8
  require "winrm"
9
+ require "winrm-elevated"
8
10
  require "winrm-fs"
9
11
 
10
12
  module Remotus
@@ -21,6 +23,9 @@ module Remotus
21
23
  # @return [String] host hostname
22
24
  attr_reader :host
23
25
 
26
+ # @return [String] shell type
27
+ attr_reader :shell
28
+
24
29
  # @return [Remotus::HostPool] host_pool associated host pool
25
30
  attr_reader :host_pool
26
31
 
@@ -38,6 +43,7 @@ module Remotus
38
43
  @host = host
39
44
  @port = port
40
45
  @host_pool = host_pool
46
+ @shell = :powershell
41
47
  end
42
48
 
43
49
  #
@@ -69,14 +75,17 @@ module Remotus
69
75
 
70
76
  #
71
77
  # Retrieves/creates the WinRM shell connection for the host
78
+ #
79
+ # @param [symbol] shell connection shell type, defaults to :powershell
72
80
  # If the connection already exists, the existing connection will be retrieved
73
81
  #
74
- # @return [WinRM::Shells::Powershell] remote connection
82
+ # @return [WinRM::Shells::Powershell, WinRM::Shells::Elevated] remote connection
75
83
  #
76
- def connection
77
- return @connection unless restart_connection?
84
+ def connection(shell = :powershell)
85
+ return @connection unless restart_connection?(shell: shell)
78
86
 
79
- @connection = base_connection(reload: true).shell(:powershell)
87
+ @shell = shell
88
+ @connection = base_connection(reload: true).shell(@shell)
80
89
  end
81
90
 
82
91
  #
@@ -93,13 +102,14 @@ module Remotus
93
102
  #
94
103
  # @param [String] command command to run
95
104
  # @param [Array] args command arguments
96
- # @param [Hash] _options unused command options
105
+ # @param [Hash] options command options
106
+ # @option options [Symbol] :shell shell type to use for the connection
97
107
  #
98
108
  # @return [Remotus::Result] result describing the stdout, stderr, and exit status of the command
99
109
  #
100
- def run(command, *args, **_options)
110
+ def run(command, *args, **options)
101
111
  command = "#{command}#{args.empty? ? "" : " "}#{args.join(" ")}"
102
- run_result = connection.run(command)
112
+ run_result = options[:shell].nil? ? connection.run(command) : connection(options[:shell]).run(command)
103
113
  Remotus::Result.new(command, run_result.stdout, run_result.stderr, run_result.output, run_result.exitcode)
104
114
  rescue WinRM::WinRMAuthorizationError => e
105
115
  raise Remotus::AuthenticationError, e.to_s
@@ -171,7 +181,7 @@ module Remotus
171
181
  # @return [Boolean] whether to restart the current base connection
172
182
  #
173
183
  def restart_base_connection?
174
- return restart_connection? if @connection
184
+ return restart_connection?(shell: @shell) if @connection
175
185
  return true unless @base_connection
176
186
  return true if @host != @base_connection.instance_values["connection_opts"][:endpoint].scan(%r{//(.*):}).flatten.first
177
187
  return true if Remotus::Auth.credential(self).user != @base_connection.instance_values["connection_opts"][:user]
@@ -183,10 +193,14 @@ module Remotus
183
193
  #
184
194
  # Whether to restart the current WinRM connection
185
195
  #
196
+ # @param [Hash] options restart connection options
197
+ # @option options [Symbol] :shell shell type to use for the connection
198
+ #
186
199
  # @return [Boolean] whether to restart the current connection
187
200
  #
188
- def restart_connection?
201
+ def restart_connection?(**options)
189
202
  return true unless @connection
203
+ return true if shell && !options[:shell].casecmp?(@shell)
190
204
  return true if @host != @connection.connection_opts[:endpoint].scan(%r{//(.*):}).flatten.first
191
205
  return true if Remotus::Auth.credential(self).user != @connection.connection_opts[:user]
192
206
  return true if Remotus::Auth.credential(self).password != @connection.connection_opts[:password]
data/remotus.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "net-scp", "~> 3.0"
34
34
  spec.add_dependency "net-ssh", "~> 6.1"
35
35
  spec.add_dependency "winrm", "~> 2.3"
36
+ spec.add_dependency "winrm-elevated", "~> 1.2"
36
37
  spec.add_dependency "winrm-fs", "~> 1.3"
37
38
 
38
39
  # Development dependencies
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Newell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-18 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: winrm-elevated
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: winrm-fs
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +202,7 @@ files:
188
202
  - lib/remotus/auth/credential.rb
189
203
  - lib/remotus/auth/hash_store.rb
190
204
  - lib/remotus/auth/store.rb
205
+ - lib/remotus/core_ext/elevated.rb
191
206
  - lib/remotus/core_ext/string.rb
192
207
  - lib/remotus/host_pool.rb
193
208
  - lib/remotus/logger.rb