gazer 0.2.16 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/gzr/commands/dashboard/import.rb +2 -2
- data/lib/gzr/commands/look/import.rb +1 -1
- data/lib/gzr/modules/look.rb +47 -32
- data/lib/gzr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87c9fc855fb39c5b2db03afb3495706a6acbc341
|
4
|
+
data.tar.gz: 924bf3c6fd99783bd6d94960c9aac2a0404e6c36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe576cfebc5fa0f91339c07934818239899d214cb0c738fa3ff403a09129c2d97eb27fa8f5d7ba53d5caa9ba93f8a10f75b09f4490b0418589fa8d2dfeb3146e
|
7
|
+
data.tar.gz: 6bd4af2afb618333b1cd5ecff92bb4d4acd03289bcf26aac5f323a98c632e1cafbbc48baa7f8ff70cdbc6d562e5ef57898a56188623192ba01284a1589ff625e
|
data/Gemfile.lock
CHANGED
@@ -123,14 +123,14 @@ module Gzr
|
|
123
123
|
|
124
124
|
say_ok "Modifying existing dashboard #{existing_dashboard.id} #{existing_dashboard[:title]} in space #{target_space_id}", output: output
|
125
125
|
new_dash = source.select do |k,v|
|
126
|
-
(keys_to_keep('update_dashboard') - [:space_id,:user_id,:slug]).include? k
|
126
|
+
(keys_to_keep('update_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k
|
127
127
|
end
|
128
128
|
new_dash[:slug] = source[:slug] unless slug_used
|
129
129
|
new_dash[:deleted] = false if existing_dashboard[:deleted]
|
130
130
|
return update_dashboard(existing_dashboard.id,new_dash)
|
131
131
|
else
|
132
132
|
new_dash = source.select do |k,v|
|
133
|
-
(keys_to_keep('create_dashboard') - [:space_id,:user_id,:slug]).include? k
|
133
|
+
(keys_to_keep('create_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k
|
134
134
|
end
|
135
135
|
new_dash[:slug] = source[:slug] unless slug_used
|
136
136
|
new_dash[:space_id] = target_space_id
|
@@ -49,7 +49,7 @@ module Gzr
|
|
49
49
|
@me ||= query_me("id")
|
50
50
|
|
51
51
|
read_file(@file) do |data|
|
52
|
-
look = upsert_look(@me.id,create_fetch_query(data[:query]).id,@dest_space_id,data)
|
52
|
+
look = upsert_look(@me.id,create_fetch_query(data[:query]).id,@dest_space_id,data,output: output)
|
53
53
|
upsert_plans_for_look(look.id,@me.id,data[:scheduled_plans]) if data[:scheduled_plans]
|
54
54
|
output.puts "Imported look #{look.id}" unless @options[:plain]
|
55
55
|
output.puts look.id if @options[:plain]
|
data/lib/gzr/modules/look.rb
CHANGED
@@ -36,11 +36,13 @@ module Gzr
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def search_looks_by_slug(slug, space_id=nil)
|
39
|
-
data =
|
39
|
+
data = []
|
40
40
|
begin
|
41
41
|
req = { :slug => slug }
|
42
42
|
req[:space_id] = space_id if space_id
|
43
43
|
data = @sdk.search_looks(req)
|
44
|
+
req[:deleted] = true
|
45
|
+
data = @sdk.search_looks(req) if data.empty?
|
44
46
|
rescue LookerSDK::Error => e
|
45
47
|
say_error "Error search_looks_by_slug(#{JSON.pretty_generate(req)})"
|
46
48
|
say_error e.message
|
@@ -50,11 +52,13 @@ module Gzr
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def search_looks_by_title(title, space_id=nil)
|
53
|
-
data =
|
55
|
+
data = []
|
54
56
|
begin
|
55
57
|
req = { :title => title }
|
56
58
|
req[:space_id] = space_id if space_id
|
57
59
|
data = @sdk.search_looks(req)
|
60
|
+
req[:deleted] = true
|
61
|
+
data = @sdk.search_looks(req) if data.empty?
|
58
62
|
rescue LookerSDK::Error => e
|
59
63
|
say_error "Error search_looks_by_title(#{JSON.pretty_generate(req)})"
|
60
64
|
say_error e.message
|
@@ -97,44 +101,55 @@ module Gzr
|
|
97
101
|
data
|
98
102
|
end
|
99
103
|
|
100
|
-
def upsert_look(user_id, query_id, space_id,
|
101
|
-
|
102
|
-
|
104
|
+
def upsert_look(user_id, query_id, space_id, source, output: $stdout)
|
105
|
+
# try to find look by slug in target space
|
106
|
+
existing_look = search_looks_by_slug(source[:slug], space_id).fetch(0,nil) if source[:slug]
|
107
|
+
# check for look of same title in target space
|
108
|
+
title_used = search_looks_by_title(source[:title], space_id).fetch(0,nil)
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
# If there is no match by slug in target space or no slug given, then we match by title
|
111
|
+
existing_look ||= title_used
|
112
|
+
|
113
|
+
# same_title is now a flag indicating that there is already a look in the same space with
|
114
|
+
# that title, and it is the one we are updating.
|
115
|
+
same_title = (title_used&.fetch(:id,nil) == existing_look&.fetch(:id,nil))
|
116
|
+
|
117
|
+
# check if the slug is used by any look
|
118
|
+
slug_used = search_looks_by_slug(source[:slug]).fetch(0,nil) if source[:slug]
|
119
|
+
|
120
|
+
# same_slug is now a flag indicating that there is already a look with
|
121
|
+
# that slug, but it is the one we are updating.
|
122
|
+
same_slug = (slug_used&.fetch(:id,nil) == existing_look&.fetch(:id,nil))
|
123
|
+
|
124
|
+
if slug_used && !same_slug then
|
125
|
+
say_warning "slug #{slug_used.slug} already used for look #{slug_used.title} in space #{slug_used.space_id}", output: output
|
126
|
+
say_warning("That look is in the 'Trash' but not fully deleted yet", output: output) if slug_used.deleted
|
127
|
+
say_warning "look will be imported with new slug", output: output
|
114
128
|
end
|
115
129
|
|
116
130
|
if existing_look then
|
117
|
-
if
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
131
|
+
if title_used && !same_title then
|
132
|
+
raise Gzr::CLI::Error, "Look #{source[:title]} already exists in space #{space_id}\nDelete it before trying to upate another Look to have that title."
|
133
|
+
end
|
134
|
+
raise Gzr::CLI::Error, "Look #{existing_look[:title]} with slug #{existing_look[:slug]} already exists in space #{space_id}\nUse --force if you want to overwrite it" unless @options[:force]
|
135
|
+
say_ok "Modifying existing Look #{existing_look.id} #{existing_look.title} in space #{space_id}", output: output
|
136
|
+
new_look = source.select do |k,v|
|
137
|
+
(keys_to_keep('update_look') - [:space_id,:folder_id,:user_id,:query_id,:slug]).include? k
|
138
|
+
end
|
139
|
+
new_look[:slug] = source[:slug] if source[:slug] && !slug_used
|
140
|
+
new_look[:deleted] = false if existing_look[:deleted]
|
123
141
|
new_look[:query_id] = query_id
|
124
142
|
return update_look(existing_look.id,new_look)
|
125
143
|
else
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
new_look[:query_id] = query_id
|
134
|
-
new_look[:user_id] = user_id
|
135
|
-
new_look[:space_id] = space_id
|
144
|
+
new_look = source.select do |k,v|
|
145
|
+
(keys_to_keep('create_look') - [:space_id,:folder_id,:user_id,:query_id,:slug]).include? k
|
146
|
+
end
|
147
|
+
new_look[:slug] = source[:slug] unless slug_used
|
148
|
+
new_look[:query_id] = query_id
|
149
|
+
new_look[:user_id] = user_id
|
150
|
+
new_look[:space_id] = space_id
|
136
151
|
|
137
|
-
|
152
|
+
return create_look(new_look)
|
138
153
|
end
|
139
154
|
end
|
140
155
|
|
data/lib/gzr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gazer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike DeAngelo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-reader
|