moura 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +75 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/Rakefile +12 -0
- data/exe/moura +11 -0
- data/lib/moura/cli.rb +30 -0
- data/lib/moura/model/diff.rb +85 -0
- data/lib/moura/model/local.rb +22 -0
- data/lib/moura/model/remote.rb +111 -0
- data/lib/moura/model.rb +8 -0
- data/lib/moura/onelogin.rb +18 -0
- data/lib/moura/version.rb +5 -0
- data/lib/moura/view/diff.rb +44 -0
- data/lib/moura/view.rb +8 -0
- data/lib/moura.rb +36 -0
- data/lib/onelogin/api.rb +32 -0
- data/moura.gemspec +36 -0
- data/sig/moura.rbs +4 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d418b2f6e7cf1b072b58c6c5127d6af31646b39d42da97b01d6e1f2140fb072c
|
4
|
+
data.tar.gz: 80f27d606099843d803894fdb3c64e20a14c8d4ebf317b4b3091c2573babfcdb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e965bdb4db281323f01a64fb443b54361041e9f8e8daa5380969dc140a248c452d3b58ea29f00575cde6efeb0a85638dd9571a00502db206b121e50c140806a1
|
7
|
+
data.tar.gz: 30fa656e1bbb60c74aa6d9a7de3490eb56f48ed9c245bbb468a2bd461e8cf2ba17a91c1f317db2ac11eb575343e82e5ac3cb61408ad689061177772452e8fe44
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.2
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/FrozenStringLiteralComment:
|
13
|
+
Exclude:
|
14
|
+
- exe/moura
|
15
|
+
|
16
|
+
Style/StringLiterals:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: double_quotes
|
19
|
+
|
20
|
+
Style/StringLiteralsInInterpolation:
|
21
|
+
Enabled: true
|
22
|
+
EnforcedStyle: double_quotes
|
23
|
+
|
24
|
+
Layout/LineLength:
|
25
|
+
Max: 120
|
26
|
+
|
27
|
+
Metrics/AbcSize:
|
28
|
+
Max: 26
|
29
|
+
|
30
|
+
Metrics/CyclomaticComplexity:
|
31
|
+
Max: 10
|
32
|
+
|
33
|
+
Metrics/MethodLength:
|
34
|
+
Max: 25
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in moura.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
gem "rubocop", "~> 1.21"
|
12
|
+
gem "rubocop-rake"
|
13
|
+
gem "rubocop-rspec"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
moura (0.2.0)
|
5
|
+
hashdiff (~> 1.0.1)
|
6
|
+
onelogin (~> 3.0.0.pre.alpha.1)
|
7
|
+
thor (~> 1.2, >= 1.2.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
ast (2.4.2)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
ethon (0.16.0)
|
15
|
+
ffi (>= 1.15.0)
|
16
|
+
ffi (1.15.5)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
json (2.6.3)
|
19
|
+
onelogin (3.0.0.pre.alpha.1)
|
20
|
+
typhoeus (~> 1.0, >= 1.0.1)
|
21
|
+
parallel (1.22.1)
|
22
|
+
parser (3.2.0.0)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
rainbow (3.1.1)
|
25
|
+
rake (13.0.6)
|
26
|
+
regexp_parser (2.6.1)
|
27
|
+
rexml (3.2.5)
|
28
|
+
rspec (3.12.0)
|
29
|
+
rspec-core (~> 3.12.0)
|
30
|
+
rspec-expectations (~> 3.12.0)
|
31
|
+
rspec-mocks (~> 3.12.0)
|
32
|
+
rspec-core (3.12.0)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-expectations (3.12.2)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-mocks (3.12.2)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-support (3.12.0)
|
41
|
+
rubocop (1.43.0)
|
42
|
+
json (~> 2.3)
|
43
|
+
parallel (~> 1.10)
|
44
|
+
parser (>= 3.2.0.0)
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
regexp_parser (>= 1.8, < 3.0)
|
47
|
+
rexml (>= 3.2.5, < 4.0)
|
48
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
49
|
+
ruby-progressbar (~> 1.7)
|
50
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
51
|
+
rubocop-ast (1.24.1)
|
52
|
+
parser (>= 3.1.1.0)
|
53
|
+
rubocop-rake (0.6.0)
|
54
|
+
rubocop (~> 1.0)
|
55
|
+
rubocop-rspec (2.17.1)
|
56
|
+
rubocop (~> 1.33)
|
57
|
+
ruby-progressbar (1.11.0)
|
58
|
+
thor (1.2.1)
|
59
|
+
typhoeus (1.4.0)
|
60
|
+
ethon (>= 0.9.0)
|
61
|
+
unicode-display_width (2.4.2)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
x86_64-linux
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
moura!
|
68
|
+
rake (~> 13.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rubocop (~> 1.21)
|
71
|
+
rubocop-rake
|
72
|
+
rubocop-rspec
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.4.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 GMO Pepabo, Inc.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Moura
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/moura`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add moura
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install moura
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
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.
|
24
|
+
|
25
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/moura.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/moura
ADDED
data/lib/moura/cli.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require_relative "model/diff"
|
5
|
+
require_relative "view"
|
6
|
+
|
7
|
+
module Moura
|
8
|
+
class Cli < Thor
|
9
|
+
desc "dump", "dump"
|
10
|
+
def dump
|
11
|
+
remote_roles = Model::Remote.new.dump
|
12
|
+
puts YAML.dump(remote_roles.sort_by(&:first).to_h)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "diff <file>", "diff"
|
16
|
+
def diff(file)
|
17
|
+
model = Model::Diff.new(file)
|
18
|
+
|
19
|
+
View::Diff.new(model.diff).show
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "apply <file>", "diff"
|
23
|
+
def apply(file)
|
24
|
+
model = Model::Diff.new(file)
|
25
|
+
model.apply
|
26
|
+
|
27
|
+
View::Diff.new(model.diff).show
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hashdiff"
|
4
|
+
require_relative "local"
|
5
|
+
require_relative "remote"
|
6
|
+
|
7
|
+
module Moura
|
8
|
+
module Model
|
9
|
+
class Diff
|
10
|
+
attr_reader :diff
|
11
|
+
|
12
|
+
def initialize(local_file)
|
13
|
+
@local = Local.new(local_file)
|
14
|
+
@remote = Remote.new
|
15
|
+
|
16
|
+
hash_diff = Hashdiff.diff(@remote.dump, @local.dump)
|
17
|
+
@diff = parse_hash_diff(hash_diff)
|
18
|
+
|
19
|
+
validate_diff_data
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_hash_diff(data)
|
23
|
+
data.each_with_object({}) do |(mark, target, diff), result|
|
24
|
+
(role_name, child) = target.match(/^(.+?)(?:\.(apps|users)(?:\[\d+\])?)?$/).captures
|
25
|
+
action = mark == "+" ? :add : :remove
|
26
|
+
|
27
|
+
unless result[role_name]
|
28
|
+
result[role_name] = {
|
29
|
+
action: :none,
|
30
|
+
apps: { add: [], remove: [] },
|
31
|
+
users: { add: [], remove: [] }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
if child
|
36
|
+
result[role_name][child.to_sym][action] <<= diff
|
37
|
+
else
|
38
|
+
result[role_name][:action] = action
|
39
|
+
result[role_name][:apps][action] += diff.fetch("apps", [])
|
40
|
+
result[role_name][:users][action] += diff.fetch("users", [])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_diff_data
|
46
|
+
apps = @diff.map { |_, v| v[:apps][:add] }.flatten.sort.uniq
|
47
|
+
@remote.validate_apps(apps)
|
48
|
+
|
49
|
+
emails = @diff.map { |_, v| v[:users][:add] }.flatten.sort.uniq
|
50
|
+
@remote.validate_emails(emails)
|
51
|
+
end
|
52
|
+
|
53
|
+
def apply
|
54
|
+
@diff.each do |role, attr|
|
55
|
+
case attr[:action]
|
56
|
+
when :add
|
57
|
+
@remote.create_role(role)
|
58
|
+
when :remove
|
59
|
+
@remote.delete_role(role)
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
63
|
+
apps = attr[:apps]
|
64
|
+
add_apps = apps[:add]
|
65
|
+
remove_apps = apps[:remove]
|
66
|
+
if add_apps.present? || remove_apps.present?
|
67
|
+
merged_app_ids = merge_role_apps(role, apps[:add], apps[:remove])
|
68
|
+
@remote.set_role_apps(role, merged_app_ids)
|
69
|
+
end
|
70
|
+
|
71
|
+
users = attr[:users]
|
72
|
+
@remote.add_role_users(role, users[:add])
|
73
|
+
@remote.remove_role_users(role, users[:remove])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def merge_role_apps(role, add, remove)
|
78
|
+
current_apps = @remote.role(role).apps
|
79
|
+
add_apps = add.map { |name| @remote.find_app_id_by_name(name) }
|
80
|
+
remove_apps = remove.map { |name| @remote.find_app_id_by_name(name) }
|
81
|
+
current_apps + add_apps - remove_apps
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module Moura
|
6
|
+
module Model
|
7
|
+
class Local
|
8
|
+
def initialize(file)
|
9
|
+
@roles = YAML.load_file(file, aliases: true).sort_by(&:first).to_h do |(k, v)|
|
10
|
+
apps = v["apps"] || []
|
11
|
+
users = v["users"] || []
|
12
|
+
|
13
|
+
[k, { "apps" => apps.sort.uniq, "users" => users.sort.uniq }]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def dump
|
18
|
+
@roles
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../onelogin"
|
4
|
+
require "onelogin/api"
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
module Moura
|
8
|
+
module Model
|
9
|
+
class Remote
|
10
|
+
def initialize
|
11
|
+
@client = OneLogin.client
|
12
|
+
|
13
|
+
# データを圧縮するために取得フィールドを絞る
|
14
|
+
@users = @client.list_users(fields: "id,email,firstname,lastname", limit: 1000).to_h do |user|
|
15
|
+
[user.id, user]
|
16
|
+
end
|
17
|
+
@apps = @client.list_apps(limit: 1000).to_h { |app| [app.id, app] }
|
18
|
+
update_roles
|
19
|
+
end
|
20
|
+
|
21
|
+
def role(name)
|
22
|
+
@roles[name]
|
23
|
+
end
|
24
|
+
|
25
|
+
def app(id)
|
26
|
+
@apps[id]
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_role_id(name)
|
30
|
+
role = @roles[name]
|
31
|
+
raise RoleNotFound unless role
|
32
|
+
|
33
|
+
role.id
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump
|
37
|
+
@roles.map do |(name, role)|
|
38
|
+
apps = role.apps.map { |id| @apps[id].name }.sort
|
39
|
+
users = role.users.map { |id| @users[id].email }.sort
|
40
|
+
[name, { "apps" => apps, "users" => users }]
|
41
|
+
end.sort_by(&:first).to_h
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_apps(apps)
|
45
|
+
apps.each do |app|
|
46
|
+
raise ApplicationNotFound, app unless find_app_id_by_name(app)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_emails(emails)
|
51
|
+
emails.each do |email|
|
52
|
+
raise UserNotFound, email unless find_user_id_by_email(email)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_role(name)
|
57
|
+
body = { name: }
|
58
|
+
@client.create_roles(debug_body: body)
|
59
|
+
update_roles
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_role_apps(name, app_ids)
|
63
|
+
role_id = find_role_id_by_name(name)
|
64
|
+
@client.set_role_apps(role_id, app_ids)
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_role_users(name, emails)
|
68
|
+
role_id = find_role_id_by_name(name)
|
69
|
+
user_ids = emails&.map { |email| find_user_id_by_email(email) }
|
70
|
+
|
71
|
+
@client.add_role_users(role_id, user_ids) if user_ids&.present?
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_role(name)
|
75
|
+
role_id = find_role_id_by_name(name)
|
76
|
+
@client.delete_role(role_id) if role_id
|
77
|
+
end
|
78
|
+
|
79
|
+
def remove_role_users(name, emails)
|
80
|
+
role_id = find_role_id_by_name(name)
|
81
|
+
user_ids = emails&.map { |email| find_user_id_by_email(email) }
|
82
|
+
|
83
|
+
@client.remove_role_users(role_id, user_ids) if user_ids&.present?
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_role_id_by_name(name)
|
87
|
+
return unless (role = @roles.find { |_, r| r.name == name })
|
88
|
+
|
89
|
+
role.last.id
|
90
|
+
end
|
91
|
+
|
92
|
+
def find_app_id_by_name(name)
|
93
|
+
return unless (app = @apps.find { |_, a| a.name == name })
|
94
|
+
|
95
|
+
app.last.id
|
96
|
+
end
|
97
|
+
|
98
|
+
def find_user_id_by_email(email)
|
99
|
+
return unless (user = @users.find { |_, v| v.email == email })
|
100
|
+
|
101
|
+
user.last.id
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def update_roles
|
107
|
+
@roles = @client.list_roles(limit: 1000).to_h { |role| [role.name, role] }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/moura/model.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "onelogin"
|
4
|
+
|
5
|
+
module Moura
|
6
|
+
module OneLogin
|
7
|
+
def self.client
|
8
|
+
::OneLogin.configure do |config|
|
9
|
+
config.host = ENV.fetch("ONELOGIN_API_DOMAIN")
|
10
|
+
config.debugging = ENV.fetch("ONELOGIN_DEBUG", false)
|
11
|
+
end
|
12
|
+
|
13
|
+
client_id = ENV.fetch("ONELOGIN_CLIENT_ID")
|
14
|
+
client_secret = ENV.fetch("ONELOGIN_CLIENT_SECRET")
|
15
|
+
::OneLogin::Api.new(client_id, client_secret)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Moura
|
4
|
+
module View
|
5
|
+
class Diff
|
6
|
+
attr :data
|
7
|
+
|
8
|
+
def initialize(diff)
|
9
|
+
@data = diff
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@data.each do |role, attr|
|
14
|
+
mark = symbol_to_mark(attr[:action])
|
15
|
+
puts "#{mark} #{role}"
|
16
|
+
show_child(attr[:apps], "アプリケーション")
|
17
|
+
show_child(attr[:users], "ユーザ")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def symbol_to_mark(sym)
|
22
|
+
case sym
|
23
|
+
when :add then "+"
|
24
|
+
when :remove then "-"
|
25
|
+
else " "
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_child(data, name)
|
30
|
+
return if data[:add].empty? && data[:remove].empty?
|
31
|
+
|
32
|
+
puts " => #{name}"
|
33
|
+
|
34
|
+
data[:add].sort.each do |a|
|
35
|
+
puts "+ #{a}"
|
36
|
+
end
|
37
|
+
|
38
|
+
data[:remove].sort.each do |r|
|
39
|
+
puts "- #{r}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/moura/view.rb
ADDED
data/lib/moura.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "moura/cli"
|
4
|
+
require_relative "moura/version"
|
5
|
+
|
6
|
+
class Array
|
7
|
+
def present?
|
8
|
+
!empty?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Moura
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
class RoleNotFound < Error
|
16
|
+
def initialize(role)
|
17
|
+
super("role '#{role}' does not exist")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class UserNotFound < Error
|
22
|
+
def initialize(user)
|
23
|
+
super("user '#{user}' does not exist")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ApplicationNotFound < Error
|
28
|
+
def initialize(app)
|
29
|
+
super("application '#{app}' does not exist")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.start(_argv = ARGV)
|
34
|
+
Cli.start(ARGV)
|
35
|
+
end
|
36
|
+
end
|
data/lib/onelogin/api.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "onelogin"
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
module OneLogin
|
7
|
+
class Api
|
8
|
+
def initialize(client_id, client_secret, client = ApiClient.default)
|
9
|
+
@client = DefaultApi.new(client)
|
10
|
+
@access_token = generate_token(client_id, client_secret).access_token
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_token(client_id, client_secret)
|
14
|
+
auth = "client_id:#{client_id}, client_secret:#{client_secret}"
|
15
|
+
generate_token_request = OneLogin::GenerateTokenRequest.new
|
16
|
+
generate_token_request.grant_type = "client_credentials"
|
17
|
+
@client.generate_token(auth, generate_token_request)
|
18
|
+
end
|
19
|
+
|
20
|
+
def authorazation
|
21
|
+
"bearer #{@access_token}"
|
22
|
+
end
|
23
|
+
|
24
|
+
DefaultApi.public_instance_methods(false)
|
25
|
+
.grep_v(/api_client|generate_token|_with_http_info/)
|
26
|
+
.each do |name|
|
27
|
+
define_method(name) do |*args|
|
28
|
+
@client.send(name, authorazation, *args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/moura.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/moura/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "moura"
|
7
|
+
spec.version = Moura::VERSION
|
8
|
+
spec.authors = ["Yuki Koya"]
|
9
|
+
spec.email = ["ykky@pepabo.com"]
|
10
|
+
|
11
|
+
spec.summary = "Management tool for Onelogin resources."
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/pepabo/moura/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.2.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "hashdiff", "~> 1.0.1"
|
34
|
+
spec.add_dependency "onelogin", "~> 3.0.0.pre.alpha.1"
|
35
|
+
spec.add_dependency "thor", "~> 1.2", ">= 1.2.1"
|
36
|
+
end
|
data/sig/moura.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moura
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuki Koya
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashdiff
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: onelogin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0.pre.alpha.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0.pre.alpha.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.2.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.2'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.2.1
|
61
|
+
description: Management tool for Onelogin resources.
|
62
|
+
email:
|
63
|
+
- ykky@pepabo.com
|
64
|
+
executables:
|
65
|
+
- moura
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".rspec"
|
70
|
+
- ".rubocop.yml"
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- exe/moura
|
77
|
+
- lib/moura.rb
|
78
|
+
- lib/moura/cli.rb
|
79
|
+
- lib/moura/model.rb
|
80
|
+
- lib/moura/model/diff.rb
|
81
|
+
- lib/moura/model/local.rb
|
82
|
+
- lib/moura/model/remote.rb
|
83
|
+
- lib/moura/onelogin.rb
|
84
|
+
- lib/moura/version.rb
|
85
|
+
- lib/moura/view.rb
|
86
|
+
- lib/moura/view/diff.rb
|
87
|
+
- lib/onelogin/api.rb
|
88
|
+
- moura.gemspec
|
89
|
+
- sig/moura.rbs
|
90
|
+
homepage: https://github.com/pepabo/moura/
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
homepage_uri: https://github.com/pepabo/moura/
|
95
|
+
source_code_uri: https://github.com/pepabo/moura/
|
96
|
+
changelog_uri: https://github.com/pepabo/moura/
|
97
|
+
rubygems_mfa_required: 'true'
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 3.2.0
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubygems_version: 3.4.1
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Management tool for Onelogin resources.
|
117
|
+
test_files: []
|