gazer 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/lib/gzr/cli.rb +4 -3
- data/lib/gzr/commands/model/set/cat.rb +60 -0
- data/lib/gzr/commands/model/set/import.rb +73 -0
- data/lib/gzr/commands/model/set/ls.rb +74 -0
- data/lib/gzr/commands/model/set/rm.rb +49 -0
- data/lib/gzr/commands/model/set.rb +97 -0
- data/lib/gzr/commands/model.rb +3 -0
- data/lib/gzr/commands/{permissions → permission}/ls.rb +3 -3
- data/lib/gzr/commands/permission/set/cat.rb +60 -0
- data/lib/gzr/commands/permission/set/import.rb +73 -0
- data/lib/gzr/commands/permission/set/ls.rb +78 -0
- data/lib/gzr/commands/permission/set/rm.rb +49 -0
- data/lib/gzr/commands/permission/set.rb +98 -0
- data/lib/gzr/commands/permission/tree.rb +71 -0
- data/lib/gzr/commands/{permissions.rb → permission.rb} +22 -6
- data/lib/gzr/commands/role/cat.rb +4 -3
- data/lib/gzr/commands/role/create.rb +51 -0
- data/lib/gzr/commands/role.rb +19 -1
- data/lib/gzr/commands/subcommandbase.rb +2 -2
- data/lib/gzr/modules/model/set.rb +123 -0
- data/lib/gzr/modules/permission/set.rb +123 -0
- data/lib/gzr/modules/{permissions.rb → permission.rb} +1 -1
- data/lib/gzr/modules/role.rb +23 -0
- data/lib/gzr/version.rb +1 -1
- metadata +19 -5
@@ -0,0 +1,49 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../../command'
|
25
|
+
require_relative '../../../modules/permission/set'
|
26
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Permission
|
30
|
+
class Set
|
31
|
+
class Delete < Gzr::Command
|
32
|
+
include Gzr::Permission::Set
|
33
|
+
def initialize(permission_set_id,options)
|
34
|
+
super()
|
35
|
+
@permission_set_id = permission_set_id
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
delete_permission_set(@permission_set_id)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../subcommandbase'
|
25
|
+
|
26
|
+
module Gzr
|
27
|
+
module Commands
|
28
|
+
class Permission
|
29
|
+
class Set < SubCommandBase
|
30
|
+
|
31
|
+
namespace :'permission set'
|
32
|
+
|
33
|
+
desc 'ls', 'List the permission sets in this server.'
|
34
|
+
method_option :help, aliases: '-h', type: :boolean,
|
35
|
+
desc: 'Display usage information'
|
36
|
+
method_option :fields, type: :string, default: 'id,name,permissions,built_in,all_access',
|
37
|
+
desc: 'Fields to display'
|
38
|
+
method_option :plain, type: :boolean, default: false,
|
39
|
+
desc: 'print without any extra formatting'
|
40
|
+
method_option :csv, type: :boolean, default: false,
|
41
|
+
desc: 'output in csv format per RFC4180'
|
42
|
+
def ls(*)
|
43
|
+
if options[:help]
|
44
|
+
invoke :help, ['ls']
|
45
|
+
else
|
46
|
+
require_relative 'set/ls'
|
47
|
+
Gzr::Commands::Permission::Set::Ls.new(options).execute
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'cat PERMISSION_SET_ID', 'Output json information about a permission set to screen or file'
|
52
|
+
method_option :help, aliases: '-h', type: :boolean,
|
53
|
+
desc: 'Display usage information'
|
54
|
+
method_option :dir, type: :string,
|
55
|
+
desc: 'Directory to store output file'
|
56
|
+
method_option :trim, type: :boolean,
|
57
|
+
desc: 'Trim output to minimal set of fields for later import'
|
58
|
+
def cat(permission_set_id)
|
59
|
+
if options[:help]
|
60
|
+
invoke :help, ['cat']
|
61
|
+
else
|
62
|
+
require_relative 'set/cat'
|
63
|
+
Gzr::Commands::Permission::Set::Cat.new(permission_set_id,options).execute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc 'import FILE', 'Import a permission set from a file'
|
68
|
+
method_option :help, aliases: '-h', type: :boolean,
|
69
|
+
desc: 'Display usage information'
|
70
|
+
method_option :force, type: :boolean,
|
71
|
+
desc: 'Overwrite an existing permission set'
|
72
|
+
method_option :plain, type: :boolean, default: false,
|
73
|
+
desc: 'print without any extra formatting'
|
74
|
+
def import(file)
|
75
|
+
if options[:help]
|
76
|
+
invoke :help, ['import']
|
77
|
+
else
|
78
|
+
require_relative 'set/import'
|
79
|
+
Gzr::Commands::Permission::Set::Import.new(file, options).execute
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc 'rm PERMISSION_SET_ID', 'Delete the permission_set given by PERMISSION_SET_ID'
|
84
|
+
method_option :help, aliases: '-h', type: :boolean,
|
85
|
+
desc: 'Display usage information'
|
86
|
+
def rm(permission_set_id)
|
87
|
+
if options[:help]
|
88
|
+
invoke :help, ['delete']
|
89
|
+
else
|
90
|
+
require_relative 'set/rm'
|
91
|
+
Gzr::Commands::Permission::Set::Delete.new(permission_set_id,options).execute
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/permission'
|
26
|
+
require 'tty-tree'
|
27
|
+
|
28
|
+
require_relative '../../command'
|
29
|
+
|
30
|
+
module Gzr
|
31
|
+
module Commands
|
32
|
+
class Permission
|
33
|
+
class Tree < Gzr::Command
|
34
|
+
include Gzr::Permission
|
35
|
+
def initialize(options)
|
36
|
+
super()
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(input: $stdin, output: $stdout)
|
41
|
+
say_warning(@options) if @options[:debug]
|
42
|
+
with_session do
|
43
|
+
data = query_all_permissions()
|
44
|
+
begin
|
45
|
+
say_ok "No permissions found"
|
46
|
+
return nil
|
47
|
+
end unless data && data.length > 0
|
48
|
+
|
49
|
+
tree_data = Hash.new
|
50
|
+
|
51
|
+
data.sort! { |a,b| a[:permission] <=> b[:permission] }
|
52
|
+
data.select {|e| e[:parent] == nil}.each do |e|
|
53
|
+
tree_data[e[:permission]] = [recurse_permissions(e[:permission], data)]
|
54
|
+
end
|
55
|
+
|
56
|
+
tree = TTY::Tree.new(tree_data)
|
57
|
+
output.puts tree.render
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def recurse_permissions(permission, data)
|
62
|
+
tree_branch = Hash.new
|
63
|
+
data.select { |e| e[:parent] == permission }.each do |e|
|
64
|
+
tree_branch[e[:permission]] = [recurse_permissions(e[:permission], data)]
|
65
|
+
end
|
66
|
+
tree_branch
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -21,13 +21,16 @@
|
|
21
21
|
|
22
22
|
# frozen_string_literal: true
|
23
23
|
|
24
|
-
|
24
|
+
require_relative 'subcommandbase'
|
25
25
|
|
26
26
|
module Gzr
|
27
27
|
module Commands
|
28
|
-
class
|
28
|
+
class Permission < SubCommandBase
|
29
29
|
|
30
|
-
|
30
|
+
require_relative 'permission/set'
|
31
|
+
register Gzr::Commands::Permission::Set, 'set', 'set [SUBCOMMAND]', 'Commands pertaining to permission sets'
|
32
|
+
|
33
|
+
namespace :permission
|
31
34
|
|
32
35
|
desc 'ls', 'List all available permissions'
|
33
36
|
method_option :help, aliases: '-h', type: :boolean,
|
@@ -40,10 +43,23 @@ module Gzr
|
|
40
43
|
if options[:help]
|
41
44
|
invoke :help, ['ls']
|
42
45
|
else
|
43
|
-
require_relative '
|
44
|
-
Gzr::Commands::
|
46
|
+
require_relative 'permission/ls'
|
47
|
+
Gzr::Commands::Permission::Ls.new(options).execute
|
45
48
|
end
|
46
49
|
end
|
50
|
+
|
51
|
+
desc 'tree', 'List all available permissions in a tree'
|
52
|
+
method_option :help, aliases: '-h', type: :boolean,
|
53
|
+
desc: 'Display usage information'
|
54
|
+
def tree(*)
|
55
|
+
if options[:help]
|
56
|
+
invoke :help, ['tree']
|
57
|
+
else
|
58
|
+
require_relative 'permission/tree'
|
59
|
+
Gzr::Commands::Permission::Tree.new(options).execute
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
47
63
|
end
|
48
64
|
end
|
49
65
|
end
|
@@ -40,9 +40,10 @@ module Gzr
|
|
40
40
|
def execute(input: $stdin, output: $stdout)
|
41
41
|
say_warning("options: #{@options.inspect}") if @options[:debug]
|
42
42
|
with_session do
|
43
|
-
data = query_role(@role_id)
|
44
|
-
|
45
|
-
|
43
|
+
data = query_role(@role_id)&.to_attrs
|
44
|
+
data = trim_role(data) if @options[:trim]
|
45
|
+
write_file(@options[:dir] ? "Role_#{data[:id]}_#{data[:name]}.json" : nil, @options[:dir], nil, output) do |f|
|
46
|
+
f.puts JSON.pretty_generate(data)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
require_relative '../../command'
|
25
|
+
require_relative '../../modules/role'
|
26
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Role
|
30
|
+
class Create < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(name,pset,mset, options)
|
33
|
+
super()
|
34
|
+
@name = name
|
35
|
+
@pset = pset
|
36
|
+
@mset = mset
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(input: $stdin, output: $stdout)
|
41
|
+
folder = nil
|
42
|
+
with_session do
|
43
|
+
role = create_role(@name, @pset, @mset)
|
44
|
+
output.puts "Created role #{role[:id]} #{role[:name]}" unless @options[:plain]
|
45
|
+
output.puts role[:id] if @options[:plain]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/gzr/commands/role.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -132,6 +132,8 @@ module Gzr
|
|
132
132
|
desc: 'Display usage information'
|
133
133
|
method_option :dir, type: :string,
|
134
134
|
desc: 'Directory to get output file'
|
135
|
+
method_option :trim, type: :boolean,
|
136
|
+
desc: 'Trim output to minimal set of fields for later import'
|
135
137
|
def cat(role_id)
|
136
138
|
if options[:help]
|
137
139
|
invoke :help, ['cat']
|
@@ -158,6 +160,22 @@ module Gzr
|
|
158
160
|
Gzr::Commands::Role::Ls.new(options).execute
|
159
161
|
end
|
160
162
|
end
|
163
|
+
|
164
|
+
desc 'create ROLE_NAME PERMISSION_SET_ID MODEL_SET_ID', "Create new role with the given permission and model sets"
|
165
|
+
method_option :help, aliases: '-h', type: :boolean,
|
166
|
+
desc: 'Display usage information'
|
167
|
+
method_option :plain, type: :boolean, default: false,
|
168
|
+
desc: 'print without any extra formatting'
|
169
|
+
|
170
|
+
def create(name, pset, mset)
|
171
|
+
if options[:help]
|
172
|
+
invoke :help, ['create']
|
173
|
+
else
|
174
|
+
require_relative 'role/create'
|
175
|
+
Gzr::Commands::Role::Create.new(name, pset, mset, options).execute
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
161
179
|
end
|
162
180
|
end
|
163
181
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# The MIT License (MIT)
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
4
|
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
# this software and associated documentation files (the "Software"), to deal in
|
@@ -34,7 +34,7 @@ module Gzr
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.subcommand_prefix
|
37
|
-
self.
|
37
|
+
self.namespace
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
module Gzr
|
25
|
+
module Model
|
26
|
+
module Set
|
27
|
+
|
28
|
+
def all_model_sets(fields=nil)
|
29
|
+
req = {}
|
30
|
+
req[:fields] = fields if fields
|
31
|
+
begin
|
32
|
+
return @sdk.all_model_sets(req)
|
33
|
+
rescue LookerSDK::NotFound => e
|
34
|
+
return nil
|
35
|
+
rescue LookerSDK::Error => e
|
36
|
+
say_error "Error querying all_model_sets(#{JSON.pretty_generate(req)})"
|
37
|
+
say_error e
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def cat_model_set(set_id, fields=nil)
|
43
|
+
req = {}
|
44
|
+
req[:fields] = fields if fields
|
45
|
+
begin
|
46
|
+
return @sdk.model_set(set_id,req)&.to_attrs
|
47
|
+
rescue LookerSDK::NotFound => e
|
48
|
+
return nil
|
49
|
+
rescue LookerSDK::Error => e
|
50
|
+
say_error "Error querying model_set(#{set_id},#{JSON.pretty_generate(req)})"
|
51
|
+
say_error e
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def trim_model_set(data)
|
57
|
+
trimmed = data.select do |k,v|
|
58
|
+
(keys_to_keep('update_model_set') + [:id,:built_in]).include? k
|
59
|
+
end
|
60
|
+
trimmed
|
61
|
+
end
|
62
|
+
|
63
|
+
def search_model_sets(fields: nil, sorts: nil, id: nil, name: nil, all_access: nil, built_in: nil, filter_or: nil)
|
64
|
+
data = []
|
65
|
+
begin
|
66
|
+
req = {}
|
67
|
+
req[:fields] = fields unless fields.nil?
|
68
|
+
req[:sorts] = sorts unless sorts.nil?
|
69
|
+
req[:id] = id unless id.nil?
|
70
|
+
req[:name] = name unless name.nil?
|
71
|
+
req[:all_access] = all_access unless all_access.nil?
|
72
|
+
req[:built_in] = built_in unless built_in.nil?
|
73
|
+
req[:filter_or] = filter_or unless filter_or.nil?
|
74
|
+
req[:limit] = 64
|
75
|
+
loop do
|
76
|
+
page = @sdk.search_model_sets(req)
|
77
|
+
data+=page
|
78
|
+
break unless page.length == req[:limit]
|
79
|
+
req[:offset] = (req[:offset] || 0) + req[:limit]
|
80
|
+
end
|
81
|
+
rescue LookerSDK::NotFound => e
|
82
|
+
# do nothing
|
83
|
+
rescue LookerSDK::Error => e
|
84
|
+
say_error "Error calling search_model_sets(#{JSON.pretty_generate(req)})"
|
85
|
+
say_error e
|
86
|
+
raise
|
87
|
+
end
|
88
|
+
data
|
89
|
+
end
|
90
|
+
|
91
|
+
def update_model_set(model_set_id, data)
|
92
|
+
begin
|
93
|
+
return @sdk.update_model_set(model_set_id, data)&.to_attrs
|
94
|
+
rescue LookerSDK::Error => e
|
95
|
+
say_error "Error calling update_model_set(#{model_set_id},#{JSON.pretty_generate(data)})"
|
96
|
+
say_error e
|
97
|
+
raise
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_model_set(data)
|
102
|
+
begin
|
103
|
+
return @sdk.create_model_set(data)&.to_attrs
|
104
|
+
rescue LookerSDK::Error => e
|
105
|
+
say_error "Error calling create_model_set(#{JSON.pretty_generate(data)})"
|
106
|
+
say_error e
|
107
|
+
raise
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete_model_set(model_set_id)
|
112
|
+
begin
|
113
|
+
return @sdk.delete_model_set(model_set_id)
|
114
|
+
rescue LookerSDK::Error => e
|
115
|
+
say_error "Error calling delete_model_set(#{model_set_id}})"
|
116
|
+
say_error e
|
117
|
+
raise
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2023 Mike DeAngelo Google, Inc.
|
4
|
+
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
# this software and associated documentation files (the "Software"), to deal in
|
7
|
+
# the Software without restriction, including without limitation the rights to
|
8
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
# 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, FITNESS
|
17
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
# frozen_string_literal: true
|
23
|
+
|
24
|
+
module Gzr
|
25
|
+
module Permission
|
26
|
+
module Set
|
27
|
+
|
28
|
+
def all_permission_sets(fields=nil)
|
29
|
+
req = {}
|
30
|
+
req[:fields] = fields if fields
|
31
|
+
begin
|
32
|
+
return @sdk.all_permission_sets(req)
|
33
|
+
rescue LookerSDK::NotFound => e
|
34
|
+
return nil
|
35
|
+
rescue LookerSDK::Error => e
|
36
|
+
say_error "Error querying all_permission_sets(#{JSON.pretty_generate(req)})"
|
37
|
+
say_error e
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def cat_permission_set(set_id, fields=nil)
|
43
|
+
req = {}
|
44
|
+
req[:fields] = fields if fields
|
45
|
+
begin
|
46
|
+
return @sdk.permission_set(set_id,req)&.to_attrs
|
47
|
+
rescue LookerSDK::NotFound => e
|
48
|
+
return nil
|
49
|
+
rescue LookerSDK::Error => e
|
50
|
+
say_error "Error querying permission_set(#{set_id},#{JSON.pretty_generate(req)})"
|
51
|
+
say_error e
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def trim_permission_set(data)
|
57
|
+
trimmed = data.select do |k,v|
|
58
|
+
(keys_to_keep('update_permission_set') + [:id,:built_in]).include? k
|
59
|
+
end
|
60
|
+
trimmed
|
61
|
+
end
|
62
|
+
|
63
|
+
def search_permission_sets(fields: nil, sorts: nil, id: nil, name: nil, all_access: nil, built_in: nil, filter_or: nil)
|
64
|
+
data = []
|
65
|
+
begin
|
66
|
+
req = {}
|
67
|
+
req[:fields] = fields unless fields.nil?
|
68
|
+
req[:sorts] = sorts unless sorts.nil?
|
69
|
+
req[:id] = id unless id.nil?
|
70
|
+
req[:name] = name unless name.nil?
|
71
|
+
req[:all_access] = all_access unless all_access.nil?
|
72
|
+
req[:built_in] = built_in unless built_in.nil?
|
73
|
+
req[:filter_or] = filter_or unless filter_or.nil?
|
74
|
+
req[:limit] = 64
|
75
|
+
loop do
|
76
|
+
page = @sdk.search_permission_sets(req)
|
77
|
+
data+=page
|
78
|
+
break unless page.length == req[:limit]
|
79
|
+
req[:offset] = (req[:offset] || 0) + req[:limit]
|
80
|
+
end
|
81
|
+
rescue LookerSDK::NotFound => e
|
82
|
+
# do nothing
|
83
|
+
rescue LookerSDK::Error => e
|
84
|
+
say_error "Error calling search_permission_sets(#{JSON.pretty_generate(req)})"
|
85
|
+
say_error e
|
86
|
+
raise
|
87
|
+
end
|
88
|
+
data
|
89
|
+
end
|
90
|
+
|
91
|
+
def update_permission_set(permission_set_id, data)
|
92
|
+
begin
|
93
|
+
return @sdk.update_permission_set(permission_set_id, data)&.to_attrs
|
94
|
+
rescue LookerSDK::Error => e
|
95
|
+
say_error "Error calling update_permission_set(#{permission_set_id},#{JSON.pretty_generate(data)})"
|
96
|
+
say_error e
|
97
|
+
raise
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_permission_set(data)
|
102
|
+
begin
|
103
|
+
return @sdk.create_permission_set(data)&.to_attrs
|
104
|
+
rescue LookerSDK::Error => e
|
105
|
+
say_error "Error calling create_permission_set(#{JSON.pretty_generate(data)})"
|
106
|
+
say_error e
|
107
|
+
raise
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete_permission_set(permission_set_id)
|
112
|
+
begin
|
113
|
+
return @sdk.delete_permission_set(permission_set_id)
|
114
|
+
rescue LookerSDK::Error => e
|
115
|
+
say_error "Error calling delete_permission_set(#{permission_set_id}})"
|
116
|
+
say_error e
|
117
|
+
raise
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/gzr/modules/role.rb
CHANGED
@@ -53,6 +53,18 @@ module Gzr
|
|
53
53
|
end
|
54
54
|
data
|
55
55
|
end
|
56
|
+
def trim_role(data)
|
57
|
+
trimmed = data.select do |k,v|
|
58
|
+
(keys_to_keep('create_role') + [:id]).include? k
|
59
|
+
end
|
60
|
+
trimmed[:permission_set] = data[:permission_set].select do |k,v|
|
61
|
+
(keys_to_keep('create_permission_set') + [:id,:built_in,:all_access]).include? k
|
62
|
+
end
|
63
|
+
trimmed[:model_set] = data[:model_set].select do |k,v|
|
64
|
+
(keys_to_keep('create_model_set') + [:id,:built_in,:all_access]).include? k
|
65
|
+
end
|
66
|
+
trimmed
|
67
|
+
end
|
56
68
|
def delete_role(role_id)
|
57
69
|
data = nil
|
58
70
|
begin
|
@@ -124,5 +136,16 @@ module Gzr
|
|
124
136
|
end
|
125
137
|
data
|
126
138
|
end
|
139
|
+
def create_role(name,pset,mset)
|
140
|
+
req = { name: name, permission_set_id: pset, model_set_id: mset }
|
141
|
+
begin
|
142
|
+
return @sdk.create_role(req)&.to_attrs
|
143
|
+
rescue LookerSDK::Error => e
|
144
|
+
say_error "Unable to call create_role(#{JSON.pretty_generate(req)})"
|
145
|
+
say_error e
|
146
|
+
raise
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
127
150
|
end
|
128
151
|
end
|