gazer 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +35 -0
- data/Gemfile.lock +150 -0
- data/LICENSE.txt +20 -0
- data/README.md +527 -0
- data/Rakefile +27 -0
- data/bin/console +35 -0
- data/bin/setup +30 -0
- data/exe/gzr +40 -0
- data/gzr.gemspec +67 -0
- data/lib/gzr.rb +25 -0
- data/lib/gzr/cli.rb +86 -0
- data/lib/gzr/command.rb +251 -0
- data/lib/gzr/commands/.gitkeep +1 -0
- data/lib/gzr/commands/connection.rb +69 -0
- data/lib/gzr/commands/connection/dialects.rb +72 -0
- data/lib/gzr/commands/connection/ls.rb +72 -0
- data/lib/gzr/commands/dashboard.rb +75 -0
- data/lib/gzr/commands/dashboard/cat.rb +67 -0
- data/lib/gzr/commands/dashboard/import.rb +256 -0
- data/lib/gzr/commands/dashboard/rm.rb +47 -0
- data/lib/gzr/commands/group.rb +87 -0
- data/lib/gzr/commands/group/ls.rb +73 -0
- data/lib/gzr/commands/group/member_groups.rb +74 -0
- data/lib/gzr/commands/group/member_users.rb +74 -0
- data/lib/gzr/commands/look.rb +75 -0
- data/lib/gzr/commands/look/cat.rb +55 -0
- data/lib/gzr/commands/look/import.rb +62 -0
- data/lib/gzr/commands/look/rm.rb +47 -0
- data/lib/gzr/commands/model.rb +51 -0
- data/lib/gzr/commands/model/ls.rb +72 -0
- data/lib/gzr/commands/plan.rb +149 -0
- data/lib/gzr/commands/plan/cat.rb +52 -0
- data/lib/gzr/commands/plan/disable.rb +49 -0
- data/lib/gzr/commands/plan/enable.rb +49 -0
- data/lib/gzr/commands/plan/failures.rb +98 -0
- data/lib/gzr/commands/plan/import.rb +69 -0
- data/lib/gzr/commands/plan/ls.rb +102 -0
- data/lib/gzr/commands/plan/rm.rb +47 -0
- data/lib/gzr/commands/plan/run.rb +58 -0
- data/lib/gzr/commands/query.rb +49 -0
- data/lib/gzr/commands/query/runquery.rb +102 -0
- data/lib/gzr/commands/role.rb +163 -0
- data/lib/gzr/commands/role/cat.rb +52 -0
- data/lib/gzr/commands/role/group_add.rb +51 -0
- data/lib/gzr/commands/role/group_ls.rb +76 -0
- data/lib/gzr/commands/role/group_rm.rb +51 -0
- data/lib/gzr/commands/role/ls.rb +75 -0
- data/lib/gzr/commands/role/rm.rb +47 -0
- data/lib/gzr/commands/role/user_add.rb +51 -0
- data/lib/gzr/commands/role/user_ls.rb +76 -0
- data/lib/gzr/commands/role/user_rm.rb +51 -0
- data/lib/gzr/commands/space.rb +137 -0
- data/lib/gzr/commands/space/cat.rb +53 -0
- data/lib/gzr/commands/space/create.rb +50 -0
- data/lib/gzr/commands/space/export.rb +117 -0
- data/lib/gzr/commands/space/ls.rb +97 -0
- data/lib/gzr/commands/space/rm.rb +56 -0
- data/lib/gzr/commands/space/top.rb +62 -0
- data/lib/gzr/commands/space/tree.rb +79 -0
- data/lib/gzr/commands/subcommandbase.rb +41 -0
- data/lib/gzr/commands/user.rb +111 -0
- data/lib/gzr/commands/user/cat.rb +52 -0
- data/lib/gzr/commands/user/disable.rb +47 -0
- data/lib/gzr/commands/user/enable.rb +47 -0
- data/lib/gzr/commands/user/ls.rb +82 -0
- data/lib/gzr/commands/user/me.rb +66 -0
- data/lib/gzr/modules/connection.rb +52 -0
- data/lib/gzr/modules/dashboard.rb +215 -0
- data/lib/gzr/modules/filehelper.rb +81 -0
- data/lib/gzr/modules/group.rb +93 -0
- data/lib/gzr/modules/look.rb +162 -0
- data/lib/gzr/modules/model.rb +40 -0
- data/lib/gzr/modules/plan.rb +216 -0
- data/lib/gzr/modules/role.rb +128 -0
- data/lib/gzr/modules/session.rb +203 -0
- data/lib/gzr/modules/space.rb +160 -0
- data/lib/gzr/modules/user.rb +114 -0
- data/lib/gzr/templates/.gitkeep +1 -0
- data/lib/gzr/templates/connection/dialects/.gitkeep +1 -0
- data/lib/gzr/templates/connection/ls/.gitkeep +1 -0
- data/lib/gzr/templates/dashboard/cat/.gitkeep +1 -0
- data/lib/gzr/templates/dashboard/import/.gitkeep +1 -0
- data/lib/gzr/templates/dashboard/rm/.gitkeep +1 -0
- data/lib/gzr/templates/group/ls/.gitkeep +1 -0
- data/lib/gzr/templates/group/member_groups/.gitkeep +1 -0
- data/lib/gzr/templates/group/member_users/.gitkeep +1 -0
- data/lib/gzr/templates/look/cat/.gitkeep +1 -0
- data/lib/gzr/templates/look/import/.gitkeep +1 -0
- data/lib/gzr/templates/look/rm/.gitkeep +1 -0
- data/lib/gzr/templates/model/ls/.gitkeep +1 -0
- data/lib/gzr/templates/plan/cat/.gitkeep +1 -0
- data/lib/gzr/templates/plan/disable/.gitkeep +1 -0
- data/lib/gzr/templates/plan/enable/.gitkeep +1 -0
- data/lib/gzr/templates/plan/failures/.gitkeep +1 -0
- data/lib/gzr/templates/plan/import/.gitkeep +1 -0
- data/lib/gzr/templates/plan/ls/.gitkeep +1 -0
- data/lib/gzr/templates/plan/rm/.gitkeep +1 -0
- data/lib/gzr/templates/plan/run/.gitkeep +1 -0
- data/lib/gzr/templates/query/run/.gitkeep +1 -0
- data/lib/gzr/templates/role/cat/.gitkeep +1 -0
- data/lib/gzr/templates/role/group_add/.gitkeep +1 -0
- data/lib/gzr/templates/role/group_ls/.gitkeep +1 -0
- data/lib/gzr/templates/role/group_rm/.gitkeep +1 -0
- data/lib/gzr/templates/role/ls/.gitkeep +1 -0
- data/lib/gzr/templates/role/rm/.gitkeep +1 -0
- data/lib/gzr/templates/role/user_add/.gitkeep +1 -0
- data/lib/gzr/templates/role/user_ls/.gitkeep +1 -0
- data/lib/gzr/templates/role/user_rm/.gitkeep +1 -0
- data/lib/gzr/templates/space/cat/.gitkeep +1 -0
- data/lib/gzr/templates/space/create/.gitkeep +1 -0
- data/lib/gzr/templates/space/export/.gitkeep +1 -0
- data/lib/gzr/templates/space/ls/.gitkeep +1 -0
- data/lib/gzr/templates/space/rm/.gitkeep +1 -0
- data/lib/gzr/templates/space/top/.gitkeep +1 -0
- data/lib/gzr/templates/space/tree/.gitkeep +1 -0
- data/lib/gzr/templates/user/cat/.gitkeep +1 -0
- data/lib/gzr/templates/user/disable/.gitkeep +1 -0
- data/lib/gzr/templates/user/enable/.gitkeep +1 -0
- data/lib/gzr/templates/user/ls/.gitkeep +1 -0
- data/lib/gzr/templates/user/me/.gitkeep +1 -0
- data/lib/gzr/version.rb +24 -0
- metadata +325 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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 'json'
|
26
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Query
|
30
|
+
class RunQuery < Gzr::Command
|
31
|
+
def initialize(query_def,options)
|
32
|
+
super()
|
33
|
+
@query_def = query_def
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute(input: $stdin, output: $stdout)
|
38
|
+
unless @query_def
|
39
|
+
raise Gzr::CLI::Error, "No query specified. A query id, query slug, or a query in json formation must be specified."
|
40
|
+
end
|
41
|
+
|
42
|
+
case @options[:format]
|
43
|
+
when 'png','jpg','xlsx'
|
44
|
+
raise Gzr::CLI::Error, "Output file must be specified with '--file=filename' when using '--format=#{@options[:format]}" unless @options[:file]
|
45
|
+
when 'json', 'json_detail', 'csv', 'txt', 'html', 'md', 'sql'
|
46
|
+
# these formats can be output to stdout
|
47
|
+
else
|
48
|
+
raise Gzr::CLI::Error, "'--format=#{@options[:format]}' not understood. The format must be one of json,json_detail,csv,txt,html,md,xlsx,sql,png,jpg"
|
49
|
+
end
|
50
|
+
|
51
|
+
case @query_def
|
52
|
+
when /^[0-9]+$/
|
53
|
+
query_id = @query_def.to_i
|
54
|
+
when /^[A-Za-z0-9]+$/
|
55
|
+
query_slug = @query_def
|
56
|
+
else
|
57
|
+
begin
|
58
|
+
query_hash = JSON.parse(@query_def,{:symbolize_names => true})
|
59
|
+
rescue JSON::ParserError => e
|
60
|
+
raise Gzr::CLI::Error, "The query specification is not a valid id, slug, or json document"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
f = File.open(@options[:file], "w") if @options[:file]
|
65
|
+
with_session do
|
66
|
+
if query_id || query_slug then
|
67
|
+
begin
|
68
|
+
@sdk.query(query_id)
|
69
|
+
rescue LookerSDK::NotFound => e
|
70
|
+
raise Gzr::CLI::Error, "Query with the id #{query_id} not found"
|
71
|
+
end if query_id
|
72
|
+
|
73
|
+
begin
|
74
|
+
query_id = @sdk.query_for_slug(query_slug, { :fields => 'id' }).id.to_i
|
75
|
+
rescue LookerSDK::NotFound => e
|
76
|
+
raise Gzr::CLI::Error, "Query with the slug #{query_slug} not found"
|
77
|
+
end if query_slug
|
78
|
+
|
79
|
+
begin
|
80
|
+
@sdk.run_query(query_id,@options[:format]) { |data,progress| (f || output).write(data) }
|
81
|
+
rescue LookerSDK::Error => e
|
82
|
+
say_error "Error in run_query(#{query_id},#{@options[:format]})})"
|
83
|
+
say_error e.message
|
84
|
+
raise
|
85
|
+
end
|
86
|
+
else
|
87
|
+
begin
|
88
|
+
@sdk.run_inline_query(@options[:format],query_hash) { |data,progress| (f || output).write(data) }
|
89
|
+
rescue LookerSDK::Error => e
|
90
|
+
say_error "Error in run_inline_query(#{@options[:format]},#{JSON.pretty_generate(query_hash)})"
|
91
|
+
say_error e.message
|
92
|
+
raise
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
ensure
|
97
|
+
f.close if f
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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 'thor'
|
25
|
+
|
26
|
+
module Gzr
|
27
|
+
module Commands
|
28
|
+
class Role < Thor
|
29
|
+
|
30
|
+
namespace :role
|
31
|
+
|
32
|
+
desc 'group_rm ROLE_ID GROUP_ID GROUP_ID GROUP_ID ...', 'Remove indicated groups from role'
|
33
|
+
method_option :help, aliases: '-h', type: :boolean,
|
34
|
+
desc: 'Display usage information'
|
35
|
+
def group_rm(role_id, *groups)
|
36
|
+
if options[:help]
|
37
|
+
invoke :help, ['group_rm']
|
38
|
+
else
|
39
|
+
require_relative 'role/group_rm'
|
40
|
+
Gzr::Commands::Role::GroupRm.new(role_id, groups, options).execute
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'user_rm ROLE_ID USER_ID USER_ID USER_ID ...', 'Remove indicated users from role'
|
45
|
+
method_option :help, aliases: '-h', type: :boolean,
|
46
|
+
desc: 'Display usage information'
|
47
|
+
def user_rm(role_id,*users)
|
48
|
+
if options[:help]
|
49
|
+
invoke :help, ['user_rm']
|
50
|
+
else
|
51
|
+
require_relative 'role/user_rm'
|
52
|
+
Gzr::Commands::Role::UserRm.new(role_id,users,options).execute
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'group_add ROLE_ID GROUP_ID GROUP_ID GROUP_ID ...', 'Add indicated groups to role'
|
57
|
+
method_option :help, aliases: '-h', type: :boolean,
|
58
|
+
desc: 'Display usage information'
|
59
|
+
def group_add(role_id,*groups)
|
60
|
+
if options[:help]
|
61
|
+
invoke :help, ['group_add']
|
62
|
+
else
|
63
|
+
require_relative 'role/group_add'
|
64
|
+
Gzr::Commands::Role::GroupAdd.new(role_id, groups, options).execute
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'user_add ROLE_ID USER_ID USER_ID USER_ID ...', 'Add indicated users to role'
|
69
|
+
method_option :help, aliases: '-h', type: :boolean,
|
70
|
+
desc: 'Display usage information'
|
71
|
+
def user_add(role_id,*users)
|
72
|
+
if options[:help]
|
73
|
+
invoke :help, ['user_add']
|
74
|
+
else
|
75
|
+
require_relative 'role/user_add'
|
76
|
+
Gzr::Commands::Role::UserAdd.new(role_id,users,options).execute
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'group_ls ROLE_ID', 'List the groups assigned to a role'
|
81
|
+
method_option :help, aliases: '-h', type: :boolean,
|
82
|
+
desc: 'Display usage information'
|
83
|
+
method_option :fields, type: :string, default: 'id,name,external_group_id',
|
84
|
+
desc: 'Fields to display'
|
85
|
+
method_option :plain, type: :boolean, default: false,
|
86
|
+
desc: 'print without any extra formatting'
|
87
|
+
method_option :csv, type: :boolean, default: false,
|
88
|
+
desc: 'output in csv format per RFC4180'
|
89
|
+
def group_ls(role_id)
|
90
|
+
if options[:help]
|
91
|
+
invoke :help, ['group_ls']
|
92
|
+
else
|
93
|
+
require_relative 'role/group_ls'
|
94
|
+
Gzr::Commands::Role::GroupLs.new(role_id,options).execute
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'user_ls ROLE_ID', 'List the users assigned to a role'
|
99
|
+
method_option :help, aliases: '-h', type: :boolean,
|
100
|
+
desc: 'Display usage information'
|
101
|
+
method_option :fields, type: :string, default: 'id,first_name,last_name,email',
|
102
|
+
desc: 'Fields to display'
|
103
|
+
method_option :plain, type: :boolean, default: false,
|
104
|
+
desc: 'print without any extra formatting'
|
105
|
+
method_option :csv, type: :boolean, default: false,
|
106
|
+
desc: 'output in csv format per RFC4180'
|
107
|
+
method_option :all_users, type: :boolean, default: false,
|
108
|
+
desc: 'Show users with this role through a group membership'
|
109
|
+
def user_ls(role_id)
|
110
|
+
if options[:help]
|
111
|
+
invoke :help, ['user_ls']
|
112
|
+
else
|
113
|
+
require_relative 'role/user_ls'
|
114
|
+
Gzr::Commands::Role::UserLs.new(role_id,options).execute
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'rm ROLE_ID', 'Delete a role'
|
119
|
+
method_option :help, aliases: '-h', type: :boolean,
|
120
|
+
desc: 'Display usage information'
|
121
|
+
def rm(role_id)
|
122
|
+
if options[:help]
|
123
|
+
invoke :help, ['rm']
|
124
|
+
else
|
125
|
+
require_relative 'role/rm'
|
126
|
+
Gzr::Commands::Role::Rm.new(role_id,options).execute
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
desc 'cat ROLE_ID', 'Output the JSON representation of a role to screen/file'
|
131
|
+
method_option :help, aliases: '-h', type: :boolean,
|
132
|
+
desc: 'Display usage information'
|
133
|
+
method_option :dir, type: :string,
|
134
|
+
desc: 'Directory to get output file'
|
135
|
+
def cat(role_id)
|
136
|
+
if options[:help]
|
137
|
+
invoke :help, ['cat']
|
138
|
+
else
|
139
|
+
require_relative 'role/cat'
|
140
|
+
Gzr::Commands::Role::Cat.new(role_id,options).execute
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
desc 'ls', 'Display all roles'
|
145
|
+
method_option :help, aliases: '-h', type: :boolean,
|
146
|
+
desc: 'Display usage information'
|
147
|
+
method_option :fields, type: :string, default: 'id,name,permission_set(id,name,permissions),model_set(id,name,models)',
|
148
|
+
desc: 'Fields to display'
|
149
|
+
method_option :plain, type: :boolean, default: false,
|
150
|
+
desc: 'print without any extra formatting'
|
151
|
+
method_option :csv, type: :boolean, default: false,
|
152
|
+
desc: 'output in csv format per RFC4180'
|
153
|
+
def ls(*)
|
154
|
+
if options[:help]
|
155
|
+
invoke :help, ['ls']
|
156
|
+
else
|
157
|
+
require_relative 'role/ls'
|
158
|
+
Gzr::Commands::Role::Ls.new(options).execute
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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
|
+
require_relative '../../modules/filehelper'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Role
|
31
|
+
class Cat < Gzr::Command
|
32
|
+
include Gzr::Role
|
33
|
+
include Gzr::FileHelper
|
34
|
+
def initialize(role_id,options)
|
35
|
+
super()
|
36
|
+
@role_id = role_id
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute(input: $stdin, output: $stdout)
|
41
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
42
|
+
with_session do
|
43
|
+
data = query_role(@role_id)
|
44
|
+
write_file(@options[:dir] ? "Role_#{data.id}_#{data.name}.json" : nil, @options[:dir], nil, output) do |f|
|
45
|
+
f.puts JSON.pretty_generate(data.to_attrs)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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 GroupAdd < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(role_id,groups,options)
|
33
|
+
super()
|
34
|
+
@role_id = role_id
|
35
|
+
@groups = groups.collect { |g| g.to_i }
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
|
42
|
+
with_session do
|
43
|
+
groups = query_role_groups(@role_id, 'id').collect { |g| g.id }
|
44
|
+
groups += @groups
|
45
|
+
set_role_groups(@role_id,groups.uniq)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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
|
+
require 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Role
|
31
|
+
class GroupLs < Gzr::Command
|
32
|
+
include Gzr::Role
|
33
|
+
def initialize(role_id,options)
|
34
|
+
super()
|
35
|
+
@role_id = role_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
|
+
data = query_role_groups(@role_id,@options[:fields])
|
43
|
+
begin
|
44
|
+
say_ok "No role groups found"
|
45
|
+
return nil
|
46
|
+
end unless data && data.length > 0
|
47
|
+
|
48
|
+
table_hash = Hash.new
|
49
|
+
fields = field_names(@options[:fields])
|
50
|
+
table_hash[:header] = fields unless @options[:plain]
|
51
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
52
|
+
table_hash[:rows] = data.map do |row|
|
53
|
+
expressions.collect do |e|
|
54
|
+
v = eval "row.#{e}"
|
55
|
+
next (v.join "\n") if v.kind_of? Array
|
56
|
+
v
|
57
|
+
end
|
58
|
+
end
|
59
|
+
table = TTY::Table.new(table_hash)
|
60
|
+
alignments = fields.collect do |k|
|
61
|
+
next :left if k == "external_group_id"
|
62
|
+
(k =~ /(id|count)$/) ? :right : :left
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
if @options[:csv] then
|
66
|
+
output.puts render_csv(table)
|
67
|
+
else
|
68
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments)
|
69
|
+
end
|
70
|
+
end if table
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
# Copyright (c) 2018 Mike DeAngelo Looker Data Sciences, 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 GroupRm < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(role_id,groups,options)
|
33
|
+
super()
|
34
|
+
@role_id = role_id
|
35
|
+
@groups = groups.collect { |g| g.to_i }
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning(@options) if @options[:debug]
|
41
|
+
|
42
|
+
with_session do
|
43
|
+
groups = query_role_groups(@role_id, 'id').collect { |g| g.id }
|
44
|
+
groups -= @groups
|
45
|
+
set_role_groups(@role_id,groups.uniq)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|