gazer 0.2.59 → 0.2.60
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/.github/workflows/lint-pr.yml +17 -0
- data/.github/workflows/release.yml +2 -3
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +6 -5
- data/gzr.gemspec +2 -1
- data/lib/gzr/cli.rb +5 -6
- data/lib/gzr/command.rb +12 -8
- data/lib/gzr/commands/attribute/get_group_value.rb +1 -1
- data/lib/gzr/commands/attribute/set_group_value.rb +1 -1
- data/lib/gzr/commands/dashboard/cat.rb +1 -1
- data/lib/gzr/commands/dashboard/import.rb +33 -26
- data/lib/gzr/commands/dashboard/mv.rb +7 -7
- data/lib/gzr/commands/dashboard.rb +8 -8
- data/lib/gzr/commands/{space → folder}/cat.rb +7 -7
- data/lib/gzr/commands/{space → folder}/create.rb +9 -9
- data/lib/gzr/commands/{space → folder}/export.rb +20 -20
- data/lib/gzr/commands/{space → folder}/ls.rb +11 -11
- data/lib/gzr/commands/{space → folder}/rm.rb +12 -12
- data/lib/gzr/commands/{space → folder}/top.rb +7 -7
- data/lib/gzr/commands/{space → folder}/tree.rb +21 -21
- data/lib/gzr/commands/{space.rb → folder.rb} +28 -28
- data/lib/gzr/commands/group.rb +1 -1
- data/lib/gzr/commands/look/import.rb +3 -3
- data/lib/gzr/commands/look/mv.rb +8 -8
- data/lib/gzr/commands/look.rb +8 -8
- data/lib/gzr/commands/user.rb +2 -2
- data/lib/gzr/modules/dashboard.rb +17 -4
- data/lib/gzr/modules/{space.rb → folder.rb} +38 -38
- data/lib/gzr/modules/look.rb +18 -17
- data/lib/gzr/modules/session.rb +6 -11
- data/lib/gzr/version.rb +1 -1
- metadata +26 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffbe3dcb8878d37708779d3b188b007db7a1fac7807183ccdee7f8e0410dbcf8
|
4
|
+
data.tar.gz: 3feaf5d5dd4d55c3f6844afdf62b86177ab489186c77b54dfcfc81b6b8b59daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e28bcbc38b1f0077d7b4242649524b72db04ba7064add9e296569519bee38b43792f1b80bac96cbcdb4f50bf136aae6aa211c6f92d2a2ebdada43c6b79999fa
|
7
|
+
data.tar.gz: 857b9185b9ce97528befaa636895295bf0a1ff7724fa5b747227198f58324922ac74bf2e113a8d9fb09f420ebdb847fd8525ba2cc56eb3ddd8e574c92fdfb3ae
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: "Lint PR"
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request_target:
|
5
|
+
types:
|
6
|
+
- opened
|
7
|
+
- edited
|
8
|
+
- synchronize
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
main:
|
12
|
+
name: Validate PR title
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
steps:
|
15
|
+
- uses: amannn/action-semantic-pull-request@v5
|
16
|
+
env:
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@@ -11,6 +11,8 @@ jobs:
|
|
11
11
|
release-please:
|
12
12
|
runs-on: ubuntu-latest
|
13
13
|
steps:
|
14
|
+
# Checkout code
|
15
|
+
- uses: actions/checkout@v3
|
14
16
|
- uses: GoogleCloudPlatform/release-please-action@v2
|
15
17
|
id: release
|
16
18
|
with:
|
@@ -20,9 +22,6 @@ jobs:
|
|
20
22
|
bump-patch-for-minor-pre-major: true
|
21
23
|
version-file: "lib/gzr/version.rb"
|
22
24
|
token: ${{ secrets.LOS_AUTO_BOT_RP_TOKEN }}
|
23
|
-
# Checkout code if release was created
|
24
|
-
- uses: actions/checkout@v2
|
25
|
-
if: ${{ steps.release.outputs.release_created }}
|
26
25
|
# Setup ruby if a release was created
|
27
26
|
- uses: ruby/setup-ruby@v1
|
28
27
|
with:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### [0.2.60](https://www.github.com/looker-open-source/gzr/compare/v0.2.59...v0.2.60) (2023-04-11)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* quick typo fixes for API 4.0 changes ([#168](https://www.github.com/looker-open-source/gzr/issues/168)) ([82a634e](https://www.github.com/looker-open-source/gzr/commit/82a634e77de0aaee5bd62c84092e827a2f7f6c73))
|
9
|
+
|
3
10
|
### [0.2.59](https://www.github.com/looker-open-source/gzr/compare/v0.2.58...v0.2.59) (2023-03-29)
|
4
11
|
|
5
12
|
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gazer (0.2.
|
5
|
-
|
4
|
+
gazer (0.2.60)
|
5
|
+
faraday (~> 1.10.3)
|
6
|
+
looker-sdk (~> 0.1.1)
|
6
7
|
net-http-persistent (~> 4.0, >= 4.0.1)
|
7
8
|
netrc (~> 0.11.0)
|
8
9
|
pastel (~> 0.8.0)
|
@@ -42,8 +43,8 @@ GEM
|
|
42
43
|
faraday-patron (1.0.0)
|
43
44
|
faraday-rack (1.0.0)
|
44
45
|
faraday-retry (1.0.3)
|
45
|
-
looker-sdk (0.1.
|
46
|
-
faraday (>= 1.2, <
|
46
|
+
looker-sdk (0.1.4)
|
47
|
+
faraday (>= 1.2, < 3.0)
|
47
48
|
sawyer (~> 0.8)
|
48
49
|
multipart-post (2.3.0)
|
49
50
|
net-http-persistent (4.0.1)
|
@@ -51,7 +52,7 @@ GEM
|
|
51
52
|
netrc (0.11.0)
|
52
53
|
pastel (0.8.0)
|
53
54
|
tty-color (~> 0.5)
|
54
|
-
public_suffix (
|
55
|
+
public_suffix (5.0.1)
|
55
56
|
rake (12.3.3)
|
56
57
|
rspec (3.10.0)
|
57
58
|
rspec-core (~> 3.10.0)
|
data/gzr.gemspec
CHANGED
@@ -59,7 +59,8 @@ Gem::Specification.new do |spec|
|
|
59
59
|
spec.add_runtime_dependency 'thor', '~> 1.1', '>= 1.1.0'
|
60
60
|
spec.add_dependency 'netrc', "~> 0.11.0"
|
61
61
|
spec.add_runtime_dependency 'rubyzip', '~> 1.3', '>= 1.3.0'
|
62
|
-
spec.add_dependency '
|
62
|
+
spec.add_dependency 'faraday', "~> 1.10.3"
|
63
|
+
spec.add_dependency 'looker-sdk', "~> 0.1.1"
|
63
64
|
spec.add_runtime_dependency 'net-http-persistent', '~> 4.0', '>= 4.0.1'
|
64
65
|
|
65
66
|
spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.10'
|
data/lib/gzr/cli.rb
CHANGED
@@ -36,9 +36,8 @@ module Gzr
|
|
36
36
|
class_option :debug, type: :boolean, default: false, desc: 'Run in debug mode'
|
37
37
|
class_option :host, type: :string, default: 'localhost', desc: 'Looker Host'
|
38
38
|
class_option :port, type: :string, default: '19999', desc: 'Looker API Port'
|
39
|
-
class_option :client_id, type: :string, desc: '
|
40
|
-
class_option :client_secret, type: :string, desc: '
|
41
|
-
class_option :api_version, type: :string, desc: 'Looker API Version'
|
39
|
+
class_option :client_id, type: :string, desc: 'API Client Id'
|
40
|
+
class_option :client_secret, type: :string, desc: 'API Client Secret'
|
42
41
|
class_option :ssl, type: :boolean, default: true, desc: 'Use ssl to communicate with host'
|
43
42
|
class_option :verify_ssl, type: :boolean, default: true, desc: 'Verify the SSL certificate of the host'
|
44
43
|
class_option :timeout, type: :numeric, default: 60, desc: 'Seconds to wait for a response from the server'
|
@@ -57,7 +56,7 @@ module Gzr
|
|
57
56
|
puts "v#{Gzr::VERSION}"
|
58
57
|
end
|
59
58
|
map %w(--version -v) => :version
|
60
|
-
map
|
59
|
+
map space: :folder # Alias space command to folder
|
61
60
|
|
62
61
|
require_relative 'commands/attribute'
|
63
62
|
register Gzr::Commands::Attribute, 'attribute', 'attribute [SUBCOMMAND]', 'Command description...'
|
@@ -92,7 +91,7 @@ module Gzr
|
|
92
91
|
require_relative 'commands/look'
|
93
92
|
register Gzr::Commands::Look, 'look', 'look [SUBCOMMAND]', 'Commands pertaining to looks'
|
94
93
|
|
95
|
-
require_relative 'commands/
|
96
|
-
register Gzr::Commands::
|
94
|
+
require_relative 'commands/folder'
|
95
|
+
register Gzr::Commands::Folder, 'folder', 'folder [SUBCOMMAND]', 'Commands pertaining to folders'
|
97
96
|
end
|
98
97
|
end
|
data/lib/gzr/command.rb
CHANGED
@@ -25,6 +25,7 @@ require 'forwardable'
|
|
25
25
|
require 'tty-reader'
|
26
26
|
require 'netrc'
|
27
27
|
require 'looker-sdk'
|
28
|
+
require 'faraday/multipart'
|
28
29
|
|
29
30
|
require_relative 'modules/session'
|
30
31
|
|
@@ -182,7 +183,7 @@ module Gzr
|
|
182
183
|
return
|
183
184
|
end
|
184
185
|
@default_colors=color_palette_lookup!(dcc)
|
185
|
-
say_warning("Default colors #{JSON.pretty_generate @default_colors}") if @options[:debug]
|
186
|
+
#say_warning("Default colors #{JSON.pretty_generate @default_colors}") if @options[:debug]
|
186
187
|
end unless @default_colors
|
187
188
|
|
188
189
|
if obj.respond_to?(:'has_key?') && obj.has_key?(:collection_id) && obj.has_key?(:palette_id)
|
@@ -194,13 +195,13 @@ module Gzr
|
|
194
195
|
|
195
196
|
def color_palette_lookup!(obj)
|
196
197
|
return nil unless obj.respond_to?(:'has_key?')
|
197
|
-
say_warning("performing color_palette_lookup! on #{JSON.pretty_generate obj}") if @options[:debug]
|
198
|
+
#say_warning("performing color_palette_lookup! on #{JSON.pretty_generate obj}") if @options[:debug]
|
198
199
|
palettes = []
|
199
200
|
palettes += obj[:categoricalPalettes] if obj[:categoricalPalettes]
|
200
201
|
palettes += obj[:sequentialPalettes] if obj[:sequentialPalettes]
|
201
202
|
palettes += obj[:divergingPalettes] if obj[:divergingPalettes]
|
202
203
|
obj[:palettes]=palettes
|
203
|
-
say_warning("got palettes #{JSON.pretty_generate palettes}") if @options[:debug]
|
204
|
+
#say_warning("got palettes #{JSON.pretty_generate palettes}") if @options[:debug]
|
204
205
|
obj
|
205
206
|
end
|
206
207
|
|
@@ -211,11 +212,11 @@ module Gzr
|
|
211
212
|
cc = default_colors
|
212
213
|
else
|
213
214
|
o[:collection_default] = false
|
214
|
-
say_ok("looking up color collection by id #{o[:collection_id]}") if @options[:debug]
|
215
|
+
#say_ok("looking up color collection by id #{o[:collection_id]}") if @options[:debug]
|
215
216
|
cc = color_palette_lookup!(color_collection(o[:collection_id]))
|
216
217
|
end
|
217
218
|
return unless cc
|
218
|
-
say_warning("got color collection #{JSON.pretty_generate cc}") if @options[:debug]
|
219
|
+
#say_warning("got color collection #{JSON.pretty_generate cc}") if @options[:debug]
|
219
220
|
o[:collection_label] = cc[:label]
|
220
221
|
ps = cc[:palettes].select { |p| p[:id] == o[:palette_id] }
|
221
222
|
if ps.length > 0
|
@@ -233,11 +234,11 @@ module Gzr
|
|
233
234
|
cc = default_colors
|
234
235
|
if !(force_default && o[:collection_default])
|
235
236
|
# look up color collection by id
|
236
|
-
say_warning("attempting to match palette on id #{o[:collection_id]}") if @options[:debug]
|
237
|
+
#say_warning("attempting to match palette on id #{o[:collection_id]}") if @options[:debug]
|
237
238
|
cc = color_palette_lookup!(color_collection(o[:collection_id]))
|
238
239
|
if cc.nil?
|
239
240
|
# find color collection by name
|
240
|
-
say_warning("no match on id, attempting to match palette on name #{o[:collection_label]}") if @options[:debug]
|
241
|
+
#say_warning("no match on id, attempting to match palette on name #{o[:collection_label]}") if @options[:debug]
|
241
242
|
ccs = all_color_collections()&.select { |cc| o[:collection_label] == cc[:label]}
|
242
243
|
if ccs.nil? || ccs.length == 0
|
243
244
|
# no color collection found. Use default.
|
@@ -291,7 +292,10 @@ module Gzr
|
|
291
292
|
|
292
293
|
say_warning "Expecting exactly one body parameter with a schema for operation #{operation}" unless parameters.length == 1
|
293
294
|
schema_ref = parameters[0][:schema][:$ref].split(/\//)
|
294
|
-
|
295
|
+
key_list = @sdk.swagger[schema_ref[1].to_sym][schema_ref[2].to_sym][:properties].reject { |k,v| v[:readOnly] }.keys
|
296
|
+
say_warning "key_list #{operation} -> #{key_list}" if @options[:debug]
|
297
|
+
return key_list
|
298
|
+
|
295
299
|
end
|
296
300
|
|
297
301
|
##
|
@@ -38,16 +38,16 @@ module Gzr
|
|
38
38
|
include Gzr::User
|
39
39
|
include Gzr::Plan
|
40
40
|
include Gzr::FileHelper
|
41
|
-
def initialize(file,
|
41
|
+
def initialize(file, dest_folder_id, options)
|
42
42
|
super()
|
43
43
|
@file = file
|
44
|
-
@
|
44
|
+
@dest_folder_id = dest_folder_id
|
45
45
|
@options = options
|
46
46
|
end
|
47
47
|
|
48
48
|
def execute(input: $stdin, output: $stdout)
|
49
49
|
say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
|
50
|
-
with_session
|
50
|
+
with_session do
|
51
51
|
|
52
52
|
@me ||= query_me("id")
|
53
53
|
|
@@ -63,7 +63,8 @@ module Gzr
|
|
63
63
|
raise Gzr::CLI::Error, "import file is not a valid dashboard"
|
64
64
|
end
|
65
65
|
|
66
|
-
dashboard = sync_dashboard(data,@
|
66
|
+
dashboard = sync_dashboard(data,@dest_folder_id, output: output)
|
67
|
+
say_warning "dashboard object #{JSON.pretty_generate dashboard.map(&:to_a).to_json}" if @options[:debug]
|
67
68
|
|
68
69
|
dashboard[:dashboard_filters] ||= []
|
69
70
|
source_filters = data[:dashboard_filters].sort { |a,b| a[:row] <=> b[:row] }
|
@@ -79,30 +80,32 @@ module Gzr
|
|
79
80
|
dashboard[:dashboard_elements] ||= []
|
80
81
|
elem_table = data[:dashboard_elements].map do |new_element|
|
81
82
|
element = new_element.select do |k,v|
|
82
|
-
(keys_to_keep('create_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id, :result_maker_id]).include? k
|
83
|
+
(keys_to_keep('create_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id, :result_maker_id, :query, :merge_result]).include? k
|
83
84
|
end
|
84
|
-
(element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element)
|
85
|
-
say_warning "Creating dashboard element #{element.inspect}" if @options[:debug]
|
85
|
+
(element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element)
|
86
|
+
say_warning "Creating dashboard element #{element.select {|k,v| !v.nil?}.inspect}" if @options[:debug]
|
86
87
|
element[:dashboard_id] = dashboard.id
|
87
88
|
result_maker = copy_result_maker_filterables(new_element)
|
88
89
|
element[:result_maker] = result_maker if result_maker
|
89
90
|
dashboard_element = create_dashboard_element(element)
|
91
|
+
say_warning "dashboard_element #{dashboard_element.inspect}" if @options[:debug]
|
90
92
|
dashboard[:dashboard_elements].push dashboard_element
|
91
93
|
[new_element[:id], dashboard_element.id]
|
92
94
|
end
|
93
95
|
|
94
96
|
source_dashboard_layouts = data[:dashboard_layouts].map do |new_layout|
|
95
97
|
layout_obj = nil
|
96
|
-
if new_layout[:active]
|
98
|
+
if new_layout[:active]
|
97
99
|
layout_obj = get_dashboard_layout(dashboard[:dashboard_layouts].first.id)
|
98
100
|
say_warning "Updating layout #{layout_obj.id}" if @options[:debug]
|
99
|
-
else
|
101
|
+
else
|
100
102
|
layout = new_layout.select do |k,v|
|
101
103
|
(keys_to_keep('create_dashboard_layout') - [:dashboard_id]).include? k
|
102
104
|
end
|
103
105
|
layout[:dashboard_id] = dashboard.id
|
104
106
|
say_warning "Creating dashboard layout #{layout}" if @options[:debug]
|
105
107
|
layout_obj = create_dashboard_layout(layout)
|
108
|
+
say_warning "Created dashboard layout #{JSON.pretty_generate layout_obj.map(&:to_a).to_json}" if @options[:debug]
|
106
109
|
end
|
107
110
|
layout_components = new_layout[:dashboard_layout_components].zip(layout_obj.dashboard_layout_components)
|
108
111
|
layout_components.each do |source,target|
|
@@ -121,22 +124,22 @@ module Gzr
|
|
121
124
|
end
|
122
125
|
end
|
123
126
|
upsert_plans_for_dashboard(dashboard.id,@me.id,data[:scheduled_plans]) if data[:scheduled_plans]
|
124
|
-
output.puts "Imported dashboard #{dashboard.id}" unless @options[:plain]
|
125
|
-
output.puts dashboard.id if @options[:plain]
|
127
|
+
output.puts "Imported dashboard #{dashboard.id}" unless @options[:plain]
|
128
|
+
output.puts dashboard.id if @options[:plain]
|
126
129
|
end
|
127
130
|
end
|
128
131
|
end
|
129
132
|
|
130
|
-
def sync_dashboard(source,
|
131
|
-
# try to find dashboard by slug in target
|
132
|
-
existing_dashboard = search_dashboards_by_slug(source[:slug],
|
133
|
-
# check for dash of same title in target
|
134
|
-
title_used = search_dashboards_by_title(source[:title],
|
135
|
-
|
136
|
-
# If there is no match by slug in target space or no slug given, then we match by title
|
133
|
+
def sync_dashboard(source, target_folder_id, output: $stdout)
|
134
|
+
# try to find dashboard by slug in target folder
|
135
|
+
existing_dashboard = search_dashboards_by_slug(source[:slug], target_folder_id).fetch(0,nil) if source[:slug]
|
136
|
+
# check for dash of same title in target folder
|
137
|
+
title_used = search_dashboards_by_title(source[:title], target_folder_id).select {|d| !d[:deleted] }.fetch(0,nil)
|
138
|
+
# If there is no match by slug in target folder or no slug given, then we match by title
|
137
139
|
existing_dashboard ||= title_used
|
140
|
+
say_warning "existing_dashboard object #{existing_dashboard.inspect}" if @options[:debug]
|
138
141
|
|
139
|
-
# same_title is now a flag indicating that there is already a dash in the same
|
142
|
+
# same_title is now a flag indicating that there is already a dash in the same folder with
|
140
143
|
# that title, and it is the one we are updating.
|
141
144
|
same_title = (title_used&.fetch(:id,nil) == existing_dashboard&.fetch(:id,nil))
|
142
145
|
|
@@ -148,18 +151,18 @@ module Gzr
|
|
148
151
|
same_slug = (slug_used&.fetch(:id,nil) == existing_dashboard&.fetch(:id,nil))
|
149
152
|
|
150
153
|
if slug_used && !same_slug then
|
151
|
-
say_warning "slug #{slug_used.slug} already used for dashboard #{slug_used.title} in
|
154
|
+
say_warning "slug #{slug_used.slug} already used for dashboard #{slug_used.title} in folder #{slug_used.folder_id}", output: output
|
152
155
|
say_warning("That dashboard is in the 'Trash' but not fully deleted yet", output: output) if slug_used.deleted
|
153
156
|
say_warning "dashboard will be imported with new slug", output: output
|
154
157
|
end
|
155
158
|
|
156
159
|
if existing_dashboard then
|
157
160
|
if title_used && !same_title then
|
158
|
-
raise Gzr::CLI::Error, "Dashboard #{source[:title]} already exists in
|
161
|
+
raise Gzr::CLI::Error, "Dashboard #{source[:title]} already exists in folder #{target_folder_id}\nDelete it before trying to upate another dashboard to have that title."
|
159
162
|
end
|
160
|
-
raise Gzr::CLI::Error, "Dashboard #{existing_dashboard[:title]} with slug #{existing_dashboard[:slug]} already exists in
|
163
|
+
raise Gzr::CLI::Error, "Dashboard #{existing_dashboard[:title]} with slug #{existing_dashboard[:slug]} already exists in folder #{target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force]
|
161
164
|
|
162
|
-
say_ok "Modifying existing dashboard #{existing_dashboard.id} #{existing_dashboard[:title]} in
|
165
|
+
say_ok "Modifying existing dashboard #{existing_dashboard.id} #{existing_dashboard[:title]} in folder #{target_folder_id}", output: output
|
163
166
|
new_dash = source.select do |k,v|
|
164
167
|
(keys_to_keep('update_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k
|
165
168
|
end
|
@@ -188,9 +191,13 @@ module Gzr
|
|
188
191
|
(keys_to_keep('create_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k
|
189
192
|
end
|
190
193
|
new_dash[:slug] = source[:slug] unless slug_used
|
191
|
-
new_dash[:
|
194
|
+
new_dash[:folder_id] = target_folder_id
|
192
195
|
new_dash[:user_id] = @me.id
|
193
|
-
|
196
|
+
new_dash.select!{|k,v| !v.nil?}
|
197
|
+
say_warning "new dashboard request #{new_dash.inspect}" if @options[:debug]
|
198
|
+
d = create_dashboard(new_dash)
|
199
|
+
say_warning "new dashboard object #{d.inspect}" if @options[:debug]
|
200
|
+
return d
|
194
201
|
end
|
195
202
|
end
|
196
203
|
|
@@ -209,7 +216,7 @@ module Gzr
|
|
209
216
|
end
|
210
217
|
|
211
218
|
def process_dashboard_element(dash_elem)
|
212
|
-
return [nil, upsert_look(@me.id, create_fetch_query(dash_elem[:look][:query]).id, @
|
219
|
+
return [nil, upsert_look(@me.id, create_fetch_query(dash_elem[:look][:query]).id, @dest_folder_id, dash_elem[:look]).id, nil] if dash_elem[:look]
|
213
220
|
|
214
221
|
query = dash_elem[:result_maker]&.fetch(:query, false) || dash_elem[:query]
|
215
222
|
return [create_fetch_query(query).id, nil, nil] if query
|
@@ -30,10 +30,10 @@ module Gzr
|
|
30
30
|
class Dashboard
|
31
31
|
class Mv < Gzr::Command
|
32
32
|
include Gzr::Dashboard
|
33
|
-
def initialize(dashboard_id,
|
33
|
+
def initialize(dashboard_id, target_folder_id, options)
|
34
34
|
super()
|
35
35
|
@dashboard_id = dashboard_id
|
36
|
-
@
|
36
|
+
@target_folder_id = target_folder_id
|
37
37
|
@options = options
|
38
38
|
end
|
39
39
|
|
@@ -44,18 +44,18 @@ module Gzr
|
|
44
44
|
dash = query_dashboard(@dashboard_id)
|
45
45
|
raise Gzr::CLI::Error, "Dashboard with id #{@dashboard_id} does not exist" unless dash
|
46
46
|
|
47
|
-
matching_title = search_dashboards_by_title(dash[:title],@
|
47
|
+
matching_title = search_dashboards_by_title(dash[:title],@target_folder_id)
|
48
48
|
if matching_title.empty? || matching_title.first[:deleted]
|
49
49
|
matching_title = false
|
50
50
|
end
|
51
51
|
|
52
52
|
if matching_title
|
53
|
-
raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in
|
54
|
-
say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in
|
53
|
+
raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force]
|
54
|
+
say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output
|
55
55
|
update_dashboard(matching_title.first[:id],{:deleted=>true})
|
56
56
|
end
|
57
|
-
update_dashboard(dash[:id],{:
|
58
|
-
output.puts "Moved dashboard #{dash[:id]} to
|
57
|
+
update_dashboard(dash[:id],{:folder_id=>@target_folder_id})
|
58
|
+
output.puts "Moved dashboard #{dash[:id]} to folder #{@target_folder_id}" unless @options[:plain]
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -29,17 +29,17 @@ module Gzr
|
|
29
29
|
|
30
30
|
namespace :dashboard
|
31
31
|
|
32
|
-
desc 'mv DASHBOARD_ID
|
32
|
+
desc 'mv DASHBOARD_ID TARGET_FOLDER_ID', 'Move a dashboard to the given folder'
|
33
33
|
method_option :help, aliases: '-h', type: :boolean,
|
34
34
|
desc: 'Display usage information'
|
35
35
|
method_option :force, type: :boolean,
|
36
|
-
desc: 'Overwrite a dashboard with the same name in the target
|
37
|
-
def mv(dashboard_id,
|
36
|
+
desc: 'Overwrite a dashboard with the same name in the target folder'
|
37
|
+
def mv(dashboard_id, target_folder_id)
|
38
38
|
if options[:help]
|
39
39
|
invoke :help, ['mv']
|
40
40
|
else
|
41
41
|
require_relative 'dashboard/mv'
|
42
|
-
Gzr::Commands::Dashboard::Mv.new(dashboard_id,
|
42
|
+
Gzr::Commands::Dashboard::Mv.new(dashboard_id, target_folder_id, options).execute
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -63,19 +63,19 @@ module Gzr
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
desc 'import FILE
|
66
|
+
desc 'import FILE DEST_FOLDER_ID', 'Import a dashboard from a file'
|
67
67
|
method_option :help, aliases: '-h', type: :boolean,
|
68
68
|
desc: 'Display usage information'
|
69
69
|
method_option :plain, type: :boolean,
|
70
70
|
desc: 'Provide minimal response information'
|
71
71
|
method_option :force, type: :boolean,
|
72
|
-
desc: 'Overwrite a dashboard with the same name/slug in the target
|
73
|
-
def import(file,
|
72
|
+
desc: 'Overwrite a dashboard with the same name/slug in the target folder'
|
73
|
+
def import(file,dest_folder_id)
|
74
74
|
if options[:help]
|
75
75
|
invoke :help, ['import']
|
76
76
|
else
|
77
77
|
require_relative 'dashboard/import'
|
78
|
-
Gzr::Commands::Dashboard::Import.new(file,
|
78
|
+
Gzr::Commands::Dashboard::Import.new(file, dest_folder_id, options).execute
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -22,27 +22,27 @@
|
|
22
22
|
# frozen_string_literal: true
|
23
23
|
|
24
24
|
require_relative '../../command'
|
25
|
-
require_relative '../../modules/
|
25
|
+
require_relative '../../modules/folder'
|
26
26
|
require_relative '../../modules/filehelper'
|
27
27
|
require 'zlib'
|
28
28
|
|
29
29
|
module Gzr
|
30
30
|
module Commands
|
31
|
-
class
|
31
|
+
class Folder
|
32
32
|
class Cat < Gzr::Command
|
33
|
-
include Gzr::
|
33
|
+
include Gzr::Folder
|
34
34
|
include Gzr::FileHelper
|
35
|
-
def initialize(
|
35
|
+
def initialize(folder_id, options)
|
36
36
|
super()
|
37
|
-
@
|
37
|
+
@folder_id = folder_id
|
38
38
|
@options = options
|
39
39
|
end
|
40
40
|
|
41
41
|
def execute(input: $stdin, output: $stdout)
|
42
42
|
say_warning("options: #{@options.inspect}") if @options[:debug]
|
43
43
|
with_session do
|
44
|
-
data =
|
45
|
-
write_file(@options[:dir] ? "
|
44
|
+
data = query_folder(@folder_id)
|
45
|
+
write_file(@options[:dir] ? "Folder_#{data.id}_#{data.name}.json" : nil, @options[:dir], nil, output) do |f|
|
46
46
|
f.puts JSON.pretty_generate(data.to_attrs)
|
47
47
|
end
|
48
48
|
end
|
@@ -22,26 +22,26 @@
|
|
22
22
|
# frozen_string_literal: true
|
23
23
|
|
24
24
|
require_relative '../../command'
|
25
|
-
require_relative '../../modules/
|
25
|
+
require_relative '../../modules/folder'
|
26
26
|
|
27
27
|
module Gzr
|
28
28
|
module Commands
|
29
|
-
class
|
29
|
+
class Folder
|
30
30
|
class Create < Gzr::Command
|
31
|
-
include Gzr::
|
32
|
-
def initialize(name,
|
31
|
+
include Gzr::Folder
|
32
|
+
def initialize(name,parent_folder, options)
|
33
33
|
super()
|
34
34
|
@name = name
|
35
|
-
@
|
35
|
+
@parent_folder = parent_folder
|
36
36
|
@options = options
|
37
37
|
end
|
38
38
|
|
39
39
|
def execute(input: $stdin, output: $stdout)
|
40
|
-
|
40
|
+
folder = nil
|
41
41
|
with_session do
|
42
|
-
|
43
|
-
output.puts "Created
|
44
|
-
output.puts
|
42
|
+
folder = create_folder(@name, @parent_folder)
|
43
|
+
output.puts "Created folder #{folder.id}" unless @options[:plain]
|
44
|
+
output.puts folder.id if @options[:plain]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -22,7 +22,7 @@
|
|
22
22
|
# frozen_string_literal: true
|
23
23
|
|
24
24
|
require_relative '../../command'
|
25
|
-
require_relative '../../modules/
|
25
|
+
require_relative '../../modules/folder'
|
26
26
|
require_relative '../../modules/look'
|
27
27
|
require_relative '../../modules/dashboard'
|
28
28
|
require_relative '../../modules/plan'
|
@@ -33,22 +33,22 @@ require 'zip'
|
|
33
33
|
|
34
34
|
module Gzr
|
35
35
|
module Commands
|
36
|
-
class
|
36
|
+
class Folder
|
37
37
|
class Export < Gzr::Command
|
38
|
-
include Gzr::
|
38
|
+
include Gzr::Folder
|
39
39
|
include Gzr::Look
|
40
40
|
include Gzr::Dashboard
|
41
41
|
include Gzr::Plan
|
42
42
|
include Gzr::FileHelper
|
43
|
-
def initialize(
|
43
|
+
def initialize(folder_id, options)
|
44
44
|
super()
|
45
|
-
@
|
45
|
+
@folder_id = folder_id
|
46
46
|
@options = options
|
47
47
|
end
|
48
48
|
|
49
49
|
def execute(input: $stdin, output: $stdout)
|
50
50
|
say_warning("options: #{@options.inspect}") if @options[:debug]
|
51
|
-
with_session
|
51
|
+
with_session do
|
52
52
|
if @options[:tar] || @options[:tgz] || @options[:zip] then
|
53
53
|
arc_path = Pathname.new(@options[:tgz] || @options[:tar] || @options[:zip])
|
54
54
|
arc_path = Pathname.new(File.expand_path(@options[:dir])) + arc_path unless arc_path.absolute?
|
@@ -57,7 +57,7 @@ module Gzr
|
|
57
57
|
tarfile = StringIO.new(String.new,"w") unless @options[:zip]
|
58
58
|
begin
|
59
59
|
tw = Gem::Package::TarWriter.new(tarfile)
|
60
|
-
|
60
|
+
process_folder(@folder_id, tw)
|
61
61
|
tw.flush
|
62
62
|
tarfile.rewind
|
63
63
|
if @options[:tgz]
|
@@ -74,44 +74,44 @@ module Gzr
|
|
74
74
|
else
|
75
75
|
z = Zip::File.new(arc_path.to_path, Zip::File::CREATE, false, continue_on_exists_proc: true)
|
76
76
|
begin
|
77
|
-
|
77
|
+
process_folder(@folder_id, z)
|
78
78
|
ensure
|
79
79
|
z.close
|
80
80
|
end
|
81
81
|
end
|
82
82
|
else
|
83
|
-
|
83
|
+
process_folder(@folder_id, @options[:dir])
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
89
|
-
|
90
|
-
name =
|
91
|
-
name = "nil (#{
|
88
|
+
def process_folder(folder_id, base, rel_path = nil)
|
89
|
+
folder = query_folder(folder_id).to_attrs
|
90
|
+
name = folder[:name]
|
91
|
+
name = "nil (#{folder_id})" if name.nil?
|
92
92
|
path = Pathname.new(name.gsub('/',"\u{2215}"))
|
93
93
|
path = rel_path + path if rel_path
|
94
94
|
|
95
|
-
write_file("
|
96
|
-
f.write JSON.pretty_generate(
|
95
|
+
write_file("Folder_#{folder[:id]}_#{name}.json", base, path) do |f|
|
96
|
+
f.write JSON.pretty_generate(folder.reject do |k,v|
|
97
97
|
[:looks, :dashboards].include?(k)
|
98
98
|
end)
|
99
99
|
end
|
100
|
-
|
100
|
+
folder[:looks].each do |l|
|
101
101
|
look = cat_look(l[:id])
|
102
102
|
write_file("Look_#{look[:id]}_#{look[:title]}.json", base, path) do |f|
|
103
103
|
f.write JSON.pretty_generate(look)
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
folder[:dashboards].each do |d|
|
107
107
|
data = cat_dashboard(d[:id])
|
108
108
|
write_file("Dashboard_#{data[:id]}_#{data[:title]}.json", base, path) do |f|
|
109
109
|
f.write JSON.pretty_generate(data)
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
folder_children = query_folder_children(folder_id)
|
113
|
+
folder_children.each do |child_folder|
|
114
|
+
process_folder(child_folder[:id], base, path)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|