hotify 0.1.1 → 0.1.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: 07d43ef4a51523168ebf460a44da52b551af4c1c5f482d31b23bdecc02be9259
4
- data.tar.gz: 71fb287342aea6fb116a8edad06a79c73430d6b08bdb8cc2fc444c90e4509735
3
+ metadata.gz: '08ce6906a3be6a5ff236a332d461d3895dcd1017273a21ad42b5b82c252c65c3'
4
+ data.tar.gz: c6d49d34473f58493e16b2ca071fca490dca6e2653bce630cf6cdd14936b0c2c
5
5
  SHA512:
6
- metadata.gz: d7525191394ff12a09a1dd3843b8a13f881534065ee429ca0c010b21a55d55226d1582edd6b8e86a6b2dde98f46553de6515993848171bfeb1467fdbb4b82b9d
7
- data.tar.gz: ee1dbb55f0cf6140ec7944e23588fb78225dd72bb3ca907af2ba09e15dcc41381eb25790f93ec57a810af79d508b79ab3bf05a205d8f2f129f5b22c6a6421968
6
+ metadata.gz: 3e1e7fea15496bd4ee4b06958ec0646881cca7ea5634753e2a1a9eaff8c490e03f4edcf5955835563197dad546f88cd860f68e6461c9c15f6467d8e624e18b99
7
+ data.tar.gz: b106e7fe91069e3bba0d2fe2667f3bde32b958a96bcc9c34fcf24cd107cc7fb13b0d67835cb9cf84db8c8559c5ce8f56646addd3f4053ec44c43db31ea8e3f7f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotify (0.1.1)
4
+ hotify (0.1.2)
5
5
  onelogin (~> 1.5.0)
6
6
  thor (~> 1.0.1)
7
7
 
data/README.md CHANGED
@@ -18,6 +18,13 @@ gem install hotify
18
18
 
19
19
  ## Usage
20
20
 
21
+ Reading onelogin credentials from environment variables. So set the environment variable by using the command below.
22
+
23
+ ```sh
24
+ export ONELOGIN_ID=hoge
25
+ export ONELOGIN_SECRET=foo
26
+ ```
27
+
21
28
  ### Dump role and users
22
29
 
23
30
  ```sh
@@ -15,40 +15,48 @@ end
15
15
  module Hotify
16
16
  class Error < StandardError; end
17
17
  class Role
18
- def initialize
19
- @client = Hotify::Auth.new.client
18
+ def dump_role
19
+ client.get_roles.to_a.each{ |role| p role }
20
20
  end
21
21
 
22
- def dump_role
23
- @client.get_roles.to_a.each{ |role| p role }
22
+ def all_roles
23
+ @_all_roles ||= client.get_roles.to_a
24
24
  end
25
25
 
26
26
  def roles_from(user: )
27
- role_ids = @client.get_user_roles(user.id)
27
+ role_ids = client.get_user_roles(user.id)
28
28
  role_ids.map do | role_id |
29
- @client.get_role(role_id)
29
+ client.get_role(role_id)
30
30
  end
31
31
  end
32
32
 
33
- def dump_all_users_and_roles
34
- users = Hotify::Users.new
35
- all_users_and_roles = users.all_users.map do | user |
36
- { user: user, roles: roles_from(user: user) }
37
- end
33
+ def role_ids_from(user: )
34
+ client.get_user_roles(user.id)
35
+ end
38
36
 
39
- all_users_and_roles
37
+ def users
38
+ @_users ||= Hotify::Users.new
39
+ end
40
+
41
+ def all_users
42
+ @_all_users ||= users.all_users
43
+ end
44
+
45
+ def all_users_and_roles
46
+ @_all_users_and_roles ||= all_users.map do | user |
47
+ { user: user, role_ids: role_ids_from(user: user) }
48
+ end
40
49
  end
41
50
 
42
51
  def role_in_user
43
- all_users_and_roles = dump_all_users_and_roles
44
- all_roles = @client.get_roles.to_a
45
52
  role_user = Hash.new { |h,k| h[k] = [] }
46
53
 
47
-
48
54
  all_roles.each do | role |
49
- all_users_and_roles.each do | user_and_roles |
50
- user_and_roles[:roles].each do | role |
51
- role_user[role.name].push(user_and_roles[:user])
55
+ all_users_and_roles.each do | user_and_role_ids |
56
+ user_and_role_ids[:role_ids].each do | role_id |
57
+ if role.id == role_id
58
+ role_user[role.name].push(user_and_role_ids[:user])
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -61,20 +69,26 @@ module Hotify
61
69
  end
62
70
 
63
71
  def add_role(user, role)
64
- @client.assign_role_to_user(user.id, [role.id])
72
+ client.assign_role_to_user(user.id, [role.id])
65
73
  end
66
74
 
67
75
  def leave_role(user, role)
68
- @client.remove_role_from_user(user.id, [role.id])
76
+ client.remove_role_from_user(user.id, [role.id])
69
77
  end
70
78
 
71
79
  def find_by_name(name)
72
80
  name = "?name=#{name}"
73
- @client.get_role(name)
81
+ client.get_role(name)
74
82
  end
75
83
 
76
84
  def find_by(id)
77
- @client.get_role(id)
85
+ client.get_role(id)
86
+ end
87
+
88
+ private
89
+
90
+ def client
91
+ @_client ||= Hotify::Auth.new.client
78
92
  end
79
93
  end
80
94
  end
@@ -1,9 +1,5 @@
1
1
  module Hotify
2
2
  class Users
3
- def initialize
4
- @client = Hotify::Auth.new.client
5
- end
6
-
7
3
  def self.find_by(email:)
8
4
  users = user_filter_by(email: email)
9
5
  if users.size > 1
@@ -16,7 +12,7 @@ module Hotify
16
12
  end
17
13
 
18
14
  def all_users
19
- @client.get_users
15
+ client.get_users
20
16
  end
21
17
 
22
18
  private
@@ -30,5 +26,9 @@ module Hotify
30
26
 
31
27
  users
32
28
  end
29
+
30
+ def client
31
+ @_client ||= Hotify::Auth.new.client
32
+ end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Hotify
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - j-o-lantern0422
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug