superset 0.1.6 → 0.2.5

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +36 -144
  4. data/doc/duplicate_dashboards.md +2 -5
  5. data/doc/migrating_dashboards_across_environments.md +173 -0
  6. data/doc/publishing.md +39 -0
  7. data/doc/setting_up_personal_api_credentials.md +43 -7
  8. data/doc/usage.md +105 -0
  9. data/env.sample +1 -1
  10. data/lib/superset/base_put_request.rb +30 -0
  11. data/lib/superset/chart/create.rb +40 -0
  12. data/lib/superset/chart/duplicate.rb +75 -0
  13. data/lib/superset/chart/put.rb +18 -0
  14. data/lib/superset/chart/update_dataset.rb +1 -1
  15. data/lib/superset/client.rb +7 -1
  16. data/lib/superset/dashboard/bulk_delete_cascade.rb +1 -1
  17. data/lib/superset/dashboard/compare.rb +2 -2
  18. data/lib/superset/dashboard/datasets/list.rb +37 -9
  19. data/lib/superset/dashboard/embedded/get.rb +2 -2
  20. data/lib/superset/dashboard/export.rb +56 -5
  21. data/lib/superset/dashboard/get.rb +5 -0
  22. data/lib/superset/dashboard/import.rb +84 -0
  23. data/lib/superset/dashboard/list.rb +8 -4
  24. data/lib/superset/dashboard/warm_up_cache.rb +1 -1
  25. data/lib/superset/database/export.rb +119 -0
  26. data/lib/superset/database/list.rb +5 -2
  27. data/lib/superset/dataset/get.rb +10 -11
  28. data/lib/superset/dataset/list.rb +1 -1
  29. data/lib/superset/dataset/put.rb +18 -0
  30. data/lib/superset/dataset/refresh.rb +38 -0
  31. data/lib/superset/dataset/update_schema.rb +4 -3
  32. data/lib/superset/file_utilities.rb +4 -3
  33. data/lib/superset/guest_token.rb +14 -7
  34. data/lib/superset/logger.rb +2 -2
  35. data/lib/superset/request.rb +7 -4
  36. data/lib/superset/services/dashboard_loader.rb +69 -0
  37. data/lib/superset/services/duplicate_dashboard.rb +14 -13
  38. data/lib/superset/services/import_dashboard_across_environment.rb +144 -0
  39. data/lib/superset/version.rb +1 -1
  40. metadata +16 -3
