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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/lib/hotify.rb +36 -22
- data/lib/hotify/user.rb +5 -5
- data/lib/hotify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08ce6906a3be6a5ff236a332d461d3895dcd1017273a21ad42b5b82c252c65c3'
|
4
|
+
data.tar.gz: c6d49d34473f58493e16b2ca071fca490dca6e2653bce630cf6cdd14936b0c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1e7fea15496bd4ee4b06958ec0646881cca7ea5634753e2a1a9eaff8c490e03f4edcf5955835563197dad546f88cd860f68e6461c9c15f6467d8e624e18b99
|
7
|
+
data.tar.gz: b106e7fe91069e3bba0d2fe2667f3bde32b958a96bcc9c34fcf24cd107cc7fb13b0d67835cb9cf84db8c8559c5ce8f56646addd3f4053ec44c43db31ea8e3f7f
|
data/Gemfile.lock
CHANGED
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
|
data/lib/hotify.rb
CHANGED
@@ -15,40 +15,48 @@ end
|
|
15
15
|
module Hotify
|
16
16
|
class Error < StandardError; end
|
17
17
|
class Role
|
18
|
-
def
|
19
|
-
|
18
|
+
def dump_role
|
19
|
+
client.get_roles.to_a.each{ |role| p role }
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@client.get_roles.to_a
|
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 =
|
27
|
+
role_ids = client.get_user_roles(user.id)
|
28
28
|
role_ids.map do | role_id |
|
29
|
-
|
29
|
+
client.get_role(role_id)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
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
|
-
|
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 |
|
50
|
-
|
51
|
-
|
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
|
-
|
72
|
+
client.assign_role_to_user(user.id, [role.id])
|
65
73
|
end
|
66
74
|
|
67
75
|
def leave_role(user, role)
|
68
|
-
|
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
|
-
|
81
|
+
client.get_role(name)
|
74
82
|
end
|
75
83
|
|
76
84
|
def find_by(id)
|
77
|
-
|
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
|
data/lib/hotify/user.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/hotify/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|