hotify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +27 -0
- data/bin/setup +8 -0
- data/exe/hotify +5 -0
- data/hotify.gemspec +29 -0
- data/lib/hotify/auth.rb +15 -0
- data/lib/hotify/cli.rb +88 -0
- data/lib/hotify/user.rb +34 -0
- data/lib/hotify/version.rb +3 -0
- data/lib/hotify.rb +80 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff2eb5f3bb59a332b46851525b6503138802fa78181fa6153eea3640d7526b75
|
4
|
+
data.tar.gz: 6351a62df8491ba2e99df50e2ea278885f26d991eb570baf6e43b1fc06325bcf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c2a5d3b0e4f9a9b79f9e33fbc789f8e6d2af90f7f7f6ac5bfd5efd5dfe1d12a60b683d350abc8ab2494dd02242955fe9d23bbc3ffa309556e16171631ca96f5
|
7
|
+
data.tar.gz: cfe138ba8b69377087230b4caa0cd7a1294435d29d0c0685aa38d2c71e1318a575bb08f7036d5d3cac9545b5a97b55f31e72f34dc361d718620a6bd4eb70535a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in onelogin-role.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 12.0"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "byebug"
|
11
|
+
gem "pry"
|
12
|
+
gem "dotenv"
|
13
|
+
end
|
14
|
+
|
15
|
+
gem "onelogin"
|
16
|
+
gem "thor"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hotify (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.1.3)
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
dotenv (2.7.5)
|
13
|
+
httparty (0.18.0)
|
14
|
+
mime-types (~> 3.0)
|
15
|
+
multi_xml (>= 0.5.2)
|
16
|
+
method_source (1.0.0)
|
17
|
+
mime-types (3.3.1)
|
18
|
+
mime-types-data (~> 3.2015)
|
19
|
+
mime-types-data (3.2020.0512)
|
20
|
+
mini_portile2 (2.4.0)
|
21
|
+
multi_xml (0.6.0)
|
22
|
+
nokogiri (1.10.9)
|
23
|
+
mini_portile2 (~> 2.4.0)
|
24
|
+
onelogin (1.5.0)
|
25
|
+
httparty (>= 0.13.7)
|
26
|
+
nokogiri (>= 1.6.3.1)
|
27
|
+
pry (0.13.1)
|
28
|
+
coderay (~> 1.1)
|
29
|
+
method_source (~> 1.0)
|
30
|
+
rake (12.3.3)
|
31
|
+
rspec (3.9.0)
|
32
|
+
rspec-core (~> 3.9.0)
|
33
|
+
rspec-expectations (~> 3.9.0)
|
34
|
+
rspec-mocks (~> 3.9.0)
|
35
|
+
rspec-core (3.9.2)
|
36
|
+
rspec-support (~> 3.9.3)
|
37
|
+
rspec-expectations (3.9.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-mocks (3.9.1)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-support (3.9.3)
|
44
|
+
thor (1.0.1)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
byebug
|
51
|
+
dotenv
|
52
|
+
hotify!
|
53
|
+
onelogin
|
54
|
+
pry
|
55
|
+
rake (~> 12.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
thor
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 nishihata
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# hotify
|
2
|
+
|
3
|
+
Onelogin role management with yaml tool.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'hotify'
|
11
|
+
```
|
12
|
+
|
13
|
+
or install
|
14
|
+
|
15
|
+
```sh
|
16
|
+
gem install hotify
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Dump role and users
|
22
|
+
|
23
|
+
```sh
|
24
|
+
hotify dump
|
25
|
+
```
|
26
|
+
|
27
|
+
or
|
28
|
+
|
29
|
+
```sh
|
30
|
+
hotify dump ~/role_and_users.yml
|
31
|
+
```
|
32
|
+
|
33
|
+
### Apply role and users
|
34
|
+
|
35
|
+
```sh
|
36
|
+
hotify apply role_and_users.yml
|
37
|
+
```
|
38
|
+
|
39
|
+
If you want to execute dry-run
|
40
|
+
|
41
|
+
```sh
|
42
|
+
hotify apply role_and_users.yml --dry-run
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/j-o-lantern0422/hotify
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "onelogin/role"
|
5
|
+
require "onelogin"
|
6
|
+
require "thor"
|
7
|
+
require "onelogin/role/version"
|
8
|
+
require "onelogin/role/cli"
|
9
|
+
require "onelogin/role/auth"
|
10
|
+
require "onelogin/role/user"
|
11
|
+
|
12
|
+
|
13
|
+
if ENV["ENV"] == "development"
|
14
|
+
require "dotenv"
|
15
|
+
require "byebug"
|
16
|
+
require "pry"
|
17
|
+
Dotenv.load
|
18
|
+
end
|
19
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
20
|
+
# with your gem easier. You can also use a different console, if you like.
|
21
|
+
|
22
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
23
|
+
# require "pry"
|
24
|
+
# Pry.start
|
25
|
+
|
26
|
+
require "irb"
|
27
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/hotify
ADDED
data/hotify.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/hotify/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "hotify"
|
5
|
+
spec.version = Hotify::VERSION
|
6
|
+
spec.authors = ["j-o-lantern0422"]
|
7
|
+
spec.email = ["j.o.lantern0422@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Onelogin role and users mange with yaml}
|
10
|
+
spec.description = %q{Onelogin role manage, example user add, or remove from role command}
|
11
|
+
spec.homepage = "https://github.com/j-o-lantern0422/hotify"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/j-o-lantern0422/hotify"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/j-o-lantern0422/hotify"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
data/lib/hotify/auth.rb
ADDED
data/lib/hotify/cli.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Hotify
|
2
|
+
class Cli < Thor
|
3
|
+
class_option :dry_run, :type => :boolean, :default => false
|
4
|
+
|
5
|
+
desc "dump", "onelogin-role"
|
6
|
+
def dump
|
7
|
+
Hotify::Role.new.dump_role
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "dump [Path]", "yaml output"
|
11
|
+
method_options path: :string
|
12
|
+
def dump(path)
|
13
|
+
if path.nil?
|
14
|
+
path = "#{Dir.pwd}/roles_users.yml"
|
15
|
+
end
|
16
|
+
role = Hotify::Role.new
|
17
|
+
|
18
|
+
YAML.dump(role_in_user_dump(role.role_in_user), File.open(path, "w"))
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "apply [Path]", "apply user and role"
|
22
|
+
method_options path: :string
|
23
|
+
def apply(path)
|
24
|
+
role_file = YAML.load_file(path)
|
25
|
+
add_role_by_yaml(role_file)
|
26
|
+
remove_role_by_yaml(role_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
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)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
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)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
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}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
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}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def role_in_user_dump(role_in_user)
|
77
|
+
dump = Hash.new { |h,k| h[k] = [] }
|
78
|
+
role_in_user.each do | role_name, users |
|
79
|
+
users.each do | user |
|
80
|
+
dump[role_name].push(user.email)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
dump
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/hotify/user.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Hotify
|
2
|
+
class Users
|
3
|
+
def initialize
|
4
|
+
@client = Hotify::Auth.new.client
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.find_by(email:)
|
8
|
+
users = user_filter_by(email: email)
|
9
|
+
if users.size > 1
|
10
|
+
raise("Found Multiple User Entry")
|
11
|
+
elsif users.empty?
|
12
|
+
raise("User Not Found")
|
13
|
+
end
|
14
|
+
|
15
|
+
users.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def all_users
|
19
|
+
@client.get_users
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.user_filter_by(email:)
|
25
|
+
query_parameters = {
|
26
|
+
email: email
|
27
|
+
}
|
28
|
+
users_filtered = Hotify::Auth.new.client.get_users(query_parameters)
|
29
|
+
users = users_filtered.map{ |user| user }
|
30
|
+
|
31
|
+
users
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/hotify.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "onelogin"
|
2
|
+
require "thor"
|
3
|
+
require "hotify/version"
|
4
|
+
require "hotify/cli"
|
5
|
+
require "hotify/auth"
|
6
|
+
require "hotify/user"
|
7
|
+
|
8
|
+
if ENV["ENV"] == "development"
|
9
|
+
require "dotenv"
|
10
|
+
require "byebug"
|
11
|
+
require "pry"
|
12
|
+
Dotenv.load(".development.env")
|
13
|
+
end
|
14
|
+
|
15
|
+
module Hotify
|
16
|
+
class Error < StandardError; end
|
17
|
+
class Role
|
18
|
+
def initialize
|
19
|
+
@client = Hotify::Auth.new.client
|
20
|
+
end
|
21
|
+
|
22
|
+
def dump_role
|
23
|
+
@client.get_roles.to_a.each{ |role| p role }
|
24
|
+
end
|
25
|
+
|
26
|
+
def roles_from(user: )
|
27
|
+
role_ids = @client.get_user_roles(user.id)
|
28
|
+
role_ids.map do | role_id |
|
29
|
+
@client.get_role(role_id)
|
30
|
+
end
|
31
|
+
end
|
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
|
38
|
+
|
39
|
+
all_users_and_roles
|
40
|
+
end
|
41
|
+
|
42
|
+
def role_in_user
|
43
|
+
all_users_and_roles = dump_all_users_and_roles
|
44
|
+
all_roles = @client.get_roles.to_a
|
45
|
+
role_user = Hash.new { |h,k| h[k] = [] }
|
46
|
+
|
47
|
+
|
48
|
+
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])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
role_user.each do | role_name , users |
|
57
|
+
users.uniq!
|
58
|
+
end
|
59
|
+
|
60
|
+
role_user
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_role(user, role)
|
64
|
+
@client.assign_role_to_user(user.id, [role.id])
|
65
|
+
end
|
66
|
+
|
67
|
+
def leave_role(user, role)
|
68
|
+
@client.remove_role_from_user(user.id, [role.id])
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_by_name(name)
|
72
|
+
name = "?name=#{name}"
|
73
|
+
@client.get_role(name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_by(id)
|
77
|
+
@client.get_role(id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hotify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- j-o-lantern0422
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Onelogin role manage, example user add, or remove from role command
|
14
|
+
email:
|
15
|
+
- j.o.lantern0422@gmail.com
|
16
|
+
executables:
|
17
|
+
- hotify
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".travis.yml"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- exe/hotify
|
32
|
+
- hotify.gemspec
|
33
|
+
- lib/hotify.rb
|
34
|
+
- lib/hotify/auth.rb
|
35
|
+
- lib/hotify/cli.rb
|
36
|
+
- lib/hotify/user.rb
|
37
|
+
- lib/hotify/version.rb
|
38
|
+
homepage: https://github.com/j-o-lantern0422/hotify
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
allowed_push_host: https://rubygems.org
|
43
|
+
homepage_uri: https://github.com/j-o-lantern0422/hotify
|
44
|
+
source_code_uri: https://github.com/j-o-lantern0422/hotify
|
45
|
+
changelog_uri: https://github.com/j-o-lantern0422/hotify
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Onelogin role and users mange with yaml
|
65
|
+
test_files: []
|