pe_rbac 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/example.rb +22 -0
- data/lib/pe_rbac/group.rb +89 -0
- data/lib/pe_rbac/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fa983a89ed5551d3f1f8eb5fa66dfcae9673ff9ab364a5683ce0b3bd7a30db0
|
4
|
+
data.tar.gz: d8a49c61ee9686caf8e43a4932f4474524abf9fdbb0347663fa903178c751f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf75b607cc157e1b7386cbec45bf6ff3416775d7ccbf8b323c83342bbeee8990e5ee34d041aef456ea813bf5ebf5f767e99d37d03805cb87cc4936a46d85058d
|
7
|
+
data.tar.gz: 98efe4296bc715c18d9b5a58e0ec72a2fc9e6c4aa16e186fef9b369f52b698ee10bfbfab5abdbf4ad42eb0848f84d65e71399ae3408a08bd6bf75341999d43a0
|
data/.travis.yml
CHANGED
data/example.rb
CHANGED
@@ -51,6 +51,28 @@ begin
|
|
51
51
|
resp = PeRbac::get_permissions
|
52
52
|
puts resp.body
|
53
53
|
|
54
|
+
# Manage groups
|
55
|
+
require 'pe_rbac/group'
|
56
|
+
require 'json'
|
57
|
+
|
58
|
+
# Get all groups
|
59
|
+
puts JSON.pretty_generate PeRbac::Group.get_groups
|
60
|
+
|
61
|
+
# Create group
|
62
|
+
resp = PeRbac::Group.ensure_group('test-group', 2)
|
63
|
+
puts resp.code
|
64
|
+
|
65
|
+
# Get one group
|
66
|
+
test_group = PeRbac::Group.get_group(PeRbac::Group.get_group_id('test-group'))
|
67
|
+
|
68
|
+
# Update role in group
|
69
|
+
resp = PeRbac::Group.ensure_group('test-group', [1,2])
|
70
|
+
puts resp.code
|
71
|
+
|
72
|
+
# Remove group
|
73
|
+
resp = PeRbac::Group.delete_group('test-group')
|
74
|
+
puts resp.code
|
75
|
+
|
54
76
|
rescue Exception => e
|
55
77
|
puts e.message
|
56
78
|
puts e.backtrace
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2017 Declarative Systems PTY LTD
|
3
|
+
# Copyright 2016 Puppet Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
require 'json'
|
17
|
+
require 'pe_rbac/core'
|
18
|
+
require 'pe_rbac/action'
|
19
|
+
|
20
|
+
module PeRbac
|
21
|
+
module Group
|
22
|
+
def self.get_groups
|
23
|
+
JSON.parse(PeRbac::Core::request(:get, '/groups').body)
|
24
|
+
end
|
25
|
+
|
26
|
+
# get the user id for a login or false if missing
|
27
|
+
# eg 'admin' => '42bf351c-f9ec-40af-84ad-e976fec7f4bd'
|
28
|
+
def self.get_group_id(login)
|
29
|
+
groups = get_groups
|
30
|
+
id = false
|
31
|
+
i = 0
|
32
|
+
while !id and i < groups.length do
|
33
|
+
if groups[i]['login'] == login
|
34
|
+
id = groups[i]['id']
|
35
|
+
end
|
36
|
+
i += 1
|
37
|
+
end
|
38
|
+
id
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_group(id)
|
42
|
+
resp = PeRbac::Core::request(:get, "/groups/#{id}")
|
43
|
+
resp ? JSON.parse(resp.body) : false
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.ensure_group(login, role_ids)
|
47
|
+
if get_group_id(login)
|
48
|
+
# existing group
|
49
|
+
update_group(login, role_ids)
|
50
|
+
else
|
51
|
+
# new group
|
52
|
+
create_group(login, role_ids)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.create_group(login, role_ids=[])
|
58
|
+
# completely different to what the PE console sends... :/
|
59
|
+
# Elegantly convert role_ids to an array if it isn't one already
|
60
|
+
group={
|
61
|
+
"login" => login,
|
62
|
+
"role_ids" => Array(role_ids),
|
63
|
+
}
|
64
|
+
|
65
|
+
PeRbac::Core::request(:post, '/groups', group) ? true : false
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.update_group(login, role_ids=[])
|
69
|
+
group = get_group(get_group_id(login))
|
70
|
+
status = false
|
71
|
+
if group
|
72
|
+
group['login'] = login ? login : group['login']
|
73
|
+
group['role_ids'] = role_ids ? Array(role_ids) : group['role_ids']
|
74
|
+
|
75
|
+
status = PeRbac::Core::request(:put, "/groups/#{group['id']}", group) ? true : false
|
76
|
+
end
|
77
|
+
status
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.delete_group(login)
|
81
|
+
group = get_group(get_group_id(login))
|
82
|
+
status = false
|
83
|
+
if group
|
84
|
+
PeRbac::Core::request(:delete, "/groups/#{group['id']}") ? true : false
|
85
|
+
end
|
86
|
+
status
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/pe_rbac/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pe_rbac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/pe_rbac.rb
|
201
201
|
- lib/pe_rbac/action.rb
|
202
202
|
- lib/pe_rbac/core.rb
|
203
|
+
- lib/pe_rbac/group.rb
|
203
204
|
- lib/pe_rbac/permission.rb
|
204
205
|
- lib/pe_rbac/role.rb
|
205
206
|
- lib/pe_rbac/user.rb
|