kanrisuru 0.7.2 → 0.8.2

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: 4ffb2183c8f1a5610dd416259a663787076f79cb8502fe8656a52d2c2cd1a7e0
4
- data.tar.gz: 43b63c2e14d7f29356cd110261ef1ba55aabd50e97830e4aea3770429625caf8
3
+ metadata.gz: ce41108c8201af2a48ac2453f8dc3fb993869e9264a8754d603a11d09ffe1cb5
4
+ data.tar.gz: 542d34622a949d0eb5ddddc1d7403f13e9e37dfb39cb88b589c7655a2a34a3e4
5
5
  SHA512:
6
- metadata.gz: c0b333f36fb00bd16177fe434522c2bd1717db0019d39dba681ab7810b786aca050e6ea79c2647a1bedf4f0bdb4d7e6ffb26079b2ad10d92d3b6da6e4372ee56
7
- data.tar.gz: 17377294cc356a44b1a76c6d32bae36940d8ec43d31cdbf0716c4d347735a8d30591e94a8babc8f7cd70d68127f7177d6a2dd70015c4eb8132148868e47a227d
6
+ metadata.gz: 7aea2688091ff8449f21eb11cd2fdcb51d71563538fd9c9e38a484770adb8745663a3132314b0001d9e6206dbd57533fe2626af1c59e2ada6d0ea394e2fdd113
7
+ data.tar.gz: 054a8612edecb94b79bd6b7488096ae12d4fee790d17cf295d4a04f397282ae2c9f5e4a977a37145bd4fc37bf0896a2a9bbd43098762ff65496de29804aa6a0b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## Kanrisuru 0.8.2 (August 19, 2021) ##
2
+ * Convert `major` and `minor` device field values to an `integer` in lsblk system module.
3
+
4
+ ## Kanrisuru 0.8.1 (August 19, 2021) ##
5
+ * Fix `nodeps` flag value for `lsblk` command in disk module.
6
+
7
+ ## Kanrisuru 0.8.0 (August 18, 2021) ##
8
+ * Add last / lastb implementation in system core module.
9
+
10
+ ## Kanrisuru 0.7.3 (August 9, 2021) ##
11
+ * Fixed bug with zypper remove package, where the package names weren't being added to the linux command.
12
+ * Test case added to ensure package is removed.
13
+
1
14
  ## Kanrisuru 0.7.2 (August 9, 2021) ##
2
15
  * Fixed bug with the `os_method_cache` instance variable set in the namespaced instance of a host. This was causing collision issues inbetween host instances, where, hosts with the same aliased method name was getting overwritten (with a different OS), since the namespace instance variable existing on the host class definition wasn't getting reset inbetween host instantiations. Given that the `os_method_cache` is normally re-instantiated, this bug fix addresses this so that the `os_method_cache` is always defined on the host instance, ie:
3
16
 
@@ -144,7 +144,7 @@ module Kanrisuru
144
144
 
145
145
  command.append_flag('-a', all)
146
146
  command.append_flag('-p', paths)
147
- command.append_flag('-p', nodeps)
147
+ command.append_flag('-d', nodeps)
148
148
 
