gazer 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1e108603b48eccf755e49bb74db4f1d3a8095c0
4
- data.tar.gz: c5df7d93f59e9231880904bfa1bcbce1400153e1
3
+ metadata.gz: 87c9fc855fb39c5b2db03afb3495706a6acbc341
4
+ data.tar.gz: 924bf3c6fd99783bd6d94960c9aac2a0404e6c36
5
5
  SHA512:
6
- metadata.gz: 2d22b564ba4fd7ef8f0f98b33fdb0b6d522a77448f7de44e01ec90631c378da4c1f8dedc8df7b509e8bf07fde139ed9470b82be37f14886da9f7f392c4541ae2
7
- data.tar.gz: b9d39d2ce886949c42f5681c23fe795fdce14c211aad94fb3e5ed34f95458eab4a475dfb5082e0725137e17aa77df3ad3775ac0324f28f8332aaae5d4753571d
6
+ metadata.gz: fe576cfebc5fa0f91339c07934818239899d214cb0c738fa3ff403a09129c2d97eb27fa8f5d7ba53d5caa9ba93f8a10f75b09f4490b0418589fa8d2dfeb3146e
7
+ data.tar.gz: 6bd4af2afb618333b1cd5ecff92bb4d4acd03289bcf26aac5f323a98c632e1cafbbc48baa7f8ff70cdbc6d562e5ef57898a56188623192ba01284a1589ff625e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.2.16)
4
+ gazer (0.2.17)
5
5
  looker-sdk (~> 0.0.6)
6
6
  netrc (~> 0.11.0)
7
7
  pastel (~> 0.7.2)
@@ -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]
@@ -36,11 +36,13 @@ module Gzr
36
36
  end
37
37
 
38
38
  def search_looks_by_slug(slug, space_id=nil)
39
- data = nil
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 = nil
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, source_look)
101
- existing_look = search_looks_by_title(source_look[:title], space_id).fetch(0,nil)
102
- slug_used = search_looks_by_slug(source_look[:slug]).fetch(0,nil) if source_look[:slug]
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
- if slug_used then
105
- if existing_look then
106
- if !(existing_look.space_id == slug_used.space_id && existing_look.title == slug_used.title) then
107
- say_warning "slug #{slug_used.slug} already used for look #{slug_used.title} in space #{slug_used.space_id}"
108
- say_warning "look will be imported with new slug"
109
- end
110
- else
111
- say_warning "slug #{slug_used.slug} already used for look #{slug_used.title} in space #{slug_used.space_id}"
112
- say_warning "look will be imported with new slug"
113
- end
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 @options[:force] then
118
- say_ok "Modifying existing Look #{source_look[:title]} in space #{space_id}"
119
- new_look = source_look.select do |k,v|
120
- (keys_to_keep('update_look') - [:space_id,:user_id,:query_id,:slug]).include? k
121
- end
122
- new_look[:slug] = source_look[:slug] unless slug_used
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
- raise Gzr::CLI::Error, "Look #{source_look[:title]} already exists in space #{space_id}\nUse --force if you want to overwrite it"
127
- end
128
- else
129
- new_look = source_look.select do |k,v|
130
- (keys_to_keep('create_look') - [:space_id,:user_id,:query_id,:slug]).include? k
131
- end
132
- new_look[:slug] = source_look[:slug] unless slug_used
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
- return create_look(new_look)
152
+ return create_look(new_look)
138
153
  end
139
154
  end
140
155
 
data/lib/gzr/version.rb CHANGED
@@ -20,5 +20,5 @@
20
20
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  module Gzr
23
- VERSION = "0.2.16"
23
+ VERSION = "0.2.17"
24
24
  end
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.16
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-29 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-reader