kanrisuru 0.16.15 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2d1d9331232a2c1c343da0fd4a8d11fcef4b0197aea108fe1d6047a60c390f7
4
- data.tar.gz: 8e8cbf4381da58b367fbb9aa2ac29fa68d8c4eed68ca3197cfaedf71cec69f85
3
+ metadata.gz: bde6a8003df4dbe874a1b2471eb042b294fabc7e84d4146458fd3a1dbf4882ca
4
+ data.tar.gz: 4b2e3f0f35c62ee2286ad9aea4ae32cd7044418cc141c1abc176c5b017821c8d
5
5
  SHA512:
6
- metadata.gz: f5eaa5caba5ae1f48e02fc4d6dadc03ab0ff6a94c47353e365adca6235424189e76ccb41fe513121d97013b819bd149636edef726d988c436269f4d230e524b8
7
- data.tar.gz: 9ab07c9fdcf14fc3a314cbce0d9952456fa0daccb77bfeb2e8de92ad4a131f4d5f661033a3ef41c540adc18b73be0e11574b86b65a2392f2d446baaa043f13a0
6
+ metadata.gz: b32475bde12456c03a3028f8ebbc6f792d59ad69b8014737d266d65ea4d4ba3208f864aa1eb8de58929abc8460e41971371fc6d4c3bc6c2d6e28db54c73fc9b5
7
+ data.tar.gz: a22f5af50adce7dc76504ba78fdddd000d08766e2115e4d092b12e8d44b5b76aa3e0f68cf6286c3344cde9d82520238ecd96b2e6b0b11384cc4ec859bbcebd2a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Kanrisuru 0.18.0 (January 23, 2022) ##
2
+ * Add `history` command with test cases.
3
+
4
+ ## Kanrisuru 0.17.0 (January 20, 2022) ##
5
+ * Add `nproc` command with test cases.
6
+
7
+ ## Kanrisuru 0.16.17 (January 10, 2022) ##
8
+ * Add additional options to `wget` command.
9
+ * Rename some options to better reflect options from wget program.
10
+
11
+ ## Kanrisuru 0.16.16 (January 08, 2022) ##
12
+ * Fix issue with `download` command when downloading directories from remote server.
13
+
1
14
  ## Kanrisuru 0.16.15 (January 07, 2022) ##
2
15
  * Add recursive and all_targets opts to `umount` command.
3
16
 
@@ -126,8 +126,7 @@ module Kanrisuru
126
126
  field = field.downcase
127
127
  field = field.gsub(/\s/, '_')
128
128
  field = field.gsub('-', '_')
129
- field = field.gsub(':', '')
130
- field
129
+ field.gsub(':', '')
131
130
  end
132
131
 
133
132
  def dmi_type_to_struct(type)
@@ -16,7 +16,7 @@ module Kanrisuru
16
16
 
17
17
  command.append_flag('-l', opts[:lazy])
18
18
  command.append_flag('-f', opts[:force])
19
-
19
+
20
20
  command.append_flag('--all-targets', opts[:all_targets])
21
21
  command.append_flag('--recursive', opts[:recursive])
22
22
 
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module System
6
+ def history(opts = {})
7
+ histfile = opts[:histfile] || '~/.bash_history'
8
+
9
+ command = Kanrisuru::Command.new("HISTFILE=#{histfile}; history -r; history")
10
+
11
+ if Kanrisuru::Util.present?(opts[:delete])
12
+ command.append_arg('-d', Kanrisuru::Util.array_join_string(opts[:delete], ' '))
13
+ elsif Kanrisuru::Util.present?(opts[:clear])
14
+ command.append_flag('-c')
15
+ elsif Kanrisuru::Util.present?(opts[:n])
16
+ command << opts[:n]
17
+ end
18
+
19
+ execute_shell(command)
20
+
21
+ Kanrisuru::Result.new(command) do |cmd|
22
+ return if Kanrisuru::Util.present?(opts[:delete]) || Kanrisuru::Util.present?(opts[:clear])
23
+
24
+ Parser::History.parse(cmd)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module System
6
+ def nproc(opts = {})
7
+ command = Kanrisuru::Command.new('nproc')
8
+ command.append_flag('--all', opts[:all])
9
+ execute_shell(command)
10
+
11
+ Kanrisuru::Result.new(command, &:to_i)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'commands/cpu_info'
4
4
  require_relative 'commands/free'