@@ -0,0 +1,144 @@
1
+ =begin
2
+ This service is used to duplicate a dashboard from one environment to another.
3
+ It will not create any database connections from an imported dashboard zip, therefore the target_database_yaml_file configuration
4
+ must already exist as a database connection in the target superset environment.
5
+
6
+ Currently handles only 1 Database yaml file in the zip file. ( ie only 1 common database connection per dashboards datasets )
7
+
8
+ Required Attributes:
9
+ - target_database_yaml_file - location of the target database yaml config file
10
+ - target_database_schema - the schema name to be used in the target database
11
+ - dashboard_export_zip - location of the source dashboard export zip file to tranferred to a new superset Env
12
+
13
+ Usage:
14
+ Assuming you have exported a dashboard from the source environment and have the zip file, and have exported the target database yaml file
15
+
16
+ Superset::Services::ImportDashboardAcrossEnvironments.new(
17
+ target_database_yaml_file: '/tmp/database.yaml',
18
+ target_database_schema: 'insert_schema_here',
19
+ dashboard_export_zip: '/tmp/dashboard.zip'
20
+ ).perform
21
+
22
+ =end
23
+
24
+ require 'superset/file_utilities'
25
+ require 'yaml'
26
+
27
+ module Superset
28
+ module Services
29
+ class ImportDashboardAcrossEnvironments
30
+ include FileUtilities
31
+
32
+ def initialize(target_database_yaml_file:, target_database_schema: ,dashboard_export_zip:)
33
+ @target_database_yaml_file = target_database_yaml_file
34
+ @target_database_schema = target_database_schema
35
+ @dashboard_export_zip = dashboard_export_zip
36
+ end
37
+
38
+ def perform
39
+ validate_params
40
+
41
+ remove_source_database_config
42
+ insert_target_database_file
43
+ insert_target_database_config
44
+ update_dataset_configs
45
+
46
+ create_new_dashboard_zip
47
+ end
48
+
49
+ def dashboard_config
50
+ @dashboard_config ||= Superset::Services::DashboardLoader.new(dashboard_export_zip: dashboard_export_zip).perform
51
+ end
52
+
53
+ private
54
+
55
+ attr_reader :target_database_yaml_file, :target_database_schema, :dashboard_export_zip
56
+
57
+ def remove_source_database_config
58
+ return if dashboard_config[:databases].blank?
59
+ previous_database_name = dashboard_config[:databases]&.first[:content][:database_name]
60
+ File.delete(dashboard_config[:databases].first[:filename])
61
+
62
+ dashboard_config[:databases].clear
63
+ end
64
+
65
+ def insert_target_database_file
66
+ FileUtils.cp(target_database_yaml_file, File.join(dashboard_export_root_path, 'databases'))
67
+
68
+ pattern = File.join(dashboard_export_root_path, 'databases', '*.yaml')
69
+ @new_database_yaml_file_path = Dir.glob(pattern).first
70
+ end
71
+
72
+ def insert_target_database_config
73
+ yaml_content = YAML.load_file(target_database_yaml_file).deep_symbolize_keys
74
+ dashboard_config[:databases] << { filename: new_database_yaml_file_path, content: yaml_content }
75
+ end
76
+
77
+ def update_dataset_configs
78
+ dashboard_config[:datasets].each do |dataset|
79
+ dataset[:content][:database_uuid] = dashboard_config[:databases].first[:content][:uuid]
80
+ dataset[:content][:schema] = target_database_schema
81
+ stringified_content = deep_transform_keys_to_strings(dataset[:content])
82
+ File.open(dataset[:filename], 'w') { |f| f.write stringified_content.to_yaml }
83
+ end
84
+ end
85
+
86
+ def create_new_dashboard_zip
87
+ Zip::File.open(new_zip_file, Zip::File::CREATE) do |zipfile|
88
+ Dir[File.join(dashboard_export_root_path, '**', '**')].each do |file|
89
+ zipfile.add(file.sub(dashboard_export_root_path + '/', File.basename(dashboard_export_root_path) + '/' ), file) if File.file?(file)
90
+ end
91
+ end
92
+ new_zip_file
93
+ end
94
+
95
+ def new_zip_file
96
+ new_database_name = dashboard_config[:databases].first[:content][:database_name]
97
+ File.join(dashboard_config[:tmp_uniq_dashboard_path], "dashboard_import_for_#{new_database_name}.zip")
98
+ end
99
+
100
+ def new_database_yaml_file_path
101
+ @new_database_yaml_file_path ||= ''
102
+ end
103
+
104
+ def dashboard_export_root_path
105
+ # locate the unziped dashboard_export_* directory as named by superset app, eg dashboard_export_20240821T001536
106
+ @dashboard_export_root_path ||= begin
107
+ pattern = File.join(dashboard_config[:tmp_uniq_dashboard_path], 'dashboard_export_*')
108
+ Dir.glob(pattern).first
109
+ end
110
+
111
+ end
112
+
113
+ def new_database_name
114
+ dashboard_config[:databases].first[:content][:database_name]
115
+ end
116
+
117
+ def previous_database_name
118
+ @previous_database_name ||= ''
119
+ end
120
+
121
+ def validate_params
122
+ raise "Dashboard Export Zip file does not exist" unless File.exist?(dashboard_export_zip)
123
+ raise "Dashboard Export Zip file is not a zip file" unless File.extname(dashboard_export_zip) == '.zip'
124
+ raise "Target Database YAML file does not exist" unless File.exist?(target_database_yaml_file)
125
+ raise "Currently this class handles boards with single Database configs only. Multiple Database configs exist in zip file." if dashboard_config[:databases].size > 1
126
+ raise "Target Database Schema cannot be blank" if target_database_schema.blank?
127
+ end
128
+
129
+ # Method to recursively transform keys to strings
130
+ def deep_transform_keys_to_strings(value)
131
+ case value
132
+ when Hash
133
+ value.each_with_object({}) do |(k, v), result|
134
+ result[k.to_s] = deep_transform_keys_to_strings(v)
135
+ end
136
+ when Array
137
+ value.map { |v| deep_transform_keys_to_strings(v) }
138
+ else
139
+ value
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superset
4
- VERSION = "0.1.6"
4
+ VERSION = "0.2.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jbat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
11
+ date: 2025-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -208,17 +208,24 @@ files:
208
208
  - README.md
