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,52 @@
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
+ module Gzr
25
+ module Connection
26
+
27
+ def query_all_connections(fields=nil)
28
+ data = nil
29
+ begin
30
+ data = @sdk.all_connections(fields ? {:fields=>fields} : nil )
31
+ rescue LookerSDK::Error => e
32
+ say_error "Error querying all_connections({:fields=>\"#{fields}\"})"
33
+ say_error e.message
34
+ raise
35
+ end
36
+ data
37
+ end
38
+
39
+ def query_all_dialects(fields=nil)
40
+ data = nil
41
+ begin
42
+ data = @sdk.all_dialect_infos(fields ? {:fields=>fields} : nil )
43
+ rescue LookerSDK::Error => e
44
+ say_error "Error querying all_dialect_infos({:fields=>\"#{fields}\"})"
45
+ say_error e.message
46
+ raise
47
+ end
48
+ data
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,215 @@
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
+ module Gzr
25
+ module Dashboard
26
+ def query_dashboard(dashboard_id)
27
+ data = nil
28
+ begin
29
+ data = @sdk.dashboard(dashboard_id)
30
+ data&.dashboard_filters&.sort! { |a,b| a.row <=> b.row }
31
+ data&.dashboard_layouts&.sort_by! { |v| (v.active ? 0 : 1) }
32
+ rescue LookerSDK::Error => e
33
+ say_error "Error querying dashboard(#{dashboard_id})"
34
+ say_error e.message
35
+ raise
36
+ end
37
+ data
38
+ end
39
+
40
+ def delete_dashboard(dash)
41
+ data = nil
42
+ begin
43
+ data = @sdk.delete_dashboard(dash)
44
+ rescue LookerSDK::Error => e
45
+ say_error "Error deleting dashboard(#{dash})"
46
+ say_error e.message
47
+ raise
48
+ end
49
+ data
50
+ end
51
+
52
+ def search_dashboards_by_slug(slug, space_id=nil)
53
+ data = nil
54
+ begin
55
+ req = { :slug => slug }
56
+ req[:space_id] = space_id if space_id
57
+ data = @sdk.search_dashboards(req)
58
+ rescue LookerSDK::Error => e
59
+ say_error "Error search_dashboards_by_slug(#{JSON.pretty_generate(req)})"
60
+ say_error e.message
61
+ raise
62
+ end
63
+ data
64
+ end
65
+
66
+ def search_dashboards_by_title(title, space_id=nil)
67
+ data = nil
68
+ begin
69
+ req = { :title => title }
70
+ req[:space_id] = space_id if space_id
71
+ data = @sdk.search_dashboards(req)
72
+ rescue LookerSDK::Error => e
73
+ say_error "Error search_dashboards_by_title(#{JSON.pretty_generate(req)})"
74
+ say_error e.message
75
+ raise
76
+ end
77
+ data
78
+ end
79
+
80
+ def create_dashboard(dash)
81
+ begin
82
+ data = @sdk.create_dashboard(dash)
83
+ data&.dashboard_filters&.sort! { |a,b| a.row <=> b.row }
84
+ data&.dashboard_layouts&.sort_by! { |v| (v.active ? 0 : 1) }
85
+ rescue LookerSDK::Error => e
86
+ say_error "Error creating dashboard(#{JSON.pretty_generate(dash)})"
87
+ say_error e.message
88
+ raise
89
+ end
90
+ data
91
+ end
92
+
93
+ def update_dashboard(dash_id,dash)
94
+ begin
95
+ data = @sdk.update_dashboard(dash_id,dash)
96
+ data&.dashboard_filters&.sort! { |a,b| a.row <=> b.row }
97
+ rescue LookerSDK::Error => e
98
+ say_error "Error updating dashboard(#{dash_id},#{JSON.pretty_generate(dash)})"
99
+ say_error e.message
100
+ raise
101
+ end
102
+ data
103
+ end
104
+
105
+ def create_dashboard_element(dash_elem)
106
+ begin
107
+ data = @sdk.create_dashboard_element(dash_elem)
108
+ rescue LookerSDK::Error => e
109
+ say_error "Error creating dashboard_element(#{JSON.pretty_generate(dash_elem)})"
110
+ say_error e.message
111
+ raise
112
+ end
113
+ data
114
+ end
115
+
116
+ def update_dashboard_element(id,dash_elem)
117
+ begin
118
+ data = @sdk.update_dashboard_element(id,dash_elem)
119
+ rescue LookerSDK::Error => e
120
+ say_error "Error updating dashboard_element(#{id},#{JSON.pretty_generate(dash_elem)})"
121
+ say_error e.message
122
+ raise
123
+ end
124
+ data
125
+ end
126
+
127
+ def delete_dashboard_element(id)
128
+ begin
129
+ data = @sdk.delete_dashboard_element(id)
130
+ rescue LookerSDK::Error => e
131
+ say_error "Error deleting dashboard_element(#{id})})"
132
+ say_error e.message
133
+ raise
134
+ end
135
+ data
136
+ end
137
+
138
+ def create_dashboard_layout(dash_layout)
139
+ begin
140
+ data = @sdk.create_dashboard_layout(dash_layout)
141
+ rescue LookerSDK::Error => e
142
+ say_error "Error creating dashboard_layout(#{JSON.pretty_generate(dash_layout)})"
143
+ say_error e.message
144
+ raise
145
+ end
146
+ data
147
+ end
148
+
149
+ def update_dashboard_layout(id,dash_layout)
150
+ begin
151
+ data = @sdk.update_dashboard_layout(id,dash_layout)
152
+ rescue LookerSDK::Error => e
153
+ say_error "Error updating dashboard_layout(#{id},#{JSON.pretty_generate(dash_layout)})"
154
+ say_error e.message
155
+ raise
156
+ end
157
+ data
158
+ end
159
+
160
+ def delete_dashboard_layout(id)
161
+ begin
162
+ data = @sdk.delete_dashboard_layout(id)
163
+ rescue LookerSDK::Error => e
164
+ say_error "Error deleting dashboard_layout(#{id})"
165
+ say_error e.message
166
+ raise
167
+ end
168
+ data
169
+ end
170
+
171
+ def update_dashboard_layout_component(id,component)
172
+ begin
173
+ data = @sdk.update_dashboard_layout_component(id,component)
174
+ rescue LookerSDK::Error => e
175
+ say_error "Error updating dashboard_layout_component(#{id},#{JSON.pretty_generate(component)})"
176
+ say_error e.message
177
+ raise
178
+ end
179
+ data
180
+ end
181
+
182
+ def create_dashboard_filter(dash_filter)
183
+ begin
184
+ data = @sdk.create_dashboard_filter(dash_filter)
185
+ rescue LookerSDK::Error => e
186
+ say_error "Error creating dashboard_filter(#{JSON.pretty_generate(dash_filter)})"
187
+ say_error e.message
188
+ raise
189
+ end
190
+ data
191
+ end
192
+
193
+ def update_dashboard_filter(id,dash_filter)
194
+ begin
195
+ data = @sdk.update_dashboard_filter(id,dash_filter)
196
+ rescue LookerSDK::Error => e
197
+ say_error "Error updating dashboard_filter(#{id},#{JSON.pretty_generate(dash_filter)})"
198
+ say_error e.message
199
+ raise
200
+ end
201
+ data
202
+ end
203
+
204
+ def delete_dashboard_filter(id)
205
+ begin
206
+ data = @sdk.delete_dashboard_filter(id)
207
+ rescue LookerSDK::Error => e
208
+ say_error "Error deleting dashboard_filter(#{id})})"
209
+ say_error e.message
210
+ raise
211
+ end
212
+ data
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,81 @@
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 'pathname'
25
+ require 'rubygems/package'
26
+
27
+ module Gzr
28
+ module FileHelper
29
+ def write_file(file_name=nil,base_dir=nil,path=nil,output=$stdout)
30
+ f = nil
31
+ if base_dir.respond_to?(:mkdir)&& base_dir.respond_to?(:add_file) then
32
+ if path then
33
+ @archived_paths ||= Array.new
34
+ base_dir.mkdir(path.to_path, 0755) unless @archived_paths.include?(path.to_path)
35
+ @archived_paths << path.to_path
36
+ end
37
+ fn = Pathname.new(file_name.gsub('/',"\u{2215}"))
38
+ fn = path + fn if path
39
+ base_dir.add_file(fn.to_path, 0644) do |tf|
40
+ yield tf
41
+ end
42
+ return
43
+ end
44
+
45
+ base = Pathname.new(File.expand_path(base_dir)) if base_dir
46
+ begin
47
+ p = Pathname.new(path) if path
48
+ p.descend do |path_part|
49
+ test_dir = base + Pathname.new(path_part)
50
+ Dir.mkdir(test_dir) unless (test_dir.exist? && test_dir.directory?)
51
+ end if p
52
+ file = Pathname.new(file_name.gsub('/',"\u{2215}")) if file_name
53
+ file = p + file if p
54
+ file = base + file if base
55
+ f = File.open(file, "wt") if file
56
+ end if base
57
+
58
+ return ( f || output ) unless block_given?
59
+ begin
60
+ yield ( f || output )
61
+ ensure
62
+ f.close if f
63
+ end
64
+ nil
65
+ end
66
+
67
+ def read_file(file_name)
68
+ file = nil
69
+ data_hash = nil
70
+ begin
71
+ file = (file_name.kind_of? StringIO) ? file_name : File.open(file_name)
72
+ data_hash = JSON.parse(file.read,{:symbolize_names => true})
73
+ ensure
74
+ file.close if file
75
+ end
76
+ return (data_hash || {}) unless block_given?
77
+
78
+ yield data_hash || {}
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,93 @@
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
+ module Gzr
25
+ module Group
26
+ def query_all_groups(fields=nil, sorts=nil)
27
+ req = {
28
+ :per_page=>128
29
+ }
30
+ req[:fields] = fields if fields
31
+ req[:sorts] = sorts if sorts
32
+
33
+ data = Array.new
34
+ page = 1
35
+ loop do
36
+ begin
37
+ req[:page] = page
38
+ scratch_data = @sdk.all_groups(req)
39
+ rescue LookerSDK::ClientError => e
40
+ say_error "Unable to get all_groups(#{JSON.pretty_generate(req)})"
41
+ say_error e.message
42
+ raise
43
+ end
44
+ break if scratch_data.length == 0
45
+ page += 1
46
+ data += scratch_data
47
+ end
48
+ data
49
+ end
50
+
51
+ def query_group_groups(group_id,fields=nil)
52
+ req = { }
53
+ req[:fields] = fields if fields
54
+
55
+ data = Array.new
56
+ begin
57
+ data = @sdk.all_group_groups(group_id,req)
58
+ rescue LookerSDK::NotFound => e
59
+ return []
60
+ rescue LookerSDK::ClientError => e
61
+ say_error "Unable to get all_group_groups(#{group_id},#{JSON.pretty_generate(req)})"
62
+ say_error e.message
63
+ raise
64
+ end
65
+ data
66
+ end
67
+
68
+ def query_group_users(group_id,fields=nil,sorts=nil)
69
+ req = {
70
+ :per_page=>128
71
+ }
72
+ req[:fields] = fields if fields
73
+ req[:sorts] = sorts if sorts
74
+
75
+ data = Array.new
76
+ page = 1
77
+ loop do
78
+ begin
79
+ req[:page] = page
80
+ scratch_data = @sdk.all_group_users(group_id,req)
81
+ rescue LookerSDK::ClientError => e
82
+ say_error "Unable to get all_group_users(#{group_id},#{JSON.pretty_generate(req)})"
83
+ say_error e.message
84
+ raise
85
+ end
86
+ break if scratch_data.length == 0
87
+ page += 1
88
+ data += scratch_data
89
+ end
90
+ data
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,162 @@
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
+ module Gzr
25
+ module Look
26
+ def query_look(look_id)
27
+ data = nil
28
+ begin
29
+ data = @sdk.look(look_id)
30
+ rescue LookerSDK::Error => e
31
+ say_error "Error querying look(#{look_id})"
32
+ say_error e.message
33
+ raise
34
+ end
35
+ data
36
+ end
37
+
38
+ def search_looks_by_slug(slug, space_id=nil)
39
+ data = nil
40
+ begin
41
+ req = { :slug => slug }
42
+ req[:space_id] = space_id if space_id
43
+ data = @sdk.search_looks(req)
44
+ rescue LookerSDK::Error => e
45
+ say_error "Error search_looks_by_slug(#{JSON.pretty_generate(req)})"
46
+ say_error e.message
47
+ raise
48
+ end
49
+ data
50
+ end
51
+
52
+ def search_looks_by_title(title, space_id=nil)
53
+ data = nil
54
+ begin
55
+ req = { :title => title }
56
+ req[:space_id] = space_id if space_id
57
+ data = @sdk.search_looks(req)
58
+ rescue LookerSDK::Error => e
59
+ say_error "Error search_looks_by_title(#{JSON.pretty_generate(req)})"
60
+ say_error e.message
61
+ raise
62
+ end
63
+ data
64
+ end
65
+
66
+ def create_look(look)
67
+ begin
68
+ data = @sdk.create_look(look)
69
+ rescue LookerSDK::Error => e
70
+ say_error "Error creating look(#{JSON.pretty_generate(look)})"
71
+ say_error e.message
72
+ raise
73
+ end
74
+ data
75
+ end
76
+
77
+ def update_look(id,look)
78
+ begin
79
+ data = @sdk.update_look(id,look)
80
+ rescue LookerSDK::Error => e
81
+ say_error "Error updating look(#{id},#{JSON.pretty_generate(look)})"
82
+ say_error e.message
83
+ raise
84
+ end
85
+ data
86
+ end
87
+
88
+ def delete_look(look_id)
89
+ data = nil
90
+ begin
91
+ data = @sdk.delete_look(look_id)
92
+ rescue LookerSDK::Error => e
93
+ say_error "Error deleting look(#{look_id})"
94
+ say_error e.message
95
+ raise
96
+ end
97
+ data
98
+ end
99
+
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]
103
+
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
114
+ end
115
+
116
+ 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
123
+ new_look[:query_id] = query_id
124
+ return update_look(existing_look.id,new_look)
125
+ 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
136
+
137
+ return create_look(new_look)
138
+ end
139
+ end
140
+
141
+ def create_fetch_query(source_query)
142
+ new_query = source_query.select do |k,v|
143
+ (keys_to_keep('create_query') - [:client_id]).include? k
144
+ end
145
+ return create_query(new_query)
146
+ end
147
+
148
+ def create_merge_result(merge_result)
149
+ new_merge_result = merge_result.select do |k,v|
150
+ (keys_to_keep('create_merge_query') - [:client_id,:source_queries]).include? k
151
+ end
152
+ new_merge_result[:source_queries] = merge_result[:source_queries].map do |query|
153
+ new_query = {}
154
+ new_query[:query_id] = create_fetch_query(query[:query]).id
155
+ new_query[:name] = query[:name]
156
+ new_query[:merge_fields] = query[:merge_fields]
157
+ new_query
158
+ end
159
+ return create_merge_query(new_merge_result)
160
+ end
161
+ end
162
+ end