149
149
  command.append_arg('-o', 'NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
150
150
  execute(command)
@@ -244,8 +244,8 @@ module Kanrisuru
244
244
  current_device.fs_type = value
245
245
  when 'MAJ:MIN'
246
246
  maj, min = value.split(':')
247
- current_device.maj_dev = maj
248
- current_device.min_dev = min
247
+ current_device.maj_dev = maj ? maj.to_i : nil
248
+ current_device.min_dev = min ? min.to_i : nil
249
249
  when 'MOUNTPOINT'
250
250
  current_device.mount_point = value
251
251
  when 'SIZE'
@@ -281,8 +281,8 @@ module Kanrisuru
281
281
 
282
282
  LsblkDevice.new(
283
283
  device['name'],
284
- maj_min ? maj_min.split(':')[0] : nil,
285
- maj_min ? maj_min.split(':')[1] : nil,
284
+ maj_min ? maj_min.split(':')[0].to_i : nil,
285
+ maj_min ? maj_min.split(':')[1].to_i : nil,
286
286
  device['rm'],
287
287
  device['ro'],
288
288
  device['owner'],
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
+ require 'ipaddr'
4
5
 
5
6
  module Kanrisuru
6
7
  module Core
@@ -19,6 +20,7 @@ module Kanrisuru
19
20
  os_define :linux, :kstat
20
21
 
21
22
  os_define :linux, :lsof
23
+ os_define :linux, :last
22
24
 
23
25
  os_define :linux, :uptime
24
26
 
@@ -116,6 +118,19 @@ module Kanrisuru
116
118
  :name
117
119
  )
118
120
 
121
+ SessionDetail = Struct.new(
122
+ :tty,
123
+ :login_at,
124
+ :logout_at,
125
+ :ip_address,
126
+ :success
127
+ )
128
+
129
+ LoginUser = Struct.new(
130
+ :user,
131
+ :sessions
132
+ )
133
+
119
134
  def load_env
120
135
  command = Kanrisuru::Command.new('env')
121
136
  execute_shell(command)
@@ -271,6 +286,65 @@ module Kanrisuru
271
286
  Kanrisuru::Result.new(command, &:to_i)
272
287
  end
273
288
 
289
+ def last(opts = {})
290
+ command =
291
+ if opts[:failed_attempts]
292
+ Kanrisuru::Command.new('lastb')
293
+ else
294
+ Kanrisuru::Command.new('last')
295
+ end
296
+
297
+ command.append_flag('-i')
298
+ command.append_flag('-F')
299
+ command.append_arg('-f', opts[:file])
300
+
301
+ ## Some systems only use 1 space between user and TTY field
302
+ ## Add an additional space in output formatting for simple parsing
303
+ ## logic.
304
+ command | "sed 's/ / /'"
305
+
306
+ execute_shell(command)
307
+
308
+ Kanrisuru::Result.new(command) do |cmd|
309
+ lines = cmd.to_a
310
+
311
+ mapping = {}
312
+
313
+ lines.each do |line|
314
+ next if Kanrisuru::Util.blank?(line)
315
+ next if line.include?('wtmp') || line.include?('btmp')
316
+
317
+ line = line.gsub(' still logged in', '- still logged in') if line.include?('still logged in')
318
+
319
+ values = line.split(/\s{2,}/, 4)
320
+ user = values[0]
321
+ tty = values[1]
322
+ ip = IPAddr.new(values[2])
323
+
324
+ date_range = values[3]
325
+ login, logout = date_range.split(' - ')
326
+
327
+ login = parse_last_date(login) if login
328
+
329
+ logout = parse_last_date(logout) if logout
330
+
331
+ detail = SessionDetail.new
332
+ detail.tty = tty
333
+ detail.ip_address = ip
334
+ detail.login_at = login
335
+ detail.logout_at = logout
336
+
337
+ detail.success = !Kanrisuru::Util.present?(opts[:failed_attemps])
338
+
339
+ mapping[user] = LoginUser.new(user, []) unless mapping.key?(user)
340
+
341
+ mapping[user].sessions << detail
342
+ end
343
+
344
+ mapping.values
345
+ end
346
+ end
347
+
274
348
  def ps(opts = {})
275
349
  group = opts[:group]
276
350
  user = opts[:user]
@@ -567,6 +641,19 @@ module Kanrisuru
567
641
  line.split(char, 2)[1]
568
642
  end
569
643
 
644
+ def parse_last_date(string)
645
+ tokens = string.split
646
+
647
+ return if tokens.length < 4
648
+
649
+ month_abbr = tokens[1]
650
+ day = tokens[2]
651
+ timestamp = tokens[3]
652
+ year = tokens[4]
653
+
654
+ DateTime.parse("#{day} #{month_abbr} #{year} #{timestamp}")
655
+ end
656
+
570
657
  def parse_policy_abbr(value)
571
658
  case value
572
659
  when '-'
@@ -714,6 +714,9 @@ module Kanrisuru
714
714
  zypper_package_type_opt(command, opts)
715
715
  zypper_solver_opts(command, opts)
716
716
 
717
+ packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
718
+ command << packages
719
+
717
720
  execute_shell(command)
718
721
  Kanrisuru::Result.new(command)
719
722
  end
@@ -159,7 +159,6 @@ module Kanrisuru
159
159
  os_method_names.each do |method_name|
160
160
  if namespace
161
161
  namespace_class.class_eval do
162
-
163
162
  define_method method_name do |*args, &block|
164
163
  unbound_method = nil
165
164
 
@@ -193,7 +192,7 @@ module Kanrisuru
193
192
  else
194
193
  define_method method_name do |*args, &block|
195
194
  unbound_method = nil
196
-
195
+
197
196
  host = self
198
197
  os_method_cache = host.instance_variable_get(:@os_method_cache) || {}
199
198
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.7.2'
4
+ VERSION = '0.8.2'
5
5
  end
@@ -96,6 +96,21 @@ RSpec.describe Kanrisuru::Core::System do
96
96
  expect(result.cpus.length).to eq(host.cpu.cores)
97
97
  end
98
98
 
99
+ it 'gets login details' do
100
+ host.su('root')
101
+
102
+ result = host.last
103
+ expect(result).to be_success
104
+ end
105
+
106
+ it 'gets failed login attempts' do
107
+ host.su('root')
108
+
109
+ result = host.last(failed_attempts: true)
110
+ puts result.data
111
+ expect(result).to be_success
112
+ end
113
+
99
114
  it 'gets process details' do
100
115
  result = host.ps
101
116
 
@@ -40,6 +40,12 @@ RSpec.describe Kanrisuru::Core::Zypper do
40
40
  expect(result).to be_success
41
41
  end
42
42
 
43
+ it 'removes a package' do
44
+ host.su('root')
45
+ result = host.zypper('remove', packages: ['ffmpeg'])
46
+ expect(result).to be_success
47
+ end
48
+
43
49
  it 'lists updates' do
44
50
  result = host.zypper('list-updates')
45
51
  expect(result).to be_success
@@ -162,10 +162,10 @@ RSpec.describe Kanrisuru::OsPackage do
162
162
 
163
163
  expect(cluster).to respond_to(:output)
164
164
  expect(cluster.output).to eq([
165
- {:host=>"ubuntu-host", :result=>"debian"},
166
- {:host=>"centos-host", :result=>"fedora"},
167
- {:host=>"opensuse-host", :result=>"sles"}
168
- ])
165
+ { host: 'ubuntu-host', result: 'debian' },
166
+ { host: 'centos-host', result: 'fedora' },
167
+ { host: 'opensuse-host', result: 'sles' }
168
+ ])
169
169
 
