kanrisuru 0.16.12 → 0.16.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +1 -1
- data/lib/kanrisuru/core/dmi/parsers/dmi.rb +1 -2
- data/lib/kanrisuru/core/group/commands/create_group.rb +2 -0
- data/lib/kanrisuru/core/mount/commands/umount.rb +3 -0
- data/lib/kanrisuru/core/transfer/commands/download.rb +24 -4
- data/lib/kanrisuru/core/transfer/commands/upload.rb +2 -3
- data/lib/kanrisuru/core/user/commands/get_user.rb +14 -9
- data/lib/kanrisuru/core/user/parser.rb +1 -0
- data/lib/kanrisuru/core/user/parsers/user.rb +21 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/find_spec.rb +1 -1
- data/spec/functional/core/group_spec.rb +6 -1
- data/spec/functional/core/mount_spec.rb +2 -0
- data/spec/functional/remote/cluster_spec.rb +9 -9
- data/spec/support/shared_examples/integration/core/transfer.rb +18 -1
- data/spec/support/shared_examples/integration/core/user.rb +15 -1
- data/spec/support/shared_examples/integration/remote/cluster.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c72c91f337408d0a7dee545cabeb07ba9fac668baf8d3c3dbb65d0e04a27e347
|
4
|
+
data.tar.gz: 28d8387d8081783dfd32031c202ffc5ec66e4a7fea3306e8cb35d117f2193c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0d66db59619c3cb9e69567ef0ed08e564c53ca3171dccc7acd31410288dfa06ebfc5a5daa2ff09aa14cbbacf433175352928b8a6e837f2ba43217de5fb70ac
|
7
|
+
data.tar.gz: 8bfc4a39d3bb5ab4c9f180dd4e5682057a7c1fe5c5bd93e25a6d88280a6e12c79831e0c5d9cb05b2b3211b91e3c6161d585fcc20c2d851da100037393dd17752
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## Kanrisuru 0.16.16 (January 08, 2022) ##
|
2
|
+
* Fix issue with `download` command when downloading directories from remote server.
|
3
|
+
|
4
|
+
## Kanrisuru 0.16.15 (January 07, 2022) ##
|
5
|
+
* Add recursive and all_targets opts to `umount` command.
|
6
|
+
|
7
|
+
## Kanrisuru 0.16.14 (January 02, 2022) ##
|
8
|
+
* Fix `get_user` command by parsing output to get user name if uid is passed in.
|
9
|
+
|
10
|
+
## Kanrisuru 0.16.13 (January 01, 2022) ##
|
11
|
+
* Add `non_unique` and `system` opts to `create_group` command
|
12
|
+
|
1
13
|
## Kanrisuru 0.16.12 (January 01, 2022) ##
|
2
14
|
* Update date ranges for 2022 on license files.
|
3
15
|
* Add unit test case for `Kanrisuru::Logger`.
|
data/README.md
CHANGED
@@ -16,6 +16,9 @@ module Kanrisuru
|
|
16
16
|
|
17
17
|
command.append_flag('-l', opts[:lazy])
|
18
18
|
command.append_flag('-f', opts[:force])
|
19
|
+
|
20
|
+
command.append_flag('--all-targets', opts[:all_targets])
|
21
|
+
command.append_flag('--recursive', opts[:recursive])
|
19
22
|
|
20
23
|
if Kanrisuru::Util.present?(all)
|
21
24
|
command.append_flag('-a')
|
@@ -4,21 +4,41 @@ module Kanrisuru
|
|
4
4
|
module Core
|
5
5
|
module Transfer
|
6
6
|
def download(remote_path, local_path = nil, opts = {})
|
7
|
+
recursive = opts[:recursive] || false
|
8
|
+
|
9
|
+
remote_path += '/' if !remote_path.end_with?('/') && recursive
|
10
|
+
local_path += '/' if !local_path.nil? && !local_path.end_with?('/') && recursive
|
11
|
+
|
7
12
|
if local_path.instance_of?(Hash)
|
8
13
|
opts = local_path
|
9
14
|
local_path = nil
|
10
15
|
end
|
11
16
|
|
12
|
-
|
17
|
+
tmp_name = "kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
|
18
|
+
tmp_path = "/tmp/#{tmp_name}"
|
13
19
|
|
14
20
|
begin
|
15
|
-
result = cp(remote_path, tmp_path, force: true)
|
21
|
+
result = cp(remote_path, tmp_path, force: true, follow: true, recursive: recursive)
|
16
22
|
raise 'Unable to copy remote file to temp path' unless result.success?
|
17
23
|
|
24
|
+
result = chown(tmp_path, owner: @username, group: @username, recursive: recursive)
|
25
|
+
raise 'Unable to update owner or group for temp path' unless result.success?
|
26
|
+
|
27
|
+
result = chmod(tmp_path, 'u+r', recursive: true)
|
28
|
+
raise 'Unable to update owner permission read access' unless result.success?
|
29
|
+
|
30
|
+
local_path = ::File.expand_path(local_path) if local_path
|
18
31
|
result = ssh.scp.download!(tmp_path, local_path, opts)
|
19
|
-
|
32
|
+
return false unless result
|
33
|
+
|
34
|
+
if Kanrisuru::Util.present?(local_path) && recursive
|
35
|
+
remote_dirname = remote_path.split('/').last
|
36
|
+
FileUtils.mv("#{local_path}/#{tmp_name}", "#{local_path}/#{remote_dirname}")
|
37
|
+
else
|
38
|
+
result
|
39
|
+
end
|
20
40
|
ensure
|
21
|
-
rm(tmp_path, force: true) if inode?(tmp_path)
|
41
|
+
rm(tmp_path, force: true, recursive: recursive) if inode?(tmp_path)
|
22
42
|
end
|
23
43
|
end
|
24
44
|
end
|
@@ -12,9 +12,7 @@ module Kanrisuru
|
|
12
12
|
|
13
13
|
## Need to copy internal dir contents, not the tmp dir itself
|
14
14
|
if opts[:recursive]
|
15
|
-
unless dir?(remote_path)
|
16
|
-
mkdir(remote_path, silent: true)
|
17
|
-
end
|
15
|
+
mkdir(remote_path, silent: true) unless dir?(remote_path)
|
18
16
|
|
19
17
|
result = cp("#{tmp_path}/*", remote_path, recursive: true)
|
20
18
|
else
|
@@ -22,6 +20,7 @@ module Kanrisuru
|
|
22
20
|
end
|
23
21
|
|
24
22
|
raise "Unable to move file to remote path - #{result.command.raw_result}" unless result.success?
|
23
|
+
|
25
24
|
stat(remote_path)
|
26
25
|
ensure
|
27
26
|
rm(tmp_path, force: true) if inode?(tmp_path)
|
@@ -8,11 +8,16 @@ module Kanrisuru
|
|
8
8
|
execute_shell(command)
|
9
9
|
|
10
10
|
Kanrisuru::Result.new(command) do |cmd|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
if Kanrisuru::Util.numeric?(user)
|
12
|
+
uid = user.to_i
|
13
|
+
user = Parser::User.parse(cmd)
|
14
|
+
else
|
15
|
+
## Get user id
|
16
|
+
result = get_uid(user)
|
17
|
+
break if result.failure?
|
18
|
+
|
19
|
+
uid = result.to_i
|
20
|
+
end
|
16
21
|
|
17
22
|
## Get all groups for the user, with gid and group name
|
18
23
|
array = Parser::Groups.parse(cmd)
|
@@ -24,12 +29,12 @@ module Kanrisuru
|
|
24
29
|
end
|
25
30
|
|
26
31
|
## Get home / shell path information
|
27
|
-
|
28
|
-
|
32
|
+
command2 = Kanrisuru::Command.new("getent passwd #{user}")
|
33
|
+
command2 | "awk -F: '{print $6, $7}'"
|
29
34
|
|
30
|
-
execute(
|
35
|
+
execute(command2)
|
31
36
|
|
32
|
-
result = Kanrisuru::Result.new(
|
37
|
+
result = Kanrisuru::Result.new(command2) do |cmd2|
|
33
38
|
Parser::Getent.parse(cmd2)
|
34
39
|
end
|
35
40
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
module Parser
|
7
|
+
class User
|
8
|
+
def self.parse(command)
|
9
|
+
string = command.to_s
|
10
|
+
string = string.split[0]
|
11
|
+
|
12
|
+
matches = string.match(/uid=\d+\((.+)\)/)
|
13
|
+
return if !matches || !matches.captures
|
14
|
+
|
15
|
+
matches.captures.first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -21,7 +21,12 @@ RSpec.describe Kanrisuru::Core::Group do
|
|
21
21
|
|
22
22
|
it 'prepares create_group command' do
|
23
23
|
expect_command(host.create_group('admin'), 'groupadd admin')
|
24
|
-
expect_command(host.create_group('admin',
|
24
|
+
expect_command(host.create_group('admin',
|
25
|
+
gid: 9000,
|
26
|
+
non_unique: true),
|
27
|
+
'groupadd admin -g 9000 -o')
|
28
|
+
|
29
|
+
expect_command(host.create_group('admin', gid: 12, system: true), 'groupadd admin -g 12 -r')
|
25
30
|
end
|
26
31
|
|
27
32
|
it 'prepares delete_group command' do
|
@@ -95,6 +95,8 @@ RSpec.describe Kanrisuru::Core::Mount do
|
|
95
95
|
|
96
96
|
it 'prepares umount command' do
|
97
97
|
expect_command(host.umount, 'umount')
|
98
|
+
expect_command(host.umount(recursive: true, all_targets: true), 'umount --all-targets --recursive')
|
99
|
+
|
98
100
|
expect_command(host.umount(
|
99
101
|
fake: true,
|
100
102
|
no_canonicalize: true,
|
@@ -85,9 +85,9 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
85
85
|
expect(command.prepared_command).to eq('sudo -u root /bin/bash -c "ls"')
|
86
86
|
expect(cloned_command.prepared_command).to eq('sudo -u root /bin/bash -c "ls"')
|
87
87
|
|
88
|
-
expect
|
88
|
+
expect do
|
89
89
|
cluster.send(:create_command, 1)
|
90
|
-
|
90
|
+
end.to raise_error(ArgumentError)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'runs execute for a command on a cluster' do
|
@@ -178,8 +178,8 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
178
178
|
|
179
179
|
cluster.cd('/etc')
|
180
180
|
cluster.each do |host|
|
181
|
-
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
182
|
-
end
|
181
|
+
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
182
|
+
end
|
183
183
|
|
184
184
|
StubNetwork.unstub_command!(:pwd)
|
185
185
|
StubNetwork.unstub_command!(:realpath)
|
@@ -198,18 +198,18 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
198
198
|
|
199
199
|
cluster.chdir('/etc')
|
200
200
|
cluster.each do |host|
|
201
|
-
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
202
|
-
end
|
201
|
+
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
202
|
+
end
|
203
203
|
|
204
204
|
StubNetwork.unstub_command!(:pwd)
|
205
205
|
StubNetwork.unstub_command!(:realpath)
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
it 'fails to remove a host from a cluster' do
|
209
209
|
cluster = described_class.new(host1, host2)
|
210
210
|
|
211
|
-
expect
|
211
|
+
expect do
|
212
212
|
cluster.delete(1)
|
213
|
-
|
213
|
+
end.to raise_error(ArgumentError)
|
214
214
|
end
|
215
215
|
end
|
@@ -34,6 +34,7 @@ RSpec.shared_examples 'transfer' do |os_name, host_json, spec_dir|
|
|
34
34
|
keys: [host_json['ssh_key']]
|
35
35
|
)
|
36
36
|
|
37
|
+
FileUtils.rm_rf("../test-output-#{os_name}")
|
37
38
|
host.rmdir(spec_dir)
|
38
39
|
host.disconnect
|
39
40
|
end
|
@@ -80,7 +81,7 @@ RSpec.shared_examples 'transfer' do |os_name, host_json, spec_dir|
|
|
80
81
|
src_path = '/etc/hosts'
|
81
82
|
|
82
83
|
result = host.download(src_path, path)
|
83
|
-
expect(result).to
|
84
|
+
expect(result).to be_truthy
|
84
85
|
FileUtils.rm(path)
|
85
86
|
end
|
86
87
|
|
@@ -93,6 +94,22 @@ RSpec.shared_examples 'transfer' do |os_name, host_json, spec_dir|
|
|
93
94
|
expect(lines.length).to be >= 1
|
94
95
|
end
|
95
96
|
|
97
|
+
it 'downloads a dir' do
|
98
|
+
remote_path = '/var/log'
|
99
|
+
local_path = "../test-output-#{os_name}"
|
100
|
+
FileUtils.mkdir(local_path)
|
101
|
+
|
102
|
+
host.su('root')
|
103
|
+
result = host.download(remote_path, local_path, recursive: true)
|
104
|
+
expect(result).not_to be nil
|
105
|
+
|
106
|
+
paths = host.ls(path: '/var/log').map(&:path)
|
107
|
+
Dir.glob("#{local_path}/log/*").each do |file|
|
108
|
+
name = File.basename(file)
|
109
|
+
expect(paths).to include(name)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
96
113
|
it 'wgets url' do
|
97
114
|
result = host.wget('https://example.com', directory_prefix: spec_dir)
|
98
115
|
expect(result).to be_success
|
@@ -35,7 +35,7 @@ RSpec.shared_examples 'user' do |os_name, host_json, _spec_dir|
|
|
35
35
|
expect(host.get_uid('asdf').to_i).to eq(nil)
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'gets a user details' do
|
38
|
+
it 'gets a user details by name' do
|
39
39
|
result = host.get_user(host_json['username'])
|
40
40
|
expect(result.uid).to eq(1000)
|
41
41
|
expect(result.name).to eq(host_json['username'])
|
@@ -49,6 +49,20 @@ RSpec.shared_examples 'user' do |os_name, host_json, _spec_dir|
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
it 'gets a user details by uid' do
|
53
|
+
result = host.get_user(1000)
|
54
|
+
expect(result.uid).to eq(1000)
|
55
|
+
expect(result.name).to eq(host_json['username'])
|
56
|
+
expect(result.home.path).to eq(host_json['home'])
|
57
|
+
|
58
|
+
case os_name
|
59
|
+
when 'opensuse', 'sles'
|
60
|
+
expect(result.groups[0]).to have_attributes(gid: 100, name: 'users')
|
61
|
+
else
|
62
|
+
expect(result.groups[0]).to have_attributes(gid: 1000, name: host_json['username'])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
52
66
|
it 'manages a user' do
|
53
67
|
## Need priviledge escalation to manage group
|
54
68
|
host.su('root')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanrisuru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mammina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel_tests
|
@@ -347,6 +347,7 @@ files:
|
|
347
347
|
- lib/kanrisuru/core/user/parser.rb
|
348
348
|
- lib/kanrisuru/core/user/parsers/getent.rb
|
349
349
|
- lib/kanrisuru/core/user/parsers/groups.rb
|
350
|
+
- lib/kanrisuru/core/user/parsers/user.rb
|
350
351
|
- lib/kanrisuru/core/user/types.rb
|
351
352
|
- lib/kanrisuru/core/yum.rb
|
352
353
|
- lib/kanrisuru/core/yum/commands.rb
|