5
+ require_relative 'commands/history'
5
6
  require_relative 'commands/kernel_statistics'
6
7
  require_relative 'commands/kill'
7
8
  require_relative 'commands/last'
@@ -9,6 +10,7 @@ require_relative 'commands/load_average'
9
10
  require_relative 'commands/load_env'
10
11
  require_relative 'commands/lscpu'
11
12
  require_relative 'commands/lsof'
13
+ require_relative 'commands/nproc'
12
14
  require_relative 'commands/poweroff'
13
15
  require_relative 'commands/ps'
14
16
  require_relative 'commands/reboot'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'parsers/kernel_statistics'
4
+ require_relative 'parsers/history'
4
5
  require_relative 'parsers/last'
5
6
  require_relative 'parsers/load_average'
6
7
  require_relative 'parsers/load_env'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module System
6
+ module Parser
7
+ class History
8
+ def self.parse(command)
9
+ lines = command.to_a
10
+ lines.map do |line|
11
+ line.split(/^\d+\s+/)[1]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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
- tmp_path = "/tmp/kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
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
- Kanrisuru::Util.blank?(local_path) ? result : local_path
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)
@@ -105,7 +105,12 @@ module Kanrisuru
105
105
  end
106
106
 
107
107
  command.append_arg('--post-file', opts[:post_file])
108
+ command.append_arg('--method', opts[:method])
109
+
108
110
  command.append_flag('--content-disposition', opts[:content_disposition])
111
+ command.append_flag('--content-on-error', opts[:content_on_error])
112
+ command.append_flag('--trust-server-names', opts[:trust_server_names])
113
+ command.append_flag('--retry-on-host-error', opts[:retry_on_host_error])
109
114
 
110
115
  ## SSL / TLS
111
116
  if Kanrisuru::Util.present?(opts[:secure_protocol])
@@ -123,18 +128,24 @@ module Kanrisuru
123
128
  command.append_arg('--ca-directory', opts[:ca_directory])
124
129
  command.append_arg('--random-file', opts[:random_file])
125
130
  command.append_arg('--egd-file', opts[:egd_file])
131
+ command.append_flag('--https-only', opts[:https_only])
126
132
 
127
- ## FTP
133
+ ## FTP / FTPS
128
134
  command.append_arg('--ftp-user', opts[:ftp_user])
129
135
  command.append_arg('--ftp-password', opts[:ftp_password])
130
136
  command.append_flag('--no-remove-listing', opts[:no_remove_listing])
131
137
  command.append_flag('--no-glob', opts[:no_glob])
132
138
  command.append_flag('--no-passive-ftp', opts[:no_passive_ftp])
133
139
  command.append_flag('--retr-symlinks', opts[:retr_symlinks])
140
+ command.append_flag('--preserve-permissions', opts[:preserve_permissions])
141
+ command.append_flag('--ftps-implicit', opts[:ftps_implicit])
142
+ command.append_flag('--no-ftps-resume-ssl', opts[:no_ftps_resume_ssl])
143
+ command.append_flag('--ftps-clear-data-connection', opts[:ftps_clear_data_connection])
144
+ command.append_flag('--ftps-fallback-to-ftp', opts[:ftps_fallback_to_ftp])
134
145
 
135
146
  ## Recursive Retrieval
136
147
  command.append_flag('--recursive', opts[:recursive])
137
- command.append_arg('--level', opts[:depth])
148
+ command.append_arg('--level', opts[:level])
138
149
  command.append_flag('--delete-after', opts[:delete_after])
139
150
  command.append_flag('--convert-links', opts[:convert_links])
140
151
  command.append_flag('--backup-converted', opts[:backup_converted])
@@ -143,10 +154,13 @@ module Kanrisuru
143
154
  command.append_flag('--strict-comments', opts[:strict_comments])
144
155
 
145
156
  ## Recursive Accept/Reject