170
170
  expect(host1).to respond_to(:alias)
171
171
  expect(host2).to respond_to(:alias)
@@ -180,10 +180,10 @@ RSpec.describe Kanrisuru::OsPackage do
180
180
  expect(cluster).to respond_to(:alias)
181
181
  expect(cluster.alias).to respond_to(:output)
182
182
  expect(cluster.alias.output).to eq([
183
- {:host=>"ubuntu-host", :result=>"debian"},
184
- {:host=>"centos-host", :result=>"fedora"},
185
- {:host=>"opensuse-host", :result=>"sles"}
186
- ])
183
+ { host: 'ubuntu-host', result: 'debian' },
184
+ { host: 'centos-host', result: 'fedora' },
185
+ { host: 'opensuse-host', result: 'sles' }
186
+ ])
187
187
 
188
188
  host1.disconnect
189
189
  host2.disconnect
@@ -86,5 +86,17 @@ RSpec.describe Kanrisuru::Core::System do
86
86
  :inode,
87
87
  :name
88
88
  )
89
+ expect(Kanrisuru::Core::System::SessionDetail.new).to respond_to(
90
+ :tty,
91
+ :login_at,
92
+ :logout_at,
93
+ :ip_address,
94
+ :success
95
+ )
96
+
97
+ expect(Kanrisuru::Core::System::LoginUser.new).to respond_to(
98
+ :user,
99
+ :sessions
100
+ )
89
101
  end
90
102
  end
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.7.2
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec