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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/gzr/cli.rb +12 -1
  5. data/lib/gzr/command.rb +82 -1
  6. data/lib/gzr/commands/alert/cat.rb +52 -0
  7. data/lib/gzr/commands/alert/chown.rb +48 -0
  8. data/lib/gzr/commands/alert/delete.rb +47 -0
  9. data/lib/gzr/commands/alert/disable.rb +48 -0
  10. data/lib/gzr/commands/alert/enable.rb +47 -0
  11. data/lib/gzr/commands/alert/follow.rb +47 -0
  12. data/lib/gzr/commands/alert/import.rb +65 -0
  13. data/lib/gzr/commands/alert/ls.rb +76 -0
  14. data/lib/gzr/commands/alert/notifications.rb +74 -0
  15. data/lib/gzr/commands/alert/read.rb +49 -0
  16. data/lib/gzr/commands/alert/threshold.rb +48 -0
  17. data/lib/gzr/commands/alert/unfollow.rb +47 -0
  18. data/lib/gzr/commands/alert.rb +200 -0
  19. data/lib/gzr/commands/connection/cat.rb +66 -0
  20. data/lib/gzr/commands/connection/import.rb +78 -0
  21. data/lib/gzr/commands/connection/rm.rb +50 -0
  22. data/lib/gzr/commands/connection/test.rb +69 -0
  23. data/lib/gzr/commands/connection.rb +67 -1
  24. data/lib/gzr/commands/dashboard/cat.rb +1 -1
  25. data/lib/gzr/commands/dashboard/import.rb +12 -1
  26. data/lib/gzr/commands/project/cat.rb +58 -0
  27. data/lib/gzr/commands/project/deploy_key.rb +60 -0
  28. data/lib/gzr/commands/project/import.rb +68 -0
  29. data/lib/gzr/commands/project/ls.rb +73 -0
  30. data/lib/gzr/commands/project/update.rb +69 -0
  31. data/lib/gzr/commands/project.rb +104 -0
  32. data/lib/gzr/commands/session/get.rb +47 -0
  33. data/lib/gzr/commands/session/login.rb +50 -0
  34. data/lib/gzr/commands/session/logout.rb +47 -0
  35. data/lib/gzr/commands/session/update.rb +51 -0
  36. data/lib/gzr/commands/session.rb +76 -0
  37. data/lib/gzr/modules/alert.rb +169 -0
  38. data/lib/gzr/modules/connection.rb +80 -0
  39. data/lib/gzr/modules/dashboard.rb +23 -2
  40. data/lib/gzr/modules/project.rb +106 -0
  41. data/lib/gzr/modules/session.rb +81 -7
  42. data/lib/gzr/version.rb +1 -1
  43. metadata +32 -2
