superset 0.2.4 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f3edd28b29118fb3c7ebc2eb7a199a92939429683bbe0c19aecc87b09202d9e
4
- data.tar.gz: f4eba7dd0dccd0093f8016e565df81861f0157560ab2f0320e7c4f29caec31c7
3
+ metadata.gz: ddf012f64fba5d3e1fe7584f41fc5ddcbdf9b20dea686efca47ae99e9e228c58
4
+ data.tar.gz: 9295923ac58ea7f24d92e978f94d8bbcbb6c06dd4cc821de4d67c3b57ebd08d0
5
5
  SHA512:
6
- metadata.gz: c89e37964c7a4e3ae49c484cd4594f7471734184500874c04c217a58ea785eede26390fcee81b178da92d7f4f0a0f263f61d959f33ee235a7d633a609b3cdb77
7
- data.tar.gz: 96a68b6e37885caa88dd6fc1b8b219f5fbe45f25347f9e3c66a52f1a8f167b5fa48d03dac849f4fa8b04426d450ba050af0cabe268b5961e77c306fdba98b969
6
+ metadata.gz: 563f5e16113862396196f5b0bbfe8fc96b2edce69d14089e464592f3770a9da156d50ebacc2098e6b4fc1a7766c568571d25a33507db86c2641d92ac5f518ea7
7
+ data.tar.gz: 8a02610f9d42328bff42753363ddb651924af87da82abfcd9311a16dd8ab9293e1f035d4f6e60e097e7f82c1b28165d5a009dfae4de0b1c0b1d8b16a2f00f704
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Change Log
2
2
 
3
+ ## 0.2.6 - 2025-08-05
4
+ * Bump terminal-table from 1.8.0 to 4.0.0
5
+
6
+ ## 0.2.5 - 2025-05-22
7
+ * add refresh dataset call in `Superset::Dataset::Refresh.call(id)`
8
+
3
9
  ## 0.2.4 - 2025-01-29
4
10
  * modifies the `Superset::Dashboard::Datasets::List.new(id).schemas` to optionally include filter datasets as well.
5
11
  * modifies the `Superset::Dashboard::Embedded::Get.new` to accept dashboard_id as named parameter
@@ -76,6 +82,3 @@
76
82
  - add security/user endpoints
77
83
  - add security/role endpoints
78
84
  - add security/role/permission endpoints
79
-
80
-
81
-
@@ -20,12 +20,12 @@ Assuming your API env for ruby is setup for your target superset environment.
20
20
 
21
21
  new_import_zip = Superset::Services::ImportDashboardAcrossEnvironments.new(
22
22
  dashboard_export_zip: 'path_to/dashboard_101_export_20241010.zip',
23
- target_database_yaml_file: 'path_to/env2_db_config.yaml',
24
- target_database_schema: 'acme',
23
+ target_database_yaml_file: 'path_to/env2_db_config.yaml',
24
+ target_database_schema: 'acme',
25
25
  ).perform
26
26
 
27
27
  # now import the adjusted zip to the target superset env
28
- Superset::Dashboard::Import.new(source_zip_file: new_import_file).perform
28
+ Superset::Dashboard::Import.new(source: new_import_file).perform
29
29
 
30
30
  ```
31
31
 
@@ -170,4 +170,4 @@ It will attempt to update the same dashboard as the UUID for the dashboard has n
170
170
 
171
171
  Some helpful references relating to cross-environment workflows:
172
172
  - [Managing Content Across Workspaces](https://docs.preset.io/docs/managing-content-across-workspaces)
173
- - [Superset Slack AI Explanation](https://apache-superset.slack.com/archives/C072KSLBTC1/p1722382347022689)
173
+ - [Superset Slack AI Explanation](https://apache-superset.slack.com/archives/C072KSLBTC1/p1722382347022689)
@@ -1,29 +1,32 @@
1
- # Import the provided Dashboard zip file
1
+ # frozen_string_literal: true
2
+
3
+ # Import the provided Dashboard zip file or directory (aka source)
2
4
  # In the context of this API import process, assumption is that the database.yaml file details will match
3
5
  # an existing database in the Target Superset Environment.
4
6
 
5
7
  # Scenario 1: Export from Env1 -- Import to Env1 into the SAME Environment
6
- # Will result in updating/over writing the dashboard with the contents of the zip file
8
+ # Will result in updating/over writing the dashboard with the contents of the source
7
9
 
8
10
  # Scenario 2: Export from Env1 -- Import to Env2 into a DIFFERENT Environment
9
- # Assumption is that the database.yaml will match a database configuration in the target env.
10
- # Initial import will result in creating a new dashboard with the contents of the zip file.
11
- # Subsequent imports will result in updating/over writing the previous imported dashboard with the contents of the zip file.
11
+ # Assumption is that the database.yaml will match a database configuration in the target env.
12
+ # Initial import will result in creating a new dashboard with the contents of the source.
13
+ # Subsequent imports will result in updating/over writing the previous imported dashboard with the contents of the source.
12
14
 
13
15
  # the overwrite flag will determine if the dashboard will be updated or created new
14
16
  # overwrite: false .. will result in an error if a dashboard with the same UUID already exists
15
17
 
16
18
  # Usage
17
- # Superset::Dashboard::Import.new(source_zip_file: '/tmp/dashboard.zip').perform
19
+ # Superset::Dashboard::Import.new(source: '/tmp/dashboard.zip').perform
20
+ # Superset::Dashboard::Import.new(source: '/tmp/dashboard').perform
18
21
  #
19
22
 
20
23
  module Superset
21
24
  module Dashboard
22
25
  class Import < Request
23
- attr_reader :source_zip_file, :overwrite
26
+ attr_reader :source, :overwrite
24
27
 
25
- def initialize(source_zip_file: , overwrite: true)
26
- @source_zip_file = source_zip_file
28
+ def initialize(source:, overwrite: true)
29
+ @source = source
27
30
  @overwrite = overwrite
28
31
  end
29
32
 
@@ -42,16 +45,20 @@ module Superset
42
45
  private
43
46
 
44
47
  def validate_params
45
- raise ArgumentError, 'source_zip_file is required' if source_zip_file.nil?
46
- raise ArgumentError, 'source_zip_file does not exist' unless File.exist?(source_zip_file)
47
- raise ArgumentError, 'source_zip_file is not a zip file' unless File.extname(source_zip_file) == '.zip'
48
- raise ArgumentError, 'overwrite must be a boolean' unless [true, false].include?(overwrite)
49
- raise ArgumentError, "zip target database does not exist: #{zip_database_config_not_found_in_superset}" if zip_database_config_not_found_in_superset.present?
48
+ raise ArgumentError, "source is required" if source.nil?
49
+ raise ArgumentError, "source does not exist" unless File.exist?(source)
50
+ raise ArgumentError, "source is not a zip file or directory" unless zip? || directory?
51
+ raise ArgumentError, "overwrite must be a boolean" unless [true, false].include?(overwrite)
52
+
53
+ return unless database_config_not_found_in_superset.present?
54
+
55
+ raise ArgumentError,
56
+ "target database does not exist: #{database_config_not_found_in_superset}"
50
57
  end
51
58
 
52
59
  def payload
53
60
  {
54
- formData: Faraday::UploadIO.new(source_zip_file, 'application/zip'),
61
+ formData: Faraday::UploadIO.new(source_zip_file, "application/zip"),
55
62
  overwrite: overwrite.to_s
56
63
  }
57
64
  end
@@ -60,24 +67,66 @@ module Superset
60
67
  "dashboard/import/"
61
68
  end
62
69
 
63
- def zip_database_config_not_found_in_superset
64
- zip_databases_details.select {|s| !superset_database_uuids_found.include?(s[:uuid]) }
70
+ def zip?
71
+ File.extname(source) == ".zip"
65
72
  end
66
73
 
67
- def superset_database_uuids_found
68
- @superset_database_uuids_found ||= begin
69
- zip_databases_details.map {|i| i[:uuid]}.map do |uuid|
70
- uuid if Superset::Database::List.new(uuid_equals: uuid).result.present?
71
- end.compact
74
+ def directory?
75
+ File.directory?(source)
76
+ end
77
+
78
+ def source_zip_file
79
+ return source if zip?
80
+
81
+ Zip::File.open(new_zip_file, Zip::File::CREATE) do |zipfile|
82
+ Dir[File.join(source, "**", "**")].each do |file|
83
+ next unless File.file?(file)
84
+
85
+ # add a base folder to the relative path: "dashboard_import_#{timestamp}"
86
+ zipfile.add(File.join("dashboard_import_#{timestamp}", relative_path(file)), file)
87
+ end
72
88
  end
89
+ new_zip_file
90
+ end
91
+
92
+ def relative_path(file)
93
+ Pathname.new(file).relative_path_from(Pathname.new(source)).to_s
94
+ end
95
+
96
+ def new_zip_file
97
+ File.join(source, "dashboard_import_#{timestamp}.zip")
73
98
  end
74
99
 
75
- def zip_databases_details
76
- zip_dashboard_config[:databases].map{|d| {uuid: d[:content][:uuid], name: d[:content][:database_name]} }
100
+ def timestamp
101
+ @timestamp ||= Time.now.strftime("%Y%m%d%H%M%S")
102
+ end
103
+
104
+ def database_config_not_found_in_superset
105
+ databases_details.reject { |s| superset_database_uuids_found.include?(s[:uuid]) }
106
+ end
107
+
108
+ def superset_database_uuids_found
109
+ @superset_database_uuids_found ||= databases_details.map { |i| i[:uuid] }.map do |uuid|
110
+ uuid if Superset::Database::List.new(uuid_equals: uuid).result.present?
111
+ end.compact
112
+ end
113
+
114
+ def databases_details
115
+ dashboard_config[:databases].map { |d| { uuid: d[:content][:uuid], name: d[:content][:database_name] } }
116
+ end
117
+
118
+ def dashboard_config
119
+ @dashboard_config ||= zip? ? zip_dashboard_config : directory_dashboard_config
77
120
  end
78
121
 
79
122
  def zip_dashboard_config
80
- @zip_dashboard_config ||= Superset::Services::DashboardLoader.new(dashboard_export_zip: source_zip_file).perform
123
+ Superset::Services::DashboardLoader.new(dashboard_export_zip: source).perform
124
+ end
125
+
126
+ def directory_dashboard_config
127
+ Superset::Services::DashboardLoader::DashboardConfig.new(
128
+ dashboard_export_zip: "", tmp_uniq_dashboard_path: source
129
+ ).config
81
130
  end
82
131
  end
83
132
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Description: This endpoint has the same functionality as 'Sync Columns from Source' button in the Superset UI on a dataset.
4
+ # Executes the dataset against the source to confirm the query runs and then sync and cache dataset columns.
5
+ # NOTICE: only owners of the dataset can refresh it
6
+ #
7
+ # Usage: Superset::Dataset::Refresh.call(id)
8
+
9
+ module Superset
10
+ module Dataset
11
+ class Refresh < Superset::Request
12
+
13
+ attr_reader :id
14
+
15
+ def initialize(id)
16
+ @id = id
17
+ end
18
+
19
+ def self.call(id)
20
+ self.new(id).perform
21
+ end
22
+
23
+ def perform
24
+ response
25
+ end
26
+
27
+ def response
28
+ @response ||= client.put(route)
29
+ end
30
+
31
+ private
32
+
33
+ def route
34
+ "dataset/#{id}/refresh"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superset
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.6"
5
5
  end
data/superset.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "A Ruby Client for Apache Superset API"
12
12
  spec.homepage = "https://github.com/rdytech/superset-client"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 2.7.8"
15
15
 
16
16
  #spec.metadata["allowed_push_host"] = ""
17
17
 
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  # Uncomment to register a new dependency of your gem
38
38
  spec.add_dependency "dotenv", "~> 2.7"
39
39
  spec.add_dependency "json", "~> 2.6"
40
- spec.add_dependency "terminal-table", "~> 1.8"
40
+ spec.add_dependency "terminal-table", "~> 4.0"
41
41
  spec.add_dependency "rake", "~> 13.0"
42
42
  spec.add_dependency "rollbar", "~> 3.4"
43
43
  spec.add_dependency "require_all", "~> 3.0"
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.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jbat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-29 00:00:00.000000000 Z
11
+ date: 2025-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.8'
47
+ version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.8'
54
+ version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - ".buildkite/pipeline.yml"
203
203
  - ".rspec"
204
204
  - ".rubocop.yml"
205
+ - ".ruby-version"
205
206
  - CHANGELOG.md
206
207
  - Dockerfile
207
208
  - LICENSE
@@ -257,6 +258,7 @@ files:
257
258
  - lib/superset/dataset/get.rb
258
259
  - lib/superset/dataset/list.rb
259
260
  - lib/superset/dataset/put.rb
261
+ - lib/superset/dataset/refresh.rb
260
262
  - lib/superset/dataset/update_query.rb
261
263
  - lib/superset/dataset/update_schema.rb
262
264
  - lib/superset/dataset/warm_up_cache.rb
@@ -298,14 +300,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
300
  requirements:
299
301
  - - ">="
300
302
  - !ruby/object:Gem::Version
301
- version: 2.6.0
303
+ version: 2.7.8
302
304
  required_rubygems_version: !ruby/object:Gem::Requirement
303
305
  requirements:
304
306
  - - ">="
305
307
  - !ruby/object:Gem::Version
306
308
  version: '0'
307
309
  requirements: []
308
- rubygems_version: 3.3.26
310
+ rubygems_version: 3.1.6
309
311
  signing_key:
310
312
  specification_version: 4
311
313
  summary: A Ruby Client for Apache Superset API