146
- command.append_arg('--accept', Kanrisuru::Util.array_join_string(opts[:accept_list]))
147
- command.append_arg('--reject', Kanrisuru::Util.array_join_string(opts[:reject_list]))
148
- command.append_arg('--domains', Kanrisuru::Util.array_join_string(opts[:domain_list]))
149
- command.append_arg('--exclude-domains', Kanrisuru::Util.array_join_string(opts[:exclude_domain_list]))
157
+ command.append_arg('--accept', Kanrisuru::Util.array_join_string(opts[:accept]))
158
+ command.append_arg('--reject', Kanrisuru::Util.array_join_string(opts[:reject]))
159
+ command.append_arg('--accept-regex', opts[:accept_regex])
160
+ command.append_arg('--reject-regex', opts[:reject_regex])
161
+ command.append_arg('--regex_type', opts[:regex_type])
162
+ command.append_arg('--domains', Kanrisuru::Util.array_join_string(opts[:domains]))
163
+ command.append_arg('--exclude-domains', Kanrisuru::Util.array_join_string(opts[:exclude_domains]))
150
164
  command.append_arg('--follow-tags', Kanrisuru::Util.array_join_string(opts[:follow_tags]))
151
165
  command.append_arg('--ignore-tags', Kanrisuru::Util.array_join_string(opts[:ignore_tags]))
152
166
  command.append_arg('--include-directories', Kanrisuru::Util.array_join_string(opts[:include_directories]))
@@ -10,11 +10,12 @@ module Kanrisuru
10
10
  Kanrisuru::Result.new(command) do |cmd|
11
11
  if Kanrisuru::Util.numeric?(user)
12
12
  uid = user.to_i
13
- user = Parser::User.parse(cmd)
13
+ user = Parser::User.parse(cmd)
14
14
  else
15
15
  ## Get user id
16
16
  result = get_uid(user)
17
17
  break if result.failure?
18
+
18
19
  uid = result.to_i
19
20
  end
20
21
 
@@ -8,7 +8,7 @@ module Kanrisuru
8
8
  def self.parse(command)
9
9
  string = command.to_s
10
10
  string = string.split[0]
11
-
11
+
12
12
  matches = string.match(/uid=\d+\((.+)\)/)
13
13
  return if !matches || !matches.captures
14
14
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.16.15'
4
+ VERSION = '0.18.0'
5
5
  end
@@ -68,7 +68,7 @@ RSpec.describe Kanrisuru::Core::Find do
68
68
  paths: '/dev',
69
69
  iname: 'tty*'
70
70
  ),
71
- "find /dev -iname tty*")
71
+ 'find /dev -iname tty*')
72
72
 
73
73
  expect_command(host.find(
74
74
  paths: '/dev',
@@ -22,11 +22,9 @@ RSpec.describe Kanrisuru::Core::Group do
22
22
  it 'prepares create_group command' do
23
23
  expect_command(host.create_group('admin'), 'groupadd admin')
24
24
  expect_command(host.create_group('admin',
25
- gid: 9000,
26
- non_unique: true
27
- ),
28
- 'groupadd admin -g 9000 -o'
29
- )
25
+ gid: 9000,
26
+ non_unique: true),
27
+ 'groupadd admin -g 9000 -o')
30
28
 
31
29
  expect_command(host.create_group('admin', gid: 12, system: true), 'groupadd admin -g 12 -r')
32
30
  end
@@ -43,6 +43,20 @@ RSpec.describe Kanrisuru::Core::System do
43
43
  end.to raise_error(ArgumentError)
44
44
  end
45
45
 
46
+ it 'prepares history command' do
47
+ expect_command(host.history, 'HISTFILE=~/.bash_history; history -r; history')
48
+ expect_command(host.history(histfile: '~/.history', n: 100),
49
+ 'HISTFILE=~/.history; history -r; history 100')
50
+ expect_command(host.history(clear: true),
51
+ 'HISTFILE=~/.bash_history; history -r; history -c')
52
+ expect_command(host.history(delete: 5),
53
+ 'HISTFILE=~/.bash_history; history -r; history -d 5')
54
+ expect_command(host.history(delete: [23, 30]),
55
+ 'HISTFILE=~/.bash_history; history -r; history -d 23 30')
56
+ expect_command(host.history(delete: '-7'),
57
+ 'HISTFILE=~/.bash_history; history -r; history -d -7')
58
+ end
59
+
46
60
  it 'prepares kernel_statistics command' do
47
61
  expect_command(host.kernel_statistics, 'cat /proc/stat')
48
62
  end
@@ -124,6 +138,11 @@ RSpec.describe Kanrisuru::Core::System do
124
138
  end.to raise_error(ArgumentError)
125
139
  end
126
140
 