209
209
  - Rakefile
210
210
  - doc/duplicate_dashboards.md
211
+ - doc/migrating_dashboards_across_environments.md
212
+ - doc/publishing.md
211
213
  - doc/setting_up_personal_api_credentials.md
214
+ - doc/usage.md
212
215
  - docker-compose.override.yml
213
216
  - docker-compose.yml
214
217
  - env.sample
215
218
  - lib/loggers/duplicate_dashboard_logger.rb
216
219
  - lib/superset.rb
217
220
  - lib/superset/authenticator.rb
221
+ - lib/superset/base_put_request.rb
218
222
  - lib/superset/chart/bulk_delete.rb
223
+ - lib/superset/chart/create.rb
219
224
  - lib/superset/chart/delete.rb
225
+ - lib/superset/chart/duplicate.rb
220
226
  - lib/superset/chart/get.rb
221
227
  - lib/superset/chart/list.rb
228
+ - lib/superset/chart/put.rb
222
229
  - lib/superset/chart/update_dataset.rb
223
230
  - lib/superset/client.rb
224
231
  - lib/superset/credential/api_user.rb
@@ -234,10 +241,12 @@ files:
234
241
  - lib/superset/dashboard/embedded/put.rb
235
242
  - lib/superset/dashboard/export.rb
236
243
  - lib/superset/dashboard/get.rb
244
+ - lib/superset/dashboard/import.rb
237
245
  - lib/superset/dashboard/info.rb
238
246
  - lib/superset/dashboard/list.rb
239
247
  - lib/superset/dashboard/put.rb
240
248
  - lib/superset/dashboard/warm_up_cache.rb
249
+ - lib/superset/database/export.rb
241
250
  - lib/superset/database/get.rb
242
251
  - lib/superset/database/get_schemas.rb
243
252
  - lib/superset/database/list.rb
@@ -247,6 +256,8 @@ files:
247
256
  - lib/superset/dataset/duplicate.rb
248
257
  - lib/superset/dataset/get.rb
249
258
  - lib/superset/dataset/list.rb
259
+ - lib/superset/dataset/put.rb
260
+ - lib/superset/dataset/refresh.rb
250
261
  - lib/superset/dataset/update_query.rb
251
262
  - lib/superset/dataset/update_schema.rb
252
263
  - lib/superset/dataset/warm_up_cache.rb
@@ -266,7 +277,9 @@ files:
266
277
  - lib/superset/security/user/create.rb
267
278
  - lib/superset/security/user/get.rb
268
279
  - lib/superset/security/user/list.rb
280
+ - lib/superset/services/dashboard_loader.rb
269
281
  - lib/superset/services/duplicate_dashboard.rb
282
+ - lib/superset/services/import_dashboard_across_environment.rb
270
283
  - lib/superset/sqllab/execute.rb
271
284
  - lib/superset/tag/add_to_object.rb
272
285
  - lib/superset/tag/get.rb
@@ -293,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
306
  - !ruby/object:Gem::Version
294
307
  version: '0'
295
308
  requirements: []
296
- rubygems_version: 3.4.21
309
+ rubygems_version: 3.3.26
297
310
  signing_key:
298
311
  specification_version: 4
299
312
  summary: A Ruby Client for Apache Superset API