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,50 @@
|
|
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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Space
|
30
|
+
class Create < Gzr::Command
|
31
|
+
include Gzr::Space
|
32
|
+
def initialize(name,parent_space, options)
|
33
|
+
super()
|
34
|
+
@name = name
|
35
|
+
@parent_space = parent_space
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
space = nil
|
41
|
+
with_session do
|
42
|
+
space = create_space(@name, @parent_space)
|
43
|
+
output.puts "Created space #{space.id}" unless @options[:plain]
|
44
|
+
output.puts space.id if @options[:plain]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,117 @@
|
|
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/look'
|
27
|
+
require_relative '../../modules/dashboard'
|
28
|
+
require_relative '../../modules/filehelper'
|
29
|
+
require 'pathname'
|
30
|
+
require 'stringio'
|
31
|
+
|
32
|
+
module Gzr
|
33
|
+
module Commands
|
34
|
+
class Space
|
35
|
+
class Export < Gzr::Command
|
36
|
+
include Gzr::Space
|
37
|
+
include Gzr::Look
|
38
|
+
include Gzr::Dashboard
|
39
|
+
include Gzr::FileHelper
|
40
|
+
def initialize(space_id, options)
|
41
|
+
super()
|
42
|
+
@space_id = space_id
|
43
|
+
@options = options
|
44
|
+
end
|
45
|
+
|
46
|
+
def execute(input: $stdin, output: $stdout)
|
47
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
48
|
+
with_session("3.1") do
|
49
|
+
if @options[:tar] || @options[:tgz] then
|
50
|
+
arc_path = Pathname.new(@options[:tgz] || @options[:tar])
|
51
|
+
arc_path = Pathname.new(File.expand_path(@options[:dir])) + arc_path unless arc_path.absolute?
|
52
|
+
f = File.open(arc_path.to_path, "wb")
|
53
|
+
tarfile = StringIO.new(String.new,"w")
|
54
|
+
begin
|
55
|
+
tw = Gem::Package::TarWriter.new(tarfile)
|
56
|
+
process_space(@space_id, tw)
|
57
|
+
tw.flush
|
58
|
+
tarfile.rewind
|
59
|
+
if @options[:tgz]
|
60
|
+
gzw = Zlib::GzipWriter.new(f)
|
61
|
+
gzw.write tarfile.string
|
62
|
+
gzw.close
|
63
|
+
else
|
64
|
+
f.write tarfile.string
|
65
|
+
end
|
66
|
+
ensure
|
67
|
+
f.close
|
68
|
+
tarfile.close
|
69
|
+
end
|
70
|
+
else
|
71
|
+
process_space(@space_id, @options[:dir])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def process_space(space_id, base, rel_path = nil)
|
77
|
+
space = query_space(space_id)
|
78
|
+
path = Pathname.new(space.name.gsub('/',"\u{2215}"))
|
79
|
+
path = rel_path + path if rel_path
|
80
|
+
|
81
|
+
write_file("Space_#{space.id}_#{space.name}.json", base, path) do |f|
|
82
|
+
f.write JSON.pretty_generate(space.to_attrs.reject do |k,v|
|
83
|
+
[:looks, :dashboards].include?(k)
|
84
|
+
end)
|
85
|
+
end
|
86
|
+
space.looks.each do |l|
|
87
|
+
look = query_look(l.id)
|
88
|
+
write_file("Look_#{look.id}_#{look.title}.json", base, path) do |f|
|
89
|
+
f.write JSON.pretty_generate(look.to_attrs)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
space.dashboards.each do |d|
|
93
|
+
data = query_dashboard(d.id)
|
94
|
+
data.to_attrs()[:dashboard_elements].each_index do |i|
|
95
|
+
element = data[:dashboard_elements][i]
|
96
|
+
if element[:merge_result_id]
|
97
|
+
merge_result = merge_query(element[:merge_result_id])
|
98
|
+
merge_result[:source_queries].each_index do |j|
|
99
|
+
source_query = merge_result[:source_queries][j]
|
100
|
+
merge_result[:source_queries][j][:query] = query(source_query[:query_id])
|
101
|
+
end
|
102
|
+
data[:dashboard_elements][i][:merge_result] = merge_result
|
103
|
+
end
|
104
|
+
end
|
105
|
+
write_file("Dashboard_#{data.id}_#{data.title}.json", base, path) do |f|
|
106
|
+
f.write JSON.pretty_generate(data.to_attrs)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
space_children = query_space_children(space_id)
|
110
|
+
space_children.each do |child_space|
|
111
|
+
process_space(child_space.id, base, path)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Space
|
31
|
+
class Ls < Gzr::Command
|
32
|
+
include Gzr::Space
|
33
|
+
def initialize(filter_spec, options)
|
34
|
+
super()
|
35
|
+
@filter_spec = filter_spec
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
space_ids = process_args([@filter_spec])
|
43
|
+
begin
|
44
|
+
puts "No spaces match #{@filter_spec}"
|
45
|
+
return nil
|
46
|
+
end unless space_ids && space_ids.length > 0
|
47
|
+
|
48
|
+
data = space_ids.map do |space_id|
|
49
|
+
query_space(space_id, @options[:fields])
|
50
|
+
end.compact
|
51
|
+
|
52
|
+
begin
|
53
|
+
puts "No data returned for spaces #{space_ids.inspect}"
|
54
|
+
return nil
|
55
|
+
end unless data && data.length > 0
|
56
|
+
|
57
|
+
@options[:fields] = 'dashboards(id,title)' if @filter_spec == 'lookml'
|
58
|
+
table_hash = Hash.new
|
59
|
+
fields = field_names(@options[:fields])
|
60
|
+
table_hash[:header] = field_names(@options[:fields]) unless @options[:plain]
|
61
|
+
rows = []
|
62
|
+
data.each do |r|
|
63
|
+
h = r.to_attrs
|
64
|
+
if @filter_spec != 'lookml' then
|
65
|
+
rows << [h[:parent_id],h[:id],h[:name], nil, nil, nil, nil]
|
66
|
+
subspaces = query_space_children(h[:id], "id,name,parent_id")
|
67
|
+
rows += subspaces.map do |r|
|
68
|
+
h1 = r.to_attrs
|
69
|
+
[h1[:parent_id], h1[:id], h1[:name], nil, nil, nil, nil]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
h[:looks].each do |r|
|
73
|
+
rows << [h[:parent_id],h[:id],h[:name], r[:id], r[:title], nil, nil]
|
74
|
+
end if h[:looks]
|
75
|
+
h[:dashboards].each do |r|
|
76
|
+
rows << [h[:parent_id],h[:id],h[:name], nil, nil, r[:id], r[:title]] unless @filter_spec == 'lookml'
|
77
|
+
rows << [r[:id], r[:title]] if @filter_spec == 'lookml'
|
78
|
+
end if h[:dashboards]
|
79
|
+
end
|
80
|
+
table_hash[:rows] = rows
|
81
|
+
table = TTY::Table.new(table_hash) if data[0]
|
82
|
+
alignments = fields.collect do |k|
|
83
|
+
(k =~ /id\)*$/) ? :right : :left
|
84
|
+
end
|
85
|
+
begin
|
86
|
+
if @options[:csv] then
|
87
|
+
output.puts render_csv(table)
|
88
|
+
else
|
89
|
+
output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments)
|
90
|
+
end
|
91
|
+
end if table
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
|
27
|
+
module Gzr
|
28
|
+
module Commands
|
29
|
+
class Space
|
30
|
+
class Rm < Gzr::Command
|
31
|
+
include Gzr::Space
|
32
|
+
def initialize(space,options)
|
33
|
+
super()
|
34
|
+
@space = space
|
35
|
+
@options = options
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(input: $stdin, output: $stdout)
|
39
|
+
with_session do
|
40
|
+
space = query_space(@space)
|
41
|
+
|
42
|
+
begin
|
43
|
+
puts "Space #{@space} not found"
|
44
|
+
return nil
|
45
|
+
end unless space
|
46
|
+
children = query_space_children(@space)
|
47
|
+
unless (space.looks.length == 0 && space.dashboards.length == 0 && children.length == 0) || @options[:force] then
|
48
|
+
raise Gzr::CLI::Error, "Space '#{space.name}' is not empty. Space cannot be deleted unless --force is specified"
|
49
|
+
end
|
50
|
+
delete_space(@space)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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 'tty-table'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Space
|
31
|
+
class Top < Gzr::Command
|
32
|
+
include Gzr::Space
|
33
|
+
def initialize(options)
|
34
|
+
super()
|
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
|
+
spaces = all_spaces("id,name,is_shared_root,is_users_root,is_root,is_user_root,is_embed_shared_root,is_embed_users_root")
|
42
|
+
|
43
|
+
begin
|
44
|
+
puts "No spaces found"
|
45
|
+
return nil
|
46
|
+
end unless spaces && spaces.length > 0
|
47
|
+
|
48
|
+
table = TTY::Table.new(header: spaces[0].to_attrs.keys) do |t|
|
49
|
+
spaces.each do |h|
|
50
|
+
t << h.to_attrs.values if (
|
51
|
+
h.is_shared_root || h.is_users_root || h.is_root ||
|
52
|
+
h.is_user_root || h.is_embed_shared_root || h.is_embed_users_root
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end if spaces[0]
|
56
|
+
output.puts table.render(:ascii, alignments: [:right]) if table
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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 'tty-tree'
|
27
|
+
|
28
|
+
module Gzr
|
29
|
+
module Commands
|
30
|
+
class Space
|
31
|
+
class Tree < Gzr::Command
|
32
|
+
include Gzr::Space
|
33
|
+
def initialize(filter_spec, options)
|
34
|
+
super()
|
35
|
+
@filter_spec = filter_spec
|
36
|
+
@options = options
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(input: $stdin, output: $stdout)
|
40
|
+
say_warning("options: #{@options.inspect}") if @options[:debug]
|
41
|
+
with_session do
|
42
|
+
space_ids = process_args([@filter_spec])
|
43
|
+
|
44
|
+
tree_data = Hash.new
|
45
|
+
|
46
|
+
space_ids.each do |space_id|
|
47
|
+
s = query_space(space_id, "id,name,parent_id,looks(id,title),dashboards(id,title)")
|
48
|
+
space_name = s.name
|
49
|
+
space_name = "nil (#{s.id})" unless space_name
|
50
|
+
space_name = "\"#{space_name}\"" if ((space_name != space_name.strip) || (space_name.length == 0))
|
51
|
+
space_name += " (#{space_id})" unless space_ids.length == 1
|
52
|
+
tree_data[space_name] =
|
53
|
+
[ recurse_spaces(s.id) ] +
|
54
|
+
s.looks.map { |l| "(l) #{l.title}" } +
|
55
|
+
s.dashboards.map { |d| "(d) #{d.title}" }
|
56
|
+
end
|
57
|
+
tree = TTY::Tree.new(tree_data)
|
58
|
+
output.puts tree.render
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def recurse_spaces(space_id)
|
63
|
+
data = query_space_children(space_id, "id,name,parent_id,looks(id,title),dashboards(id,title)")
|
64
|
+
tree_branch = Hash.new
|
65
|
+
data.each do |s|
|
66
|
+
space_name = s.name
|
67
|
+
space_name = "nil (#{s.id})" unless space_name
|
68
|
+
space_name = "\"#{space_name}\"" if ((space_name != space_name.strip) || (space_name.length == 0))
|
69
|
+
tree_branch[space_name] =
|
70
|
+
[ recurse_spaces(s.id) ] +
|
71
|
+
s.looks.map { |l| "(l) #{l.title}" } +
|
72
|
+
s.dashboards.map { |d| "(d) #{d.title}" }
|
73
|
+
end
|
74
|
+
tree_branch
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|