gazer 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +35 -0
  8. data/Gemfile.lock +150 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +527 -0
  11. data/Rakefile +27 -0
  12. data/bin/console +35 -0
  13. data/bin/setup +30 -0
  14. data/exe/gzr +40 -0
  15. data/gzr.gemspec +67 -0
  16. data/lib/gzr.rb +25 -0
  17. data/lib/gzr/cli.rb +86 -0
  18. data/lib/gzr/command.rb +251 -0
  19. data/lib/gzr/commands/.gitkeep +1 -0
  20. data/lib/gzr/commands/connection.rb +69 -0
  21. data/lib/gzr/commands/connection/dialects.rb +72 -0
  22. data/lib/gzr/commands/connection/ls.rb +72 -0
  23. data/lib/gzr/commands/dashboard.rb +75 -0
  24. data/lib/gzr/commands/dashboard/cat.rb +67 -0
  25. data/lib/gzr/commands/dashboard/import.rb +256 -0
  26. data/lib/gzr/commands/dashboard/rm.rb +47 -0
  27. data/lib/gzr/commands/group.rb +87 -0
  28. data/lib/gzr/commands/group/ls.rb +73 -0
  29. data/lib/gzr/commands/group/member_groups.rb +74 -0
  30. data/lib/gzr/commands/group/member_users.rb +74 -0
  31. data/lib/gzr/commands/look.rb +75 -0
  32. data/lib/gzr/commands/look/cat.rb +55 -0
  33. data/lib/gzr/commands/look/import.rb +62 -0
  34. data/lib/gzr/commands/look/rm.rb +47 -0
  35. data/lib/gzr/commands/model.rb +51 -0
  36. data/lib/gzr/commands/model/ls.rb +72 -0
  37. data/lib/gzr/commands/plan.rb +149 -0
  38. data/lib/gzr/commands/plan/cat.rb +52 -0
  39. data/lib/gzr/commands/plan/disable.rb +49 -0
  40. data/lib/gzr/commands/plan/enable.rb +49 -0
  41. data/lib/gzr/commands/plan/failures.rb +98 -0
  42. data/lib/gzr/commands/plan/import.rb +69 -0
  43. data/lib/gzr/commands/plan/ls.rb +102 -0
  44. data/lib/gzr/commands/plan/rm.rb +47 -0
  45. data/lib/gzr/commands/plan/run.rb +58 -0
  46. data/lib/gzr/commands/query.rb +49 -0
  47. data/lib/gzr/commands/query/runquery.rb +102 -0
  48. data/lib/gzr/commands/role.rb +163 -0
  49. data/lib/gzr/commands/role/cat.rb +52 -0
  50. data/lib/gzr/commands/role/group_add.rb +51 -0
  51. data/lib/gzr/commands/role/group_ls.rb +76 -0
  52. data/lib/gzr/commands/role/group_rm.rb +51 -0
  53. data/lib/gzr/commands/role/ls.rb +75 -0
  54. data/lib/gzr/commands/role/rm.rb +47 -0
  55. data/lib/gzr/commands/role/user_add.rb +51 -0
  56. data/lib/gzr/commands/role/user_ls.rb +76 -0
  57. data/lib/gzr/commands/role/user_rm.rb +51 -0
  58. data/lib/gzr/commands/space.rb +137 -0
  59. data/lib/gzr/commands/space/cat.rb +53 -0
  60. data/lib/gzr/commands/space/create.rb +50 -0
  61. data/lib/gzr/commands/space/export.rb +117 -0
  62. data/lib/gzr/commands/space/ls.rb +97 -0
  63. data/lib/gzr/commands/space/rm.rb +56 -0
  64. data/lib/gzr/commands/space/top.rb +62 -0
  65. data/lib/gzr/commands/space/tree.rb +79 -0
  66. data/lib/gzr/commands/subcommandbase.rb +41 -0
  67. data/lib/gzr/commands/user.rb +111 -0
  68. data/lib/gzr/commands/user/cat.rb +52 -0
  69. data/lib/gzr/commands/user/disable.rb +47 -0
  70. data/lib/gzr/commands/user/enable.rb +47 -0
  71. data/lib/gzr/commands/user/ls.rb +82 -0
  72. data/lib/gzr/commands/user/me.rb +66 -0
  73. data/lib/gzr/modules/connection.rb +52 -0
  74. data/lib/gzr/modules/dashboard.rb +215 -0
  75. data/lib/gzr/modules/filehelper.rb +81 -0
  76. data/lib/gzr/modules/group.rb +93 -0
  77. data/lib/gzr/modules/look.rb +162 -0
  78. data/lib/gzr/modules/model.rb +40 -0
  79. data/lib/gzr/modules/plan.rb +216 -0
  80. data/lib/gzr/modules/role.rb +128 -0
  81. data/lib/gzr/modules/session.rb +203 -0
  82. data/lib/gzr/modules/space.rb +160 -0
  83. data/lib/gzr/modules/user.rb +114 -0
  84. data/lib/gzr/templates/.gitkeep +1 -0
  85. data/lib/gzr/templates/connection/dialects/.gitkeep +1 -0
  86. data/lib/gzr/templates/connection/ls/.gitkeep +1 -0
  87. data/lib/gzr/templates/dashboard/cat/.gitkeep +1 -0
  88. data/lib/gzr/templates/dashboard/import/.gitkeep +1 -0
  89. data/lib/gzr/templates/dashboard/rm/.gitkeep +1 -0
  90. data/lib/gzr/templates/group/ls/.gitkeep +1 -0
  91. data/lib/gzr/templates/group/member_groups/.gitkeep +1 -0
  92. data/lib/gzr/templates/group/member_users/.gitkeep +1 -0
  93. data/lib/gzr/templates/look/cat/.gitkeep +1 -0
  94. data/lib/gzr/templates/look/import/.gitkeep +1 -0
  95. data/lib/gzr/templates/look/rm/.gitkeep +1 -0
  96. data/lib/gzr/templates/model/ls/.gitkeep +1 -0
  97. data/lib/gzr/templates/plan/cat/.gitkeep +1 -0
  98. data/lib/gzr/templates/plan/disable/.gitkeep +1 -0
  99. data/lib/gzr/templates/plan/enable/.gitkeep +1 -0
  100. data/lib/gzr/templates/plan/failures/.gitkeep +1 -0
  101. data/lib/gzr/templates/plan/import/.gitkeep +1 -0
  102. data/lib/gzr/templates/plan/ls/.gitkeep +1 -0
  103. data/lib/gzr/templates/plan/rm/.gitkeep +1 -0
  104. data/lib/gzr/templates/plan/run/.gitkeep +1 -0
  105. data/lib/gzr/templates/query/run/.gitkeep +1 -0
  106. data/lib/gzr/templates/role/cat/.gitkeep +1 -0
  107. data/lib/gzr/templates/role/group_add/.gitkeep +1 -0
  108. data/lib/gzr/templates/role/group_ls/.gitkeep +1 -0
  109. data/lib/gzr/templates/role/group_rm/.gitkeep +1 -0
  110. data/lib/gzr/templates/role/ls/.gitkeep +1 -0
  111. data/lib/gzr/templates/role/rm/.gitkeep +1 -0
  112. data/lib/gzr/templates/role/user_add/.gitkeep +1 -0
  113. data/lib/gzr/templates/role/user_ls/.gitkeep +1 -0
  114. data/lib/gzr/templates/role/user_rm/.gitkeep +1 -0
  115. data/lib/gzr/templates/space/cat/.gitkeep +1 -0
  116. data/lib/gzr/templates/space/create/.gitkeep +1 -0
  117. data/lib/gzr/templates/space/export/.gitkeep +1 -0
  118. data/lib/gzr/templates/space/ls/.gitkeep +1 -0
  119. data/lib/gzr/templates/space/rm/.gitkeep +1 -0
  120. data/lib/gzr/templates/space/top/.gitkeep +1 -0
  121. data/lib/gzr/templates/space/tree/.gitkeep +1 -0
  122. data/lib/gzr/templates/user/cat/.gitkeep +1 -0
  123. data/lib/gzr/templates/user/disable/.gitkeep +1 -0
  124. data/lib/gzr/templates/user/enable/.gitkeep +1 -0
  125. data/lib/gzr/templates/user/ls/.gitkeep +1 -0
  126. data/lib/gzr/templates/user/me/.gitkeep +1 -0
  127. data/lib/gzr/version.rb +24 -0
  128. metadata +325 -0
