holistics 0.3.5 → 0.4.0
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 +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +5 -0
- data/holistics.gemspec +1 -1
- data/lib/dbt.rb +48 -0
- data/lib/holistics/api_client.rb +25 -23
- data/lib/holistics/helpers/http_request.rb +5 -5
- data/lib/holistics/version.rb +2 -2
- data/lib/holistics.rb +2 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 32364a4f3b5aa6da19afdc05c34a6a9c3361721a200a6788bbc81bd4c7039b52
|
4
|
+
data.tar.gz: a3a993895ae584784d2abe4b3ba4e27a21688e8a4222c71be942cad483bfa809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d5cfeb9ffc0990025139117aa02c31a0bada08b86c267bfd37e1257f240267221f9acb0d8eb162e7f9f1ab5a60a00a152c1d070c30ff8bc60a18dafd70c3919
|
7
|
+
data.tar.gz: 441660cafeee9c3b74f6a8cd6f9984b1e2b4e13bf7cbfd33c58d0a765ab98c45b5da371a3a36c315ea236287f5110b2a012aa3501e6caa85ba0f2931d84a4ff5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,11 @@ Example:
|
|
80
80
|
[job:738] Hot-swapping with Redshift table public.users ...
|
81
81
|
[job:738] Done.
|
82
82
|
|
83
|
+
## dbt commands
|
84
|
+
### Upload dbt's manifest.json file to Holistics
|
85
|
+
$ holistics dbt upload --file-path /path/to/manifest.json --data-source demodb
|
86
|
+
|
87
|
+
|
83
88
|
### Custom table build transport
|
84
89
|
|
85
90
|
See `samples/clicks_mysql_to_redshift.json` for details of transport configs.
|
data/holistics.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.0"
|
24
24
|
|
25
|
-
spec.add_dependency 'activesupport'
|
25
|
+
spec.add_dependency 'activesupport'
|
26
26
|
spec.add_dependency 'httparty', '~> 0.13'
|
27
27
|
spec.add_dependency 'thor', '~> 0.19'
|
28
28
|
spec.add_dependency 'multipart-post', '~> 2.0'
|
data/lib/dbt.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'holistics/helpers/http_request'
|
3
|
+
|
4
|
+
module Holistics
|
5
|
+
class Dbt < Thor
|
6
|
+
method_option :filepath, aliases: '--file-path', type: :string, required: false, desc: 'Path to manifest.json file'
|
7
|
+
method_option :data_source_name, aliases: '--data-source', type: :string, required: false, desc: 'Name of data_source'
|
8
|
+
desc 'upload', 'Upload manifest.json file to Holistics'
|
9
|
+
def upload
|
10
|
+
data_source_name = options[:data_source_name]
|
11
|
+
manifest_file = get_manifest_file_from(options)
|
12
|
+
|
13
|
+
params = {
|
14
|
+
data_source_name: data_source_name
|
15
|
+
}
|
16
|
+
|
17
|
+
http_request.post_file('api/v2/data_sources/upload_dbt_manifest.json', params, manifest_file, 'application/json',
|
18
|
+
'Error uploading manifest.json file')
|
19
|
+
|
20
|
+
puts 'Upload completed!'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_manifest_file_from(options)
|
26
|
+
local_filepath =
|
27
|
+
if options[:filepath].present?
|
28
|
+
options[:filepath]
|
29
|
+
else
|
30
|
+
Dir['./**/manifest.json'].first
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
file = File.open(local_filepath)
|
35
|
+
rescue StandardError
|
36
|
+
warn "Could not open file at '#{local_filepath}'."
|
37
|
+
puts 'Invalid file path. Please check your file path.'
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
file
|
42
|
+
end
|
43
|
+
|
44
|
+
def http_request
|
45
|
+
@http_request ||= Helpers::HttpRequest.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/holistics/api_client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tabular_formatter'
|
2
4
|
require 'yaml'
|
3
5
|
require 'json'
|
@@ -10,16 +12,16 @@ module Holistics
|
|
10
12
|
class ImportError < StandardError
|
11
13
|
end
|
12
14
|
|
13
|
-
def import_csv
|
15
|
+
def import_csv(options)
|
14
16
|
local_filepath = options[:filepath]
|
15
17
|
dest_ds_id = options[:dest_ds_id]
|
16
18
|
dest_fqname = options[:dest_table_name]
|
17
19
|
|
18
20
|
begin
|
19
21
|
file = File.open local_filepath
|
20
|
-
rescue
|
21
|
-
|
22
|
-
puts
|
22
|
+
rescue StandardError
|
23
|
+
warn "Could not open file at '#{local_filepath}'."
|
24
|
+
puts 'Invalid file path. Please check your file path.'
|
23
25
|
|
24
26
|
return
|
25
27
|
end
|
@@ -31,7 +33,7 @@ module Holistics
|
|
31
33
|
dest_ds_id: dest_ds_id
|
32
34
|
}
|
33
35
|
|
34
|
-
json = http_request.
|
36
|
+
json = http_request.post_file 'data_imports/import_csv.json', params, file, 'text/csv', 'Error uploading CSV file'
|
35
37
|
|
36
38
|
job_id = json['message']['job_id']
|
37
39
|
|
@@ -42,8 +44,8 @@ module Holistics
|
|
42
44
|
def ds_list
|
43
45
|
result = http_request.get 'data_sources.json', 'Error retrieving list of data sources'
|
44
46
|
|
45
|
-
table = [%w
|
46
|
-
rows = result.map {|record| [record['id'], record['dbtype'], record['name']]}
|
47
|
+
table = [%w[ID Type Name]]
|
48
|
+
rows = result.map { |record| [record['id'], record['dbtype'], record['name']] }
|
47
49
|
table.concat(rows)
|
48
50
|
|
49
51
|
puts TabularFormatter.new(table).to_pretty_table
|
@@ -52,8 +54,8 @@ module Holistics
|
|
52
54
|
def import_list
|
53
55
|
result = http_request.get 'data_imports.json', 'Error retrieving list of data imports'
|
54
56
|
|
55
|
-
table = [%w
|
56
|
-
rows = result.map {|record| [record['id'], record['title']]}
|
57
|
+
table = [%w[ID Name]]
|
58
|
+
rows = result.map { |record| [record['id'], record['title']] }
|
57
59
|
table.concat(rows)
|
58
60
|
|
59
61
|
puts TabularFormatter.new(table).to_pretty_table
|
@@ -62,8 +64,8 @@ module Holistics
|
|
62
64
|
def transform_list
|
63
65
|
result = http_request.get 'data_transforms.json', 'Error retrieving list of data transports'
|
64
66
|
|
65
|
-
table = [%w
|
66
|
-
rows = result.map {|record| [record['id'], record['title']]}
|
67
|
+
table = [%w[ID Name]]
|
68
|
+
rows = result.map { |record| [record['id'], record['title']] }
|
67
69
|
table.concat(rows)
|
68
70
|
|
69
71
|
puts TabularFormatter.new(table).to_pretty_table
|
@@ -113,7 +115,7 @@ module Holistics
|
|
113
115
|
job_manager.tail_logs job_id
|
114
116
|
res = job_manager.fetch_job_results job_id
|
115
117
|
unless res['status'] == 'success'
|
116
|
-
raise ImportError
|
118
|
+
raise ImportError, "Failed Import Job #{job_id}: #{res['error']}"
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
@@ -123,16 +125,14 @@ module Holistics
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def generate_configs(options)
|
126
|
-
unless Dir.exist?(options['output'])
|
127
|
-
raise 'Output location is invalid.'
|
128
|
-
end
|
128
|
+
raise 'Output location is invalid.' unless Dir.exist?(options['output'])
|
129
129
|
|
130
130
|
puts "Generating transport JSON config files to #{options['output']} directory..."
|
131
131
|
|
132
132
|
result = http_request.post_json 'transports/generate_configs.json', options, 'Error generating transport configs'
|
133
133
|
|
134
134
|
result.each do |table_data|
|
135
|
-
File.open("#{options['output']}/#{table_data['filename']}",
|
135
|
+
File.open("#{options['output']}/#{table_data['filename']}", 'w') do |f|
|
136
136
|
f.write(JSON.pretty_generate(table_data['json_content']))
|
137
137
|
end
|
138
138
|
|
@@ -145,24 +145,28 @@ module Holistics
|
|
145
145
|
|
146
146
|
def build_submit_params(options)
|
147
147
|
params = options.except(:config_path)
|
148
|
-
|
148
|
+
if options[:config_path]
|
149
|
+
params[:configs] = parse_transport_config(options[:config_path]).to_json
|
150
|
+
end
|
149
151
|
params
|
150
152
|
end
|
151
153
|
|
152
154
|
def parse_transport_config(filepath)
|
153
155
|
file_ext = File.extname(filepath).downcase
|
154
156
|
if file_ext == '.json'
|
155
|
-
|
157
|
+
JSON.parse(File.read(filepath))
|
156
158
|
elsif file_ext == '.yml'
|
157
|
-
|
159
|
+
YAML.safe_load(File.read(filepath))
|
158
160
|
else
|
159
|
-
raise StandardError
|
161
|
+
raise StandardError, 'Invalid config file extension. Please use either JSON or YML'
|
160
162
|
end
|
161
163
|
rescue StandardError => e
|
162
|
-
|
164
|
+
warn "Error parsing transport config file: #{e.message}"
|
163
165
|
exit 1
|
164
166
|
end
|
165
167
|
|
168
|
+
def dbt_upload(filepath, ds_name); end
|
169
|
+
|
166
170
|
private
|
167
171
|
|
168
172
|
def file_manager
|
@@ -180,7 +184,5 @@ module Holistics
|
|
180
184
|
def auth_info
|
181
185
|
@auth_info ||= Helpers::AuthInfo.new
|
182
186
|
end
|
183
|
-
|
184
|
-
|
185
187
|
end
|
186
188
|
end
|
@@ -34,7 +34,7 @@ module Holistics
|
|
34
34
|
exit_if_error(msg_if_error, response)
|
35
35
|
JSON.parse response.body
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def simple_get(url, token = nil)
|
39
39
|
HTTParty
|
40
40
|
.get url, headers: { API_KEY_HEADER => token || auth_helper.get_token_from_gconfig }
|
@@ -61,11 +61,11 @@ module Holistics
|
|
61
61
|
#
|
62
62
|
# see this link for setting it
|
63
63
|
# https://github.com/nicksieger/multipart-post/issues/18#issuecomment-171479987
|
64
|
-
def
|
64
|
+
def post_file url, params, file, content_type, msg_if_error = DEFAULT_ERROR_MSG
|
65
65
|
uri = URI.parse(endpoint_for(url))
|
66
|
-
|
67
|
-
params = params.merge file:
|
68
|
-
|
66
|
+
upload_file = UploadIO.new file, content_type, File.basename(file.path)
|
67
|
+
params = params.merge file: upload_file
|
68
|
+
|
69
69
|
post_data = Net::HTTP::Post::Multipart.new uri.path, params
|
70
70
|
post_data.add_field(API_KEY_HEADER, auth_helper.get_token_from_gconfig)
|
71
71
|
|
data/lib/holistics/version.rb
CHANGED
data/lib/holistics.rb
CHANGED
@@ -12,6 +12,7 @@ require 'transport'
|
|
12
12
|
require 'transform'
|
13
13
|
require 'data_sources'
|
14
14
|
require 'email_schedule'
|
15
|
+
require 'dbt'
|
15
16
|
|
16
17
|
module Holistics
|
17
18
|
def self.root
|
@@ -50,6 +51,7 @@ module Holistics
|
|
50
51
|
register(Holistics::Transform, 'transform', 'transform <command>', "Execute transform module's commands")
|
51
52
|
register(Holistics::DataSources, 'data_sources', 'data_sources <command>', "Execute data_sources module's commands")
|
52
53
|
register(Holistics::EmailSchedule, 'email_schedule', 'email_schedule <command>', "Execute email schedule's commands")
|
54
|
+
register(Holistics::Dbt, 'dbt', 'dbt <comnand>', 'dbt integration with Holistics')
|
53
55
|
|
54
56
|
no_commands do
|
55
57
|
def auth_api_client
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thanh Dinh Khac
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -29,16 +29,16 @@ dependencies:
|
|
29
29
|
name: activesupport
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: httparty
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- bin/holistics
|
109
109
|
- holistics.gemspec
|
110
110
|
- lib/data_sources.rb
|
111
|
+
- lib/dbt.rb
|
111
112
|
- lib/email_schedule.rb
|
112
113
|
- lib/holistics.rb
|
113
114
|
- lib/holistics/api_client.rb
|
@@ -143,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
- !ruby/object:Gem::Version
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
|
-
|
147
|
-
rubygems_version: 2.5.1
|
147
|
+
rubygems_version: 3.1.6
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: CLI interface for Holistics
|