gazer 0.2.9
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 +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,75 @@
|
|
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 Ls < Gzr::Command
|
32
|
+
include Gzr::Role
|
33
|
+
def initialize(options)
|
34
|
+
super()
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning(@options) if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
data = query_all_roles(@options[:fields])
|
42
|
+
begin
|
43
|
+
say_ok "No roles found"
|
44
|
+
return nil
|
45
|
+
end unless data && data.length > 0
|
46
|
+
|
47
|
+
table_hash = Hash.new
|
48
|
+
fields = field_names(@options[:fields])
|
49
|
+
table_hash[:header] = fields unless @options[:plain]
|
50
|
+
expressions = fields.collect { |fn| field_expression(fn) }
|
51
|
+
table_hash[:rows] = data.map do |row|
|
52
|
+
expressions.collect do |e|
|
53
|
+
v = eval "row.#{e}"
|
54
|
+
next (v.join "\n") if v.kind_of? Array
|
55
|
+
v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
table = TTY::Table.new(table_hash)
|
59
|
+
alignments = fields.collect do |k|
|
60
|
+
next :left if k == "external_group_id"
|
61
|
+
(k =~ /(id|count)$/) ? :right : :left
|
62
|
+
end
|
63
|
+
begin
|
64
|
+
if @options[:csv] then
|
65
|
+
output.puts render_csv(table)
|
66
|
+
else
|
67
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, multiline: true, alignments: alignments)
|
68
|
+
end
|
69
|
+
end if table
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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 Rm < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(role_id,options)
|
33
|
+
super()
|
34
|
+
@role_id = role_id
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
40
|
+
with_session do
|
41
|
+
delete_role(@plan_id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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 UserAdd < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(role_id,users,options)
|
33
|
+
super()
|
34
|
+
@role_id = role_id
|
35
|
+
@users = users.collect { |u| u.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
|
+
users = query_role_users(@role_id, 'id').collect { |u| u.id }
|
44
|
+
users += @users
|
45
|
+
set_role_users(@role_id,users.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 UserLs < 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_users(@role_id,@options[:fields],!@options[:all_users])
|
43
|
+
begin
|
44
|
+
say_ok "No role users 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 UserRm < Gzr::Command
|
31
|
+
include Gzr::Role
|
32
|
+
def initialize(role_id,users,options)
|
33
|
+
super()
|
34
|
+
@role_id = role_id
|
35
|
+
@users = users.collect { |u| u.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
|
+
users = query_role_users(@role_id, 'id').collect { |u| u.id }
|
44
|
+
users -= @users
|
45
|
+
set_role_users(@role_id,users.uniq)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,137 @@
|
|
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 'subcommandbase'
|
25
|
+
|
26
|
+
module Gzr
|
27
|
+
module Commands
|
28
|
+
class Space < SubCommandBase
|
29
|
+
|
30
|
+
namespace :space
|
31
|
+
|
32
|
+
desc 'create NAME PARENT_SPACE', 'Command description...'
|
33
|
+
method_option :help, aliases: '-h', type: :boolean,
|
34
|
+
desc: 'Display usage information'
|
35
|
+
method_option :plain, type: :boolean,
|
36
|
+
desc: 'Provide minimal response information'
|
37
|
+
def create(name, parent_space)
|
38
|
+
if options[:help]
|
39
|
+
invoke :help, ['create']
|
40
|
+
else
|
41
|
+
require_relative 'space/create'
|
42
|
+
Gzr::Commands::Space::Create.new(name, parent_space, options).execute
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'top', 'Retrieve the top level (or root) spaces'
|
47
|
+
method_option :help, aliases: '-h', type: :boolean,
|
48
|
+
desc: 'Display usage information'
|
49
|
+
method_option :plain, type: :boolean, default: false,
|
50
|
+
desc: 'print without any extra formatting'
|
51
|
+
method_option :csv, type: :boolean, default: false,
|
52
|
+
desc: 'output in csv format per RFC4180'
|
53
|
+
def top(*)
|
54
|
+
if options[:help]
|
55
|
+
invoke :help, ['top']
|
56
|
+
else
|
57
|
+
require_relative 'space/top'
|
58
|
+
Gzr::Commands::Space::Top.new(options).execute
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'export SPACE_ID', 'Export a space, including all child looks, dashboards, and spaces.'
|
63
|
+
method_option :help, aliases: '-h', type: :boolean,
|
64
|
+
desc: 'Display usage information'
|
65
|
+
method_option :dir, type: :string, default: '.',
|
66
|
+
desc: 'Directory to store output tree'
|
67
|
+
method_option :tar, type: :string,
|
68
|
+
desc: 'Tar file to store output'
|
69
|
+
method_option :tgz, type: :string,
|
70
|
+
desc: 'TarGZ file to store output'
|
71
|
+
def export(starting_space)
|
72
|
+
if options[:help]
|
73
|
+
invoke :help, ['export']
|
74
|
+
else
|
75
|
+
require_relative 'space/export'
|
76
|
+
Gzr::Commands::Space::Export.new(starting_space,options).execute
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'tree STARTING_SPACE', 'Display the dashbaords, looks, and subspaces or a space in a tree format'
|
81
|
+
method_option :help, aliases: '-h', type: :boolean,
|
82
|
+
desc: 'Display usage information'
|
83
|
+
def tree(starting_space)
|
84
|
+
if options[:help]
|
85
|
+
invoke :help, ['tree']
|
86
|
+
else
|
87
|
+
require_relative 'space/tree'
|
88
|
+
Gzr::Commands::Space::Tree.new(starting_space,options).execute
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'cat SPACE_ID', 'Output the JSON representation of a space to the screen or a file'
|
93
|
+
method_option :help, aliases: '-h', type: :boolean,
|
94
|
+
desc: 'Display usage information'
|
95
|
+
method_option :dir, type: :string,
|
96
|
+
desc: 'Directory to get output file'
|
97
|
+
def cat(space_id)
|
98
|
+
if options[:help]
|
99
|
+
invoke :help, ['cat']
|
100
|
+
else
|
101
|
+
require_relative 'space/cat'
|
102
|
+
Gzr::Commands::Space::Cat.new(space_id,options).execute
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'ls FILTER_SPEC', 'list the contents of a space given by space name, space_id, ~ for the current user\'s default space, or ~name / ~number for the home space of a user'
|
107
|
+
method_option :help, aliases: '-h', type: :boolean,
|
108
|
+
desc: 'Display usage information'
|
109
|
+
method_option :fields, type: :string, default: 'parent_id,id,name,looks(id,title),dashboards(id,title)',
|
110
|
+
desc: 'Fields to display'
|
111
|
+
method_option :plain, type: :boolean, default: false,
|
112
|
+
desc: 'print without any extra formatting'
|
113
|
+
method_option :csv, type: :boolean, default: false,
|
114
|
+
desc: 'output in csv format per RFC4180'
|
115
|
+
def ls(filter_spec=nil)
|
116
|
+
if options[:help]
|
117
|
+
invoke :help, ['ls']
|
118
|
+
else
|
119
|
+
require_relative 'space/ls'
|
120
|
+
Gzr::Commands::Space::Ls.new(filter_spec,options).execute
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc 'rm SPACE_ID', 'Delete a space. The space must be empty or the --force flag specified to deleted subspaces, dashboards, and looks.'
|
125
|
+
method_option :help, aliases: '-h', type: :boolean,
|
126
|
+
desc: 'Display usage information'
|
127
|
+
def rm(space_id)
|
128
|
+
if options[:help]
|
129
|
+
invoke :help, ['rm']
|
130
|
+
else
|
131
|
+
require_relative 'space/rm'
|
132
|
+
Gzr::Commands::Space::Rm.new(space_id,options).execute
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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/space'
|
26
|
+
require_relative '../../modules/filehelper'
|
27
|
+
require 'zlib'
|
28
|
+
|
29
|
+
module Gzr
|
30
|
+
module Commands
|
31
|
+
class Space
|
32
|
+
class Cat < Gzr::Command
|
33
|
+
include Gzr::Space
|
34
|
+
include Gzr::FileHelper
|
35
|
+
def initialize(space_id, options)
|
36
|
+
super()
|
37
|
+
@space_id = space_id
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(input: $stdin, output: $stdout)
|
42
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
43
|
+
with_session do
|
44
|
+
data = query_space(@space_id)
|
45
|
+
write_file(@options[:dir] ? "Space_#{data.id}_#{data.name}.json" : nil, @options[:dir], nil, output) do |f|
|
46
|
+
f.puts JSON.pretty_generate(data.to_attrs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|