@@ -0,0 +1,49 @@
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/plan'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Plan
30
+ class Enable < Gzr::Command
31
+ include Gzr::Plan
32
+ def initialize(plan_id,options)
33
+ super()
34
+ @plan_id = plan_id
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning("options: #{@options.inspect}") if @options[:debug]
40
+ with_session do
41
+ plan = update_scheduled_plan(@plan_id, { :enabled=>true })
42
+ output.puts "Enabled plan #{plan.id}" unless @options[:plain]
43
+ output.puts plan.id if @options[:plain]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,98 @@
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/plan'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Plan
31
+ class Failures < Gzr::Command
32
+ include Gzr::Plan
33
+ def initialize(options)
34
+ super()
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
+ query = {
42
+ :model=>"i__looker",
43
+ :view=>"scheduled_plan",
44
+ :fields=>[
45
+ "scheduled_plan.id",
46
+ "user.name",
47
+ "scheduled_job.status",
48
+ "scheduled_job.id",
49
+ "scheduled_job.created_time",
50
+ "scheduled_plan.next_run_time"
51
+ ],
52
+ :filters=>{
53
+ "scheduled_job_stage.stage": "execute",
54
+ "scheduled_job.created_time": "1 months",
55
+ "scheduled_plan.run_once": "no"
56
+ },
57
+ :sorts=>[
58
+ "scheduled_plan.id",
59
+ "scheduled_job.created_time desc"
60
+ ],
61
+ :limit=>"5000"
62
+ }
63
+ data = run_inline_query(query)
64
+ fields = query[:fields]
65
+ expressions = fields.collect { |f| "send(\"#{f}\".to_sym)" }
66
+ begin
67
+ say_ok "No plans found in history"
68
+ return nil
69
+ end unless data && data.length > 0
70
+
71
+ table_hash = Hash.new
72
+ table_hash[:header] = fields unless @options[:plain]
73
+ prior_plan_id = nil
74
+ table_hash[:rows] = data.collect do |row|
75
+ next if row.send(:"scheduled_plan.id") == prior_plan_id
76
+ prior_plan_id = row.send(:"scheduled_plan.id")
77
+ next if row.send(:"scheduled_job.status") == 'success'
78
+ expressions.collect do |e|
79
+ eval "row.#{e}"
80
+ end
81
+ end.compact
82
+ table = TTY::Table.new(table_hash)
83
+ alignments = fields.collect do |k|
84
+ (k =~ /(id|count)$/) ? :right : :left
85
+ end
86
+ begin
87
+ if @options[:csv] then
88
+ output.puts render_csv(table)
89
+ else
90
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments)
91
+ end
92
+ end if table
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ 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/plan'
26
+ require_relative '../../modules/user'
27
+ require_relative '../../modules/filehelper'
28
+
29
+ module Gzr
30
+ module Commands
31
+ class Plan
32
+ class Import < Gzr::Command
33
+ include Gzr::Plan
34
+ include Gzr::User
35
+ include Gzr::FileHelper
36
+ def initialize(plan_file, obj_type, obj_id, options)
37
+ super()
38
+ @plan_file = plan_file
39
+ @obj_type = obj_type
40
+ @obj_id = obj_id
41
+ @options = options
42
+ end
43
+
44
+ def execute(input: $stdin, output: $stdout)
45
+ say_warning("options: #{@options.inspect}") if @options[:debug]
46
+ with_session do
47
+
48
+ @me ||= query_me("id")
49
+
50
+
51
+ read_file(@plan_file) do |data|
52
+ plan = nil
53
+ case @obj_type
54
+ when /dashboard/i
55
+ plan = upsert_plan_for_dashboard(@obj_id,@me.id,data)
56
+ when /look/i
57
+ plan = upsert_plan_for_look(@obj_id,@me.id,data)
58
+ else
59
+ raise Gzr::CLI::Error, "Invalid type '#{obj_type}', valid types are look and dashboard"
60
+ end
61
+ output.puts "Imported plan #{plan.id}" unless @options[:plain]
62
+ output.puts plan.id if @options[:plain]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,102 @@
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/plan'
26
+ require 'tty-table'
27
+
28
+ module Gzr
29
+ module Commands
30
+ class Plan
31
+ class Ls < Gzr::Command
32
+ include Gzr::Plan
33
+ def initialize(options)
34
+ super()
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
+ fields = nil
42
+ expressions = nil
43
+ if @options[:disabled] then
44
+ query = {
45
+ :model=>"i__looker",
46
+ :view=>"scheduled_plan",
47
+ :fields=>[
48
+ "scheduled_plan.id",
49
+ "scheduled_plan.enabled",
50
+ "scheduled_plan.name",
51
+ "user.id",
52
+ "user.name",
53
+ "scheduled_plan.look_id",
54
+ "scheduled_plan.dashboard_id",
55
+ "scheduled_plan.lookml_dashboard_id"
56
+ ],
57
+ :filters=>{
58
+ "scheduled_plan.enabled"=>false
59
+ },
60
+ :sorts=>[
61
+ "scheduled_plan.id asc 0"
62
+ ],
63
+ :limit=>"500"
64
+ }
65
+ data = run_inline_query(query)
66
+ fields = query[:fields]
67
+ expressions = fields.collect { |f| "send(\"#{f}\".to_sym)" }
68
+ else
69
+ data = query_all_scheduled_plans("all",@options[:fields])
70
+ fields = field_names(@options[:fields])
71
+ expressions = fields.collect { |fn| field_expression(fn) }
72
+ end
73
+ begin
74
+ say_ok "No plans found"
75
+ return nil
76
+ end unless data && data.length > 0
77
+
78
+ table_hash = Hash.new
79
+ table_hash[:header] = fields unless @options[:plain]
80
+ table_hash[:rows] = data.map do |row|
81
+ expressions.collect do |e|
82
+ eval "row.#{e}"
83
+ end
84
+ end
85
+ table = TTY::Table.new(table_hash)
86
+ alignments = fields.collect do |k|
87
+ next :left if k == "external_group_id"
88
+ (k =~ /(id|count)$/) ? :right : :left
89
+ end
90
+ begin
91
+ if @options[:csv] then
92
+ output.puts render_csv(table)
93
+ else
94
+ output.puts table.render(if @options[:plain] then :basic else :ascii end, alignments: alignments)
95
+ end
96
+ end if table
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,47 @@
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/plan'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Plan
30
+ class Rm < Gzr::Command
31
+ include Gzr::Plan
32
+ def initialize(plan_id, options)
33
+ super()
34
+ @plan_id = plan_id
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning("options: #{@options.inspect}") if @options[:debug]
40
+ with_session do
41
+ delete_scheduled_plan(@plan_id)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,58 @@
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/plan'
26
+
27
+ module Gzr
28
+ module Commands
29
+ class Plan
30
+ class RunIt < Gzr::Command
31
+ include Gzr::Plan
32
+ def initialize(plan_id,options)
33
+ super()
34
+ @plan_id = plan_id
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ say_warning("options: #{@options.inspect}") if @options[:debug]
40
+ with_session do
41
+ plan = query_scheduled_plan(@plan_id)&.to_attrs
42
+ # The api call scheduled_plan_run_once is an odd duck. It accepts
43
+ # the output of any of the calls to retrieve a scheduled plan
44
+ # even though many of the attributes passed are marked read-only.
45
+ # Furthermore, if there is a "secret" - like the password for
46
+ # sftp or s3 - it will match the plan body up with the plan
47
+ # as known in the server and if they are identical apart from
48
+ # the secret, the api will effectively include to secret in order
49
+ # execute the plan.
50
+ plan.delete(:id)
51
+ run_scheduled_plan(plan)
52
+ output.puts "Executed plan #{@plan_id}" unless @options[:plain]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,49 @@
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 'subcommandbase'
25
+
26
+ module Gzr
27
+ module Commands
28
+ class Query < SubCommandBase
29
+
30
+ namespace :query
31
+
32
+ desc 'runquery QUERY_DEF', 'Run query_id, query_slug, or json_query_desc'
33
+ method_option :help, aliases: '-h', type: :boolean,
34
+ desc: 'Display usage information'
35
+ method_option :file, type: :string,
36
+ desc: 'Filename for saved data'
37
+ method_option :format, type: :string, default: 'json',
38
+ desc: 'One of json,json_detail,csv,txt,html,md,xlsx,sql,png,jpg'
39
+ def runquery(query_def)
40
+ if options[:help]
41
+ invoke :help, ['runquery']
42
+ else
43
+ require_relative 'query/runquery'
44
+ Gzr::Commands::Query::RunQuery.new(query_def,options).execute
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end