hotify 0.1.2 → 0.1.3

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: '08ce6906a3be6a5ff236a332d461d3895dcd1017273a21ad42b5b82c252c65c3'
4
- data.tar.gz: c6d49d34473f58493e16b2ca071fca490dca6e2653bce630cf6cdd14936b0c2c
3
+ metadata.gz: 87530c74880b1befe5ee22346c52ea9832dfa0784b1fbd6457f27b9f76428821
4
+ data.tar.gz: d72bc7a24db4601fdbf932b72f11417fb129a184cf59804c54c59696572f011c
5
5
  SHA512:
6
- metadata.gz: 3e1e7fea15496bd4ee4b06958ec0646881cca7ea5634753e2a1a9eaff8c490e03f4edcf5955835563197dad546f88cd860f68e6461c9c15f6467d8e624e18b99
7
- data.tar.gz: b106e7fe91069e3bba0d2fe2667f3bde32b958a96bcc9c34fcf24cd107cc7fb13b0d67835cb9cf84db8c8559c5ce8f56646addd3f4053ec44c43db31ea8e3f7f
6
+ metadata.gz: 40a61070bacaa148c9770257df5745a9fd56fa3ddfe12417a56eebcbe813ccd510ce68d5d80b9dfc8095417180d8ab402b0e69a8219aa9ea57e1f912a33fcbc7
7
+ data.tar.gz: '095275f5c1e02b7fbff2753c1aae5548e4f60b1d898d952dec90640f7f8f3efc68c7d7adcbb3553a435680a7e66a2f9ee8f8d0d61c7d2dc8d34b036895ab1c4e'
data/Gemfile CHANGED
@@ -13,4 +13,5 @@ group :development do
13
13
  end
14
14
 
15
15
  gem "onelogin"
16
- gem "thor"
16
+ gem "thor"
17
+ gem "parallel"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotify (0.1.2)
4
+ hotify (0.1.3)
5
5
  onelogin (~> 1.5.0)
6
+ parallel (~> 1.19.1)
6
7
  thor (~> 1.0.1)
7
8
 
8
9
  GEM
@@ -26,6 +27,7 @@ GEM
26
27
  onelogin (1.5.0)
27
28
  httparty (>= 0.13.7)
28
29
  nokogiri (>= 1.6.3.1)
30
+ parallel (1.19.1)
29
31
  pry (0.13.1)
30
32
  coderay (~> 1.1)
31
33
  method_source (~> 1.0)
@@ -53,6 +55,7 @@ DEPENDENCIES
53
55
  dotenv
54
56
  hotify!
55
57
  onelogin
58
+ parallel
56
59
  pry
57
60
  rake (~> 12.0)
58
61
  rspec (~> 3.0)
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "dotenv", "~> 2.7.5"
32
32
  spec.add_dependency "onelogin", "~> 1.5.0"
33
33
  spec.add_dependency "thor", "~> 1.0.1"
34
+ spec.add_dependency "parallel", "~> 1.19.1"
34
35
  end
@@ -1,5 +1,6 @@
1
1
  require "onelogin"
2
2
  require "thor"
3
+ require "parallel"
3
4
  require "hotify/version"
4
5
  require "hotify/cli"
5
6
  require "hotify/auth"
@@ -68,12 +69,14 @@ module Hotify
68
69
  role_user
69
70
  end
70
71
 
71
- def add_role(user, role)
72
- client.assign_role_to_user(user.id, [role.id])
72
+ def add_role(user_email, role_ids)
73
+ user = Hotify::Users.find_by(email: user_email)
74
+ client.assign_role_to_user(user.id, role_ids)
73
75
  end
74
76
 
75
- def leave_role(user, role)
76
- client.remove_role_from_user(user.id, [role.id])
77
+ def leave_role(user_email, role_ids)
78
+ user = Hotify::Users.find_by(email: user_email)
79
+ client.remove_role_from_user(user.id, role_ids)
77
80
  end
78
81
 
79
82
  def find_by_name(name)
@@ -28,48 +28,77 @@ module Hotify
28
28
 
29
29
  private
30
30
 
31
+ def hotify_role
32
+ @_hotify_role ||= Hotify::Role.new
33
+ end
34
+
35
+ def role_id_names
36
+ @_role_id_names ||= hotify_role.all_roles.map{ | role | { id: role.id, name: role.name} }
37
+ end
38
+
39
+ def role_id_by(name)
40
+ role_id_names.each do | role_id_name |
41
+ return role_id_name[:id] if role_id_name[:name] == name
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ def onelogin_role_in_user
48
+ @_onelogin_role_in_user ||= role_in_user_dump(hotify_role.role_in_user)
49
+ end
50
+
31
51
  def add_role_by_yaml(hotify_role_users_hash)
