gazer 0.3.1 → 0.3.3
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/CHANGELOG.md +23 -0
- data/Gemfile.lock +1 -1
- data/lib/gzr/cli.rb +12 -1
- data/lib/gzr/command.rb +82 -1
- data/lib/gzr/commands/alert/cat.rb +52 -0
- data/lib/gzr/commands/alert/chown.rb +48 -0
- data/lib/gzr/commands/alert/delete.rb +47 -0
- data/lib/gzr/commands/alert/disable.rb +48 -0
- data/lib/gzr/commands/alert/enable.rb +47 -0
- data/lib/gzr/commands/alert/follow.rb +47 -0
- data/lib/gzr/commands/alert/import.rb +65 -0
- data/lib/gzr/commands/alert/ls.rb +76 -0
- data/lib/gzr/commands/alert/notifications.rb +74 -0
- data/lib/gzr/commands/alert/read.rb +49 -0
- data/lib/gzr/commands/alert/threshold.rb +48 -0
- data/lib/gzr/commands/alert/unfollow.rb +47 -0
- data/lib/gzr/commands/alert.rb +200 -0
- data/lib/gzr/commands/connection/cat.rb +66 -0
- data/lib/gzr/commands/connection/import.rb +78 -0
- data/lib/gzr/commands/connection/rm.rb +50 -0
- data/lib/gzr/commands/connection/test.rb +69 -0
- data/lib/gzr/commands/connection.rb +67 -1
- data/lib/gzr/commands/dashboard/cat.rb +1 -1
- data/lib/gzr/commands/dashboard/import.rb +12 -1
- data/lib/gzr/commands/project/cat.rb +58 -0
- data/lib/gzr/commands/project/deploy_key.rb +60 -0
- data/lib/gzr/commands/project/import.rb +68 -0
- data/lib/gzr/commands/project/ls.rb +73 -0
- data/lib/gzr/commands/project/update.rb +69 -0
- data/lib/gzr/commands/project.rb +104 -0
- data/lib/gzr/commands/session/get.rb +47 -0
- data/lib/gzr/commands/session/login.rb +50 -0
- data/lib/gzr/commands/session/logout.rb +47 -0
- data/lib/gzr/commands/session/update.rb +51 -0
- data/lib/gzr/commands/session.rb +76 -0
- data/lib/gzr/modules/alert.rb +169 -0
- data/lib/gzr/modules/connection.rb +80 -0
- data/lib/gzr/modules/dashboard.rb +23 -2
- data/lib/gzr/modules/project.rb +106 -0
- data/lib/gzr/modules/session.rb +81 -7
- data/lib/gzr/version.rb +1 -1
- metadata +32 -2
data/lib/gzr/modules/session.rb
CHANGED
@@ -55,6 +55,38 @@ module Gzr
|
|
55
55
|
!versions.drop_while {|v| v < minimum_version}.reverse.drop_while {|v| v > given_version}.empty?
|
56
56
|
end
|
57
57
|
|
58
|
+
def token_file
|
59
|
+
"#{ENV["HOME"]}/.gzr_auth"
|
60
|
+
end
|
61
|
+
|
62
|
+
def read_token_data
|
63
|
+
return nil unless File.exist?(token_file)
|
64
|
+
s = File.stat(token_file)
|
65
|
+
if !(s.mode.to_s(8)[3..5] == "600")
|
66
|
+
say_error "#{token_file} mode is #{s.mode.to_s(8)[3..5]}. It must be 600. Ignoring."
|
67
|
+
return nil
|
68
|
+
end
|
69
|
+
token_data = nil
|
70
|
+
file = nil
|
71
|
+
begin
|
72
|
+
file = File.open(token_file)
|
73
|
+
token_data = JSON.parse(file.read,{:symbolize_names => true})
|
74
|
+
ensure
|
75
|
+
file.close if file
|
76
|
+
end
|
77
|
+
token_data
|
78
|
+
end
|
79
|
+
|
80
|
+
def write_token_data(token_data)
|
81
|
+
file = nil
|
82
|
+
begin
|
83
|
+
file = File.new(token_file, "wt")
|
84
|
+
file.chmod(0600)
|
85
|
+
file.write JSON.pretty_generate(token_data)
|
86
|
+
ensure
|
87
|
+
file.close if file
|
88
|
+
end
|
89
|
+
end
|
58
90
|
|
59
91
|
def build_connection_hash(api_version=nil)
|
60
92
|
conn_hash = Hash.new
|
@@ -86,6 +118,9 @@ module Gzr
|
|
86
118
|
}
|
87
119
|
end
|
88
120
|
conn_hash[:user_agent] = "Gazer #{Gzr::VERSION}"
|
121
|
+
|
122
|
+
return conn_hash if @options[:token] || @options[:token_file]
|
123
|
+
|
89
124
|
if @options[:client_id] then
|
90
125
|
conn_hash[:client_id] = @options[:client_id]
|
91
126
|
if @options[:client_secret] then
|
@@ -103,12 +138,14 @@ module Gzr
|
|
103
138
|
end
|
104
139
|
|
105
140
|
def login(min_api_version="4.0")
|
106
|
-
if
|
107
|
-
@options[:client_id]
|
108
|
-
|
141
|
+
if !@options[:token] && !@options[:token_file]
|
142
|
+
if (@options[:client_id].nil? && ENV["LOOKERSDK_CLIENT_ID"])
|
143
|
+
@options[:client_id] = ENV["LOOKERSDK_CLIENT_ID"]
|
144
|
+
end
|
109
145
|
|
110
|
-
|
111
|
-
|
146
|
+
if (@options[:client_secret].nil? && ENV["LOOKERSDK_CLIENT_SECRET"])
|
147
|
+
@options[:client_secret] = ENV["LOOKERSDK_CLIENT_SECRET"]
|
148
|
+
end
|
112
149
|
end
|
113
150
|
|
114
151
|
if (@options[:verify_ssl] && ENV["LOOKERSDK_VERIFY_SSL"])
|
@@ -183,6 +220,31 @@ module Gzr
|
|
183
220
|
@sdk = LookerSDK::Client.new(conn_hash.merge(faraday: faraday)) unless @sdk
|
184
221
|
|
185
222
|
say_ok "check for connectivity: #{@sdk.alive?}" if @options[:debug]
|
223
|
+
if @options[:token_file]
|
224
|
+
entry = read_token_data&.fetch(@options[:host].to_sym,nil)&.fetch(@options[:su]&.to_sym || :default,nil)
|
225
|
+
if entry.nil?
|
226
|
+
say_error "No token found for host #{@options[:host]} and user #{@options[:su] || "default"}"
|
227
|
+
say_error "login with `gzr session login --host #{@options[:host]}` to set a token"
|
228
|
+
raise LookerSDK::Unauthorized.new
|
229
|
+
end
|
230
|
+
(day, time, tz) = entry[:expiration].split(' ')
|
231
|
+
day_parts = day.split('-')
|
232
|
+
time_parts = time.split(':')
|
233
|
+
date_time_parts = day_parts + time_parts + [tz]
|
234
|
+
expiration = Time.new(*date_time_parts)
|
235
|
+
if expiration < (Time.now + 300)
|
236
|
+
if expiration < Time.now
|
237
|
+
say_error "token expired at #{expiration}"
|
238
|
+
else
|
239
|
+
say_error "token expires at #{expiration}, which is in the next 5 minutes"
|
240
|
+
end
|
241
|
+
say_error "login again with `gzr session login --host #{@options[:host]}`"
|
242
|
+
raise LookerSDK::Unauthorized.new
|
243
|
+
end
|
244
|
+
@sdk.access_token = entry[:token]
|
245
|
+
elsif @options[:token]
|
246
|
+
@sdk.access_token = @options[:token]
|
247
|
+
end
|
186
248
|
say_ok "verify authentication: #{@sdk.authenticated?}" if @options[:debug]
|
187
249
|
rescue LookerSDK::Unauthorized => e
|
188
250
|
say_error "Unauthorized - credentials are not valid"
|
@@ -196,7 +258,7 @@ module Gzr
|
|
196
258
|
raise Gzr::CLI::Error, "Invalid credentials" unless @sdk.authenticated?
|
197
259
|
|
198
260
|
|
199
|
-
if @options[:su] then
|
261
|
+
if @options[:su] && !(@options[:token] || @options[:token_file])then
|
200
262
|
say_ok "su to user #{@options[:su]}" if @options[:debug]
|
201
263
|
@access_token_stack.push(@sdk.access_token)
|
202
264
|
begin
|
@@ -247,8 +309,20 @@ module Gzr
|
|
247
309
|
e.backtrace.each { |b| say_error b } if @options[:debug]
|
248
310
|
raise Gzr::CLI::Error, e.message
|
249
311
|
ensure
|
250
|
-
logout_all
|
312
|
+
logout_all unless @options[:token] || @options[:token_file]
|
251
313
|
end
|
252
314
|
end
|
315
|
+
|
316
|
+
def update_auth(workspace_id)
|
317
|
+
body = {}
|
318
|
+
body[:workspace_id] = workspace_id
|
319
|
+
begin
|
320
|
+
return @sdk.update_session(body)&.to_attrs
|
321
|
+
rescue LookerSDK::Error => e
|
322
|
+
say_error "Unable to run update_session(#{JSON.pretty_generate(body)})"
|
323
|
+
say_error e
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
253
327
|
end
|
254
328
|
end
|
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike DeAngelo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-reader
|
@@ -269,6 +269,19 @@ files:
|
|
269
269
|
- lib/gzr/cli.rb
|
270
270
|
- lib/gzr/command.rb
|
271
271
|
- lib/gzr/commands/.gitkeep
|
272
|
+
- lib/gzr/commands/alert.rb
|
273
|
+
- lib/gzr/commands/alert/cat.rb
|
274
|
+
- lib/gzr/commands/alert/chown.rb
|
275
|
+
- lib/gzr/commands/alert/delete.rb
|
276
|
+
- lib/gzr/commands/alert/disable.rb
|
277
|
+
- lib/gzr/commands/alert/enable.rb
|
278
|
+
- lib/gzr/commands/alert/follow.rb
|
279
|
+
- lib/gzr/commands/alert/import.rb
|
280
|
+
- lib/gzr/commands/alert/ls.rb
|
281
|
+
- lib/gzr/commands/alert/notifications.rb
|
282
|
+
- lib/gzr/commands/alert/read.rb
|
283
|
+
- lib/gzr/commands/alert/threshold.rb
|
284
|
+
- lib/gzr/commands/alert/unfollow.rb
|
272
285
|
- lib/gzr/commands/attribute.rb
|
273
286
|
- lib/gzr/commands/attribute/cat.rb
|
274
287
|
- lib/gzr/commands/attribute/create.rb
|
@@ -278,8 +291,12 @@ files:
|
|
278
291
|
- lib/gzr/commands/attribute/rm.rb
|
279
292
|
- lib/gzr/commands/attribute/set_group_value.rb
|
280
293
|
- lib/gzr/commands/connection.rb
|
294
|
+
- lib/gzr/commands/connection/cat.rb
|
281
295
|
- lib/gzr/commands/connection/dialects.rb
|
296
|
+
- lib/gzr/commands/connection/import.rb
|
282
297
|
- lib/gzr/commands/connection/ls.rb
|
298
|
+
- lib/gzr/commands/connection/rm.rb
|
299
|
+
- lib/gzr/commands/connection/test.rb
|
283
300
|
- lib/gzr/commands/dashboard.rb
|
284
301
|
- lib/gzr/commands/dashboard/cat.rb
|
285
302
|
- lib/gzr/commands/dashboard/import.rb
|
@@ -315,6 +332,12 @@ files:
|
|
315
332
|
- lib/gzr/commands/plan/ls.rb
|
316
333
|
- lib/gzr/commands/plan/rm.rb
|
317
334
|
- lib/gzr/commands/plan/run.rb
|
335
|
+
- lib/gzr/commands/project.rb
|
336
|
+
- lib/gzr/commands/project/cat.rb
|
337
|
+
- lib/gzr/commands/project/deploy_key.rb
|
338
|
+
- lib/gzr/commands/project/import.rb
|
339
|
+
- lib/gzr/commands/project/ls.rb
|
340
|
+
- lib/gzr/commands/project/update.rb
|
318
341
|
- lib/gzr/commands/query.rb
|
319
342
|
- lib/gzr/commands/query/runquery.rb
|
320
343
|
- lib/gzr/commands/role.rb
|
@@ -327,6 +350,11 @@ files:
|
|
327
350
|
- lib/gzr/commands/role/user_add.rb
|
328
351
|
- lib/gzr/commands/role/user_ls.rb
|
329
352
|
- lib/gzr/commands/role/user_rm.rb
|
353
|
+
- lib/gzr/commands/session.rb
|
354
|
+
- lib/gzr/commands/session/get.rb
|
355
|
+
- lib/gzr/commands/session/login.rb
|
356
|
+
- lib/gzr/commands/session/logout.rb
|
357
|
+
- lib/gzr/commands/session/update.rb
|
330
358
|
- lib/gzr/commands/subcommandbase.rb
|
331
359
|
- lib/gzr/commands/user.rb
|
332
360
|
- lib/gzr/commands/user/cat.rb
|
@@ -335,6 +363,7 @@ files:
|
|
335
363
|
- lib/gzr/commands/user/enable.rb
|
336
364
|
- lib/gzr/commands/user/ls.rb
|
337
365
|
- lib/gzr/commands/user/me.rb
|
366
|
+
- lib/gzr/modules/alert.rb
|
338
367
|
- lib/gzr/modules/attribute.rb
|
339
368
|
- lib/gzr/modules/connection.rb
|
340
369
|
- lib/gzr/modules/dashboard.rb
|
@@ -345,6 +374,7 @@ files:
|
|
345
374
|
- lib/gzr/modules/model.rb
|
346
375
|
- lib/gzr/modules/permissions.rb
|
347
376
|
- lib/gzr/modules/plan.rb
|
377
|
+
- lib/gzr/modules/project.rb
|
348
378
|
- lib/gzr/modules/role.rb
|
349
379
|
- lib/gzr/modules/session.rb
|
350
380
|
- lib/gzr/modules/user.rb
|