@@ -0,0 +1,74 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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/alert'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Alert
31
+ class Notifications < Gzr::Command
32
+ include Gzr::Alert
33
+ def initialize(options)
34
+ super()
35
+ @options = options
36
+ @fields = "notification_id,alert_condition_id,user_id,is_read,field_value,threshold_value,ran_at,alert(title,alert_id,investigative_content_id,dashboard_name,dashboard_id,query_slug)"
37
+ end
38
+
39
+ def execute(input: $stdin, output: $stdout)
40
+ say_warning(@options) if @options[:debug]
41
+ with_session do
42
+ data = alert_notifications()
43
+
44
+ begin
45
+ puts "No notifications returned"
46
+ return nil
47
+ end unless data && data.length > 0
48
+
49
+ table_hash = Hash.new
50
+ fields = field_names(@fields)
51
+ table_hash[:header] = fields unless @options[:plain]
52
+ expressions = fields.collect { |fn| field_expression(fn) }
53
+ table_hash[:rows] = data.map do |row|
54
+ expressions.collect do |e|
55
+ eval "row.#{e}"
56
+ end
57
+ end
58
+ table = TTY::Table.new(table_hash)
59
+ alignments = fields.collect do |k|
60
+ (k =~ /id$/) ? :right : :left
61
+ end
62
+ begin
63
+ if @options[:csv] then
64
+ output.puts render_csv(table)
65
+ else
66
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, width: @options[:width] || TTY::Screen.width)
67
+ end
68
+ end if table
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,49 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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/alert'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Alert
30
+ class Read < Gzr::Command
31
+ include Gzr::Alert
32
+ def initialize(notification_id,options)
33
+ super()
34
+ @notification_id = notification_id
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning(@options) if @options[:debug]
40
+ with_session do
41
+ data = read_alert_notification(@notification_id)
42
+ output.puts JSON.pretty_generate(data) unless (data.nil? || data.empty?)
43
+ output.puts "No notification found" if (data.nil? || data.empty?)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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/alert'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Alert
30
+ class Threshold < Gzr::Command
31
+ include Gzr::Alert
32
+ def initialize(alert_id, threshold, options)
33
+ super()
34
+ @alert_id = alert_id
35
+ @threshold = threshold
36
+ @options = options
37
+ end
38
+
39
+ def execute(input: $stdin, output: $stdout)
40
+ say_warning(@options) if @options[:debug]
41
+ with_session do
42
+ update_alert_field(@alert_id, threshold: @threshold)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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/alert'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Alert
30
+ class Unfollow < Gzr::Command
31
+ include Gzr::Alert
32
+ def initialize(alert_id,options)
33
+ super()
34
+ @alert_id = alert_id
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning(@options) if @options[:debug]
40
+ with_session do
41
+ unfollow_alert(@alert_id)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,200 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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 'thor'
25
+
26
+ module Gzr
27
+ module Commands
28
+ class Alert < Thor
29
+
30
+ namespace :alert
31
+
32
+ desc 'ls', 'list alerts'
33
+ method_option :help, aliases: '-h', type: :boolean,
34
+ desc: 'Display usage information'
35
+ method_option :fields, type: :string, default: 'id,field(title,name),comparison_type,threshold,cron,custom_title,dashboard_element_id,description',
36
+ desc: 'Fields to display'
37
+ method_option :disabled, type: :boolean, default: nil,
38
+ desc: 'return disabled alerts'
39
+ method_option :all, type: :boolean, default: nil,
40
+ desc: 'return alerts from all users (must be admin)'
41
+ method_option :plain, type: :boolean, default: false,
42
+ desc: 'print without any extra formatting'
43
+ method_option :csv, type: :boolean, default: false,
44
+ desc: 'output in csv format per RFC4180'
45
+ def ls(*)
46
+ if options[:help]
47
+ invoke :help, ['ls']
48
+ else
49
+ require_relative 'alert/ls'
50
+ Gzr::Commands::Alert::Ls.new(options).execute
51
+ end
52
+ end
53
+
54
+ desc 'cat ALERT_ID', 'Output json information about an alert to screen or file'
55
+ method_option :help, aliases: '-h', type: :boolean,
56
+ desc: 'Display usage information'
57
+ method_option :dir, type: :string,
58
+ desc: 'Directory to store output file'
59
+ def cat(alert_id)
60
+ if options[:help]
61
+ invoke :help, ['cat']
62
+ else
63
+ require_relative 'alert/cat'
64
+ Gzr::Commands::Alert::Cat.new(alert_id,options).execute
65
+ end
66
+ end
67
+
68
+ desc 'follow ALERT_ID', 'Start following the alert given by ALERT_ID'
69
+ method_option :help, aliases: '-h', type: :boolean,
70
+ desc: 'Display usage information'
71
+ def follow_alert(alert_id)
72
+ if options[:help]
73
+ invoke :help, ['follow']
74
+ else
75
+ require_relative 'alert/follow'
76
+ Gzr::Commands::Alert::Follow.new(alert_id,options).execute
77
+ end
78
+ end
79
+
80
+ desc 'unfollow ALERT_ID', 'Stop following the alert given by ALERT_ID'
81
+ method_option :help, aliases: '-h', type: :boolean,
82
+ desc: 'Display usage information'
83
+ def unfollow_alert(alert_id)
84
+ if options[:help]
85
+ invoke :help, ['unfollow']
86
+ else
87
+ require_relative 'alert/unfollow'
88
+ Gzr::Commands::Alert::Unfollow.new(alert_id,options).execute
89
+ end
90
+ end
91
+
92
+ desc 'enable ALERT_ID', 'Enable the alert given by ALERT_ID'
93
+ method_option :help, aliases: '-h', type: :boolean,
94
+ desc: 'Display usage information'
95
+ def enable(alert_id)
96
+ if options[:help]
97
+ invoke :help, ['enable']
98
+ else
99
+ require_relative 'alert/enable'
100
+ Gzr::Commands::Alert::Enable.new(alert_id,options).execute
101
+ end
102
+ end
103
+
104
+ desc 'disable ALERT_ID REASON', 'Disable the alert given by ALERT_ID'
105
+ method_option :help, aliases: '-h', type: :boolean,
106
+ desc: 'Display usage information'
107
+ def disable(alert_id,reason)
108
+ if options[:help]
109
+ invoke :help, ['disable']
110
+ else
111
+ require_relative 'alert/disable'
112
+ Gzr::Commands::Alert::Disable.new(alert_id,reason,options).execute
113
+ end
114
+ end
115
+
116
+ desc 'threshold ALERT_ID THRESHOLD', 'Change the threshold of the alert given by ALERT_ID'
117
+ method_option :help, aliases: '-h', type: :boolean,
118
+ desc: 'Display usage information'
119
+ def threshold(alert_id,threshold)
120
+ if options[:help]
121
+ invoke :help, ['threshold']
122
+ else
123
+ require_relative 'alert/threshold'
124
+ Gzr::Commands::Alert::Threshold.new(alert_id,threshold,options).execute
125
+ end
126
+ end
127
+
128
+ desc 'rm ALERT_ID', 'Delete the alert given by ALERT_ID'
129
+ method_option :help, aliases: '-h', type: :boolean,
130
+ desc: 'Display usage information'
131
+ def rm(alert_id)
132
+ if options[:help]
133
+ invoke :help, ['delete']
134
+ else
135
+ require_relative 'alert/delete'
136
+ Gzr::Commands::Alert::Delete.new(alert_id,options).execute
137
+ end
138
+ end
139
+
140
+ desc 'chown ALERT_ID OWNER_ID', 'Change the owner of the alert given by ALERT_ID to OWNER_ID'
141
+ method_option :help, aliases: '-h', type: :boolean,
142
+ desc: 'Display usage information'
143
+ def chown(alert_id, owner_id)
144
+ if options[:help]
145
+ invoke :help, ['chown']
146
+ else
147
+ require_relative 'alert/chown'
148
+ Gzr::Commands::Alert::Chown.new(alert_id,owner_id,options).execute
149
+ end
150
+ end
151
+
152
+ desc 'notifications', 'Get notifications'
153
+ method_option :help, aliases: '-h', type: :boolean,
154
+ desc: 'Display usage information'
155
+ method_option :plain, type: :boolean, default: false,
156
+ desc: 'print without any extra formatting'
157
+ method_option :csv, type: :boolean, default: false,
158
+ desc: 'output in csv format per RFC4180'
159
+ def notifications(*)
160
+ if options[:help]
161
+ invoke :help, ['notifications']
162
+ else
163
+ require_relative 'alert/notifications'
164
+ Gzr::Commands::Alert::Notifications.new(options).execute
165
+ end
166
+ end
167
+
168
+ desc 'read NOTIFICATION_ID', 'Read notification id'
169
+ method_option :help, aliases: '-h', type: :boolean,
170
+ desc: 'Display usage information'
171
+ method_option :plain, type: :boolean, default: false,
172
+ desc: 'print without any extra formatting'
173
+ method_option :csv, type: :boolean, default: false,
174
+ desc: 'output in csv format per RFC4180'
175
+ def read(notification_id)
176
+ if options[:help]
177
+ invoke :help, ['read']
178
+ else
179
+ require_relative 'alert/read'
180
+ Gzr::Commands::Alert::Read.new(notification_id,options).execute
181
+ end
182
+ end
183
+
184
+ desc 'import FILE [DASHBOARD_ELEMENT_ID]', 'Import an alert from a file'
185
+ method_option :help, aliases: '-h', type: :boolean,
186
+ desc: 'Display usage information'
187
+ method_option :plain, type: :boolean,
188
+ desc: 'Provide minimal response information'
189
+ def import(file,dashboard_element_id=nil)
190
+ if options[:help]
191
+ invoke :help, ['import']
192
+ else
193
+ require_relative 'alert/import'
194
+ Gzr::Commands::Alert::Import.new(file, dashboard_element_id, options).execute
195
+ end
196
+ end
197
+
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,66 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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 'json'
25
+ require_relative '../../command'
26
+ require_relative '../../modules/connection'
27
+ require_relative '../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Connection
32
+ class Cat < Gzr::Command
33
+ include Gzr::Connection
34
+ include Gzr::FileHelper
35
+ def initialize(connection_id,options)
36
+ super()
37
+ @connection_id = connection_id
38
+ @options = options
39
+ end
40
+
41
+ def execute(*args, input: $stdin, output: $stdout)
42
+ say_warning("options: #{@options.inspect}") if @options[:debug]
43
+ with_session do
44
+ data = cat_connection(@connection_id)
45
+ if data.nil?
46
+ say_warning "Connection #{@connection_id} not found"
47
+ return
48
+ end
49
+ data = trim_connection(data) if @options[:trim]
50
+
51
+ outputJSON = JSON.pretty_generate(data)
52
+
53
+ file_name = if @options[:dir]
54
+ @options[:simple_filename] ? "Connection_#{data[:name]}.json" : "Connection_#{data[:name]}_#{data[:dialect_name]}.json"
55
+ else
56
+ nil
57
+ end
58
+ write_file(file_name, @options[:dir], nil, output) do |f|
59
+ f.puts outputJSON
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,78 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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 '../../../gzr'
25
+ require_relative '../../command'
26
+ require_relative '../../modules/connection'
27
+ require_relative '../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Connection
32
+ class Import < Gzr::Command
33
+ include Gzr::Connection
34
+ include Gzr::FileHelper
35
+ def initialize(file, options)
36
+ super()
37
+ @file = file
38
+ @options = options
39
+ end
40
+
41
+ def execute(input: $stdin, output: $stdout)
42
+ say_warning("options: #{@options.inspect}", output: output) if @options[:debug]
43
+ with_session do
44
+ connection = nil
45
+
46
+ if @options[:prompt]
47
+ reader = TTY::Reader.new
48
+ @secret = reader.read_line("Enter your connection password:", echo: false)
49
+ @secret.chomp!
50
+ end
51
+
52
+ read_file(@file) do |data|
53
+ if !!cat_connection(data[:name])
54
+ name = data[:name]
55
+ if !@options[:force]
56
+ raise Gzr::CLI::Error, "Connection #{name} already exists\nUse --force if you want to overwrite it"
57
+ end
58
+ data.select! do |k,v|
59
+ keys_to_keep('update_connection').include? k
60
+ end
61
+ data[:password] = @secret if @secret
62
+ connection = update_connection(name, data)
63
+ else
64
+ data.select! do |k,v|
65
+ keys_to_keep('create_connection').include? k
66
+ end
67
+ data[:password] = @secret if @secret
68
+ connection = create_connection(data)
69
+ end
70
+ output.puts "Imported connection #{connection[:name]}" unless @options[:plain]
71
+ output.puts connection[:id] if @options[:name]
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ # The MIT License (MIT)
2
+
3
+ # Copyright (c) 2023 Mike DeAngelo Google, 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 'json'
25
+ require_relative '../../command'
26
+ require_relative '../../modules/connection'
27
+ require_relative '../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Connection
32
+ class Rm < Gzr::Command
33
+ include Gzr::Connection
34
+ include Gzr::FileHelper
35
+ def initialize(connection_name,options)
36
+ super()
37
+ @connection_name = connection_name
38
+ @options = options
39
+ end
40
+
41
+ def execute(*args, input: $stdin, output: $stdout)
42
+ say_warning("options: #{@options.inspect}") if @options[:debug]
43
+ with_session do
44
+ delete_connection(@connection_name)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,69 @@
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/connection'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Connection
31
+ class Test < Gzr::Command
32
+ include Gzr::Connection
33
+ def initialize(connection_name,options)
34
+ super()
35
+ @connection_name = connection_name
36
+ @options = options
37
+ end
38
+
39
+ def execute(input: $stdin, output: $stdout)
40
+ say_warning(@options) if @options[:debug]
41
+ with_session do
42
+ data = test_connection(@connection_name)
43
+
44
+ table_hash = Hash.new
45
+ fields = field_names(@options[:fields])
46
+ table_hash[:header] = fields unless @options[:plain]
47
+ expressions = fields.collect { |fn| field_expression(fn) }
48
+ table_hash[:rows] = data.map do |row|
49
+ expressions.collect do |e|
50
+ eval "row.#{e}"
51
+ end
52
+ end
53
+ table = TTY::Table.new(table_hash)
54
+ alignments = fields.collect do |k|
55
+ (k =~ /id$/) ? :right : :left
56
+ end
57
+ begin
58
+ if @options[:csv] then
59
+ output.puts render_csv(table)
60
+ else
61
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments, multiline: if @options[:plain] then false else true end, width: @options[:width] || TTY::Screen.width)
62
+ end
63
+ end if table
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end