32
- hotify_role = Hotify::Role.new
33
- hotify_role_users_hash.each do | role_name, user_emails |
34
- user_emails.each do | user_email |
35
- user = Hotify::Users.find_by(email: user_email)
36
- onelogin_user_role_names = hotify_role.roles_from(user: user).map{ | user_role | user_role.name }
37
- unless onelogin_user_role_names.include?(role_name)
38
- add!(user, role_name)
52
+ users_and_roles_will_add = Hash.new { |h,k| h[k] = [] }
53
+ hotify_role_users_hash.each do | hotify_role_name, hotify_user_emails |
54
+ hotify_user_emails.each do | hotify_user_email |
55
+ unless onelogin_role_in_user[hotify_role_name].include?(hotify_user_email)
56
+ users_and_roles_will_add[hotify_user_email].push(hotify_role_name)
39
57
  end
40
58
  end
41
59
  end
60
+
61
+ add!(users_and_roles_will_add)
42
62
  end
43
63
 
44
64
  def remove_role_by_yaml(hotify_role_users_hash)
45
- hotify_role = Hotify::Role.new
46
- onelogin_roles = hotify_role.role_in_user
47
- onelogin_roles.each do | onelogin_role_name, onelogin_users |
48
- onelogin_users.each do | user |
49
- unless hotify_role_users_hash[onelogin_role_name].include?(user.email)
50
- remove!(user, onelogin_role_name)
65
+ users_and_roles_will_remove = Hash.new { |h,k| h[k] = [] }
66
+ hotify_role_users_hash.each do | hotify_role_name, hotify_user_emails |
67
+ onelogin_role_in_user[hotify_role_name].each do | onelogin_user_email |
68
+ unless hotify_user_emails.include?(onelogin_user_email)
69
+ users_and_roles_will_remove[onelogin_user_email].push(hotify_role_name)
51
70
  end
52
71
  end
53
72
  end
73
+
74
+ remove!(users_and_roles_will_remove)
54
75
  end
55
76
 
56
- def add!(user, role_name)
57
- hotify_role = Hotify::Role.new
58
- if options[:dry_run]
59
- puts "#{user.email} will add to #{role_name}"
60
- else
61
- hotify_role.add_role(user, hotify_role.find_by_name(role_name))
62
- puts "#{user.email} added to #{role_name}"
77
+ def add!(users_and_roles_will_add)
78
+ users_and_roles_will_add.each do |user_email, role_names|
79
+ if options[:dry_run]
80
+ puts "#{user_email} will add to:"
81
+ role_names.each { | role_name | puts role_name }
82
+ else
83
+ role_ids = role_names.map{ |role_name| role_id_by(role_name) }
84
+ hotify_role.add_role(user_email, role_ids)
85
+ puts "#{user_email} added to:"
86
+ role_names.each { | role_name | puts role_name }
87
+ end
63
88
  end
64
89
  end
65
90
 
66
- def remove!(user, role_name)
67
- hotify_role = Hotify::Role.new
68
- if options[:dry_run]
69
- puts "#{user.email} will remove by #{role_name}"
70
- else
71
- hotify_role.leave_role(user, hotify_role.find_by_name(role_name))
72
- puts "#{user.email} removed by #{role_name}"
91
+ def remove!(users_and_roles_will_remove)
92
+ users_and_roles_will_remove.each do |user_email, role_names|
93
+ if options[:dry_run]
94
+ puts "#{user_email} will remove by:"
95
+ role_names.each { | role_name | puts role_name }
96
+ else
97
+ role_ids = role_names.map{ |role_name| role_id_by(role_name) }
98
+ hotify_role.leave_role(user_email, role_ids)
99
+ puts "#{user_email} removed by:"
100
+ role_names.each { | role_name | puts role_name }
101
+ end
73
102
  end
74
103
  end
75
104
 
@@ -1,3 +1,3 @@
1
1
  module Hotify
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - j-o-lantern0422
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: parallel
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.19.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.19.1
83
97
  description: Onelogin role manage, example user add, or remove from role command
84
98
  email:
85
99
  - j.o.lantern0422@gmail.com