kanrisuru 0.16.13 → 0.16.14

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: 247c662cf0cedccfd41d702e372cc536958fbfd16c583643201e13e528c3c049
4
- data.tar.gz: 8d6256b6b5dfcf84793851432e0dfedfd352222bebb04bc530bb15bc9cdcd0d5
3
+ metadata.gz: d8db62531b521e5f8606ed7bb2520100d2f2f1fe20d78c1c8ae43759926e44ee
4
+ data.tar.gz: d3372a41fe3058ffaf938ce8ca31e7458f71fe981b380ac14143c46f2be9692b
5
5
  SHA512:
6
- metadata.gz: 31bde2ec4894d4e6962ff99b438b67502687446918d59180693d11275e25944c1af1e22ad923e799c4208e7fff62ad93e9867082765b956d213b12eb5a950092
7
- data.tar.gz: b69992182e95c7f3cf3061cd4f25d875ff6095ee7e18580a39f24a6be8c6978401d9023e55be01bbb0aac92b74ec904a016abdf60a4302c9fc1cfdd32df276b2
6
+ metadata.gz: 8bfafcc5e78e8545a1a2c6565bdbd9f5e581186c40b97696c1c4cd5b80426b03306f98a400db289293e86f4b919ee1b9cad622323c03b63264344a73c555f777
7
+ data.tar.gz: a1166a9650b3f3fe95a270abfa4950afb2b36fa3acde33ad4ed237944a44eddef6c4cc1d85352b87c0f672aed69d50dd60801295127c88ffc8b56a3ebd3e35e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## Kanrisuru 0.16.14 (January 02, 2022) ##
2
+ * Fix `get_user` command by parsing output to get user name if uid is passed in.
3
+
1
4
  ## Kanrisuru 0.16.13 (January 01, 2022) ##
2
5
  * Add `non_unique` and `system` opts to `create_group` command
3
6
 
@@ -8,11 +8,15 @@ module Kanrisuru
8
8
  execute_shell(command)
9
9
 
10
10
  Kanrisuru::Result.new(command) do |cmd|
11
- ## Get user id
12
- result = get_uid(user)
13
- break if result.failure?
14
-
15
- uid = result.to_i
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
+ uid = result.to_i
19
+ end
16
20
 
17
21
  ## Get all groups for the user, with gid and group name
18
22
  array = Parser::Groups.parse(cmd)
@@ -24,12 +28,12 @@ module Kanrisuru
24
28
  end
25
29
 
26
30
  ## Get home / shell path information
27
- cmd = Kanrisuru::Command.new("getent passwd #{user}")
28
- cmd | "awk -F: '{print $6, $7}'"
31
+ command2 = Kanrisuru::Command.new("getent passwd #{user}")
32
+ command2 | "awk -F: '{print $6, $7}'"
29
33
 
30
- execute(cmd)
34
+ execute(command2)
31
35
 
32
- result = Kanrisuru::Result.new(cmd) do |cmd2|
36
+ result = Kanrisuru::Result.new(command2) do |cmd2|
33
37
  Parser::Getent.parse(cmd2)
34
38
  end
35
39
 
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'parsers/getent'
4
4
  require_relative 'parsers/groups'
5
+ require_relative 'parsers/user'
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.16.13'
4
+ VERSION = '0.16.14'
5
5
  end
@@ -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.13
4
+ version: 0.16.14
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-01 00:00:00.000000000 Z
11
+ date: 2022-01-02 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