141
+ it 'prepares nproc command' do
142
+ expect_command(host.nproc, 'nproc')
143
+ expect_command(host.nproc(all: true), 'nproc --all')
144
+ end
145
+
127
146
  it 'prepares uptime command' do
128
147
  expect_command(host.uptime, 'cat /proc/uptime')
129
148
  end
@@ -97,8 +97,11 @@ RSpec.describe Kanrisuru::Core::Stat do
97
97
  },
98
98
  content_disposition: true,
99
99
  secure_protocol: 'SSLv3',
100
+ content_on_error: true,
101
+ trust_server_names: true,
102
+ retry_on_host_error: true,
100
103
  no_check_certificate: true),
101
- "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}")
104
+ "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --content-on-error --trust-server-names --retry-on-host-error --secure-protocol SSLv3 --no-check-certificate #{url}")
102
105
 
103
106
  expect do
104
107
  host.wget(url, secure_protocol: 'SSL')
@@ -115,27 +118,37 @@ RSpec.describe Kanrisuru::Core::Stat do
115
118
 
116
119
  expect_command(host.wget(url,
117
120
  certificate: '~/cert.pem',
121
+ https_only: true,
118
122
  certificate_type: 'PEM',
119
123
  private_key: '~/key.pem',
120
124
  private_key_type: 'PEM',
121
125
  ca_certificate: '~/ca.pem',
122
126
  random_file: '~/random'),
123
- "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}")
127
+ "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random --https-only #{url}")
124
128
 
125
129
  ## FTP
126
- expect_command(host.wget(url,
130
+ expect_command(host.wget('ftp.example.com',
127
131
  ftp_user: 'admin',
128
132
  ftp_password: '12345678',
129
133
  no_remove_listing: true,
130
134
  no_glob: true,
131
135
  no_passive_ftp: true,
132
- retr_symlinks: true),
133
- "wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}")
136
+ retr_symlinks: true,
137
+ preserve_permissions: true),
138
+ 'wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks --preserve-permissions ftp.example.com')
139
+
140
+ expect_command(host.wget('ftps.example.com',
141
+ ftp_user: 'admin',
142
+ ftp_password: '12345678',
143
+ ftps_implicit: true,
144
+ no_ftps_resume_ssl: true,
145
+ ftps_fallback_to_ftp: true,
146
+ ftps_clear_data_connection: true), 'wget --ftp-user admin --ftp-password 12345678 --ftps-implicit --no-ftps-resume-ssl --ftps-clear-data-connection --ftps-fallback-to-ftp ftps.example.com')
134
147
 
135
148
  ## Recursive Retrieval
136
149
  expect_command(host.wget(url,
137
150
  recursive: true,
138
- depth: 10,
151
+ level: 10,
139
152
  delete_after: true,
140
153
  convert_links: true,
141
154
  backup_converted: true,
@@ -146,10 +159,13 @@ RSpec.describe Kanrisuru::Core::Stat do
146
159
 
147
160
  ## Recursive Accept/Reject
148
161
  expect_command(host.wget(url,
149
- accept_list: ['.txt', '.html'],
150
- reject_list: ['.csv'],
151
- domain_list: ['example.com'],
152
- exclude_domain_list: ['hackernews.com'],
162
+ accept: ['.txt', '.html'],
163
+ reject: ['.csv'],
164
+ accept_regex: 'https://*',
165
+ regect_regex: 'ftp*',
166
+ regex_type: 'posix',
167
+ domains: ['example.com'],
168
+ exclude_domains: ['hackernews.com'],
153
169
  follow_tags: %w[a div span],
154
170
  ignore_tags: %w[area link],
155
171
  include_directories: ['/gems'],
@@ -159,6 +175,6 @@ RSpec.describe Kanrisuru::Core::Stat do
159
175
  span_hosts: true,
160
176
  relative: true,
161
177
  no_parent: true),
162
- "wget --accept .txt,.html --reject .csv --domains example.com --exclude-domains hackernews.com --follow-tags a,div,span --ignore-tags area,link --include-directories /gems --exclude-directories /releases --follow-ftp --ignore-case --span-hosts --relative --no-parent #{url}")
178
+ "wget --accept .txt,.html --reject .csv --accept-regex https://* --regex_type posix --domains example.com --exclude-domains hackernews.com --follow-tags a,div,span --ignore-tags area,link --include-directories /gems --exclude-directories /releases --follow-ftp --ignore-case --span-hosts --relative --no-parent #{url}")
163
179
  end
164
180
  end
@@ -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
- }.to raise_error(ArgumentError)
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
- }.to raise_error(ArgumentError)
213
+ end.to raise_error(ArgumentError)
214
214
  end
215
215
  end
@@ -50,6 +50,12 @@ RSpec.shared_examples 'system' do |os_name, host_json, _spec_dir|
50
50
  expect(result.days).to be >= 0
51
51
  end
52
52
 
53
+ it 'gets history' do
54
+ result = host.history
55
+ expect(result).to be_success
56
+ expect(result.data).to be_instance_of(Array)
57
+ end
58
+
53
59
  it 'kills pids' do
54
60
  command = 'sleep 100000 > /dev/null 2>&1 &'
55
61
 
@@ -108,6 +114,12 @@ RSpec.shared_examples 'system' do |os_name, host_json, _spec_dir|
108
114
  expect(result).to be_success
109
115
  end
110
116
 
117
+ it 'gets nproc count' do
118
+ result = host.nproc
119
+ expect(result).to be_success
120
+ expect(result.to_i).to be > 0
121
+ end
122
+
111
123
  it 'gets process details' do
112
124
  result = host.ps
113
125
 
@@ -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 eq(path)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.shared_examples 'cluster' do |os_name, host_json, spec_dir|
5
+ RSpec.shared_examples 'cluster' do |os_name, host_json, _spec_dir|
6
6
  context "with #{os_name}" do
7
7
  let(:host1) do
8
8
  Kanrisuru::Remote::Host.new(
@@ -25,11 +25,13 @@ RSpec.describe Kanrisuru::Core::System do
25
25
  expect(host).to respond_to(:lscpu)
26
26
  expect(host).to respond_to(:load_average)
27
27
  expect(host).to respond_to(:free)
28
+ expect(host).to respond_to(:history)
28
29
  expect(host).to respond_to(:ps)
29
30
  expect(host).to respond_to(:kill)
30
31
  expect(host).to respond_to(:kernel_statistics)
31
32
  expect(host).to respond_to(:kstat)
32
33
  expect(host).to respond_to(:lsof)
34
+ expect(host).to respond_to(:nproc)
33
35
  expect(host).to respond_to(:last)
34
36
  expect(host).to respond_to(:uptime)
35
37
  expect(host).to respond_to(:w)
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.15
4
+ version: 0.18.0
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-07 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -307,6 +307,7 @@ files:
307
307
  - lib/kanrisuru/core/system/commands.rb
308
308
  - lib/kanrisuru/core/system/commands/cpu_info.rb
309
309
  - lib/kanrisuru/core/system/commands/free.rb
310
+ - lib/kanrisuru/core/system/commands/history.rb
310
311
  - lib/kanrisuru/core/system/commands/kernel_statistics.rb
311
312
  - lib/kanrisuru/core/system/commands/kill.rb
312
313
  - lib/kanrisuru/core/system/commands/last.rb
@@ -314,12 +315,14 @@ files:
314
315
  - lib/kanrisuru/core/system/commands/load_env.rb
315
316
  - lib/kanrisuru/core/system/commands/lscpu.rb
316
317
  - lib/kanrisuru/core/system/commands/lsof.rb
318
+ - lib/kanrisuru/core/system/commands/nproc.rb
317
319
  - lib/kanrisuru/core/system/commands/poweroff.rb
318
320
  - lib/kanrisuru/core/system/commands/ps.rb
319
321
  - lib/kanrisuru/core/system/commands/reboot.rb
320
322
  - lib/kanrisuru/core/system/commands/uptime.rb
321
323
  - lib/kanrisuru/core/system/commands/w.rb
322
324
  - lib/kanrisuru/core/system/parser.rb
325
+ - lib/kanrisuru/core/system/parsers/history.rb
323
326
  - lib/kanrisuru/core/system/parsers/kernel_statistics.rb
324
327
  - lib/kanrisuru/core/system/parsers/last.rb
325
328
  - lib/kanrisuru/core/system/parsers/load_average.rb
@@ -706,7 +709,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
706
709
  - !ruby/object:Gem::Version
707
710
  version: '0'
708
711
  requirements: []
709
- rubygems_version: 3.2.32
712
+ rubygems_version: 3.3.5
710
713
  signing_key:
711
714
  specification_version: 4
712
715
  summary: Manage remote servers over ssh with ruby.