holistics-cli 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b80a3a24c1ac9616a5587da1e1c01a676cd1286b
4
+ data.tar.gz: f63e22764b741514194102e825ce0e99c6ac6b32
5
+ SHA512:
6
+ metadata.gz: fdda4e959b6c83f9638a1b9113bfc6c393b6f2adf8ab2be4c0216aba003e057aeb332e9e03be7af189112f1acb2255a8f825d2976ab75c881cc5b49c9a907c62
7
+ data.tar.gz: 312913e984bf1f11a81e1d5d5619d259eb08f1db2e6751a326477401109c04265f6c22152c00525aab522bdeec021370154c5515e633ac48ea9abd82b25c3693
data/.byebug_history ADDED
@@ -0,0 +1,183 @@
1
+ exit
2
+ c.get('/data_imports')
3
+ c.get('/')
4
+ c = @this.instance_variable_get(:@client)
5
+ exit
6
+ c.token
7
+ c = @this.instance_variable_get(:@client)
8
+ @this.instance_variable_get(:@client).get('/data_imports')
9
+ @this.instance_variable_get(:@client).get('/')
10
+ @this.instance_variable_get(:@client)
11
+ @this.instance_variable_get(@client)
12
+ @this.instance_var
13
+ @this
14
+ @this.client
15
+ c
16
+ exit
17
+ item = @this.find id
18
+ item
19
+ c
20
+ log_lines[(-[line_count, log_lines.length].min)..-1]
21
+ line_count
22
+ exit
23
+ log_lines
24
+ line_count
25
+ lien_count
26
+ exit
27
+ line_count
28
+ exit
29
+ line_count
30
+ exit
31
+ line_count
32
+ exit
33
+ n
34
+ exit
35
+ number
36
+ log_lines
37
+ number
38
+ exit
39
+ e['logs'].first
40
+ e['logs']
41
+ e.keys
42
+ e = @this.logs(id)
43
+ exit
44
+ e = @this.find id
45
+ exit
46
+ tp([e])
47
+ tp(e)
48
+ e = @this.execute(id)
49
+ exit
50
+ ix.concat(12)
51
+ ix
52
+ ix.concat([11])
53
+ ix = [1,2,3]
54
+ i = [1,2,3]
55
+ self.errors
56
+ self
57
+ self.errors
58
+ self.errors = 123
59
+ self.errors
60
+ errors
61
+ errors = 123
62
+ errors
63
+ exit
64
+ self.errors
65
+ errors = 1
66
+ errors = nil
67
+ self.errors
68
+ self
69
+ errors
70
+ c
71
+ exit
72
+ c
73
+ exit
74
+ c
75
+ exit
76
+ c
77
+ exit
78
+ c
79
+ exit
80
+ e.keys
81
+ item['last_run']
82
+ e = items.first
83
+ c
84
+ exit
85
+ e['last_run_job']['status']
86
+ e['last_run_job']['stats']
87
+ e['last_run_job'].keys
88
+ e['source_label']
89
+ e['last_run_job']
90
+ e.keys
91
+ e = items.first
92
+ c
93
+ exit
94
+ destination = [item['dest_ds_id']. item['dest_schema_name'], item['dest_table_name']].join('.')
95
+ item
96
+ destination = [item['dest_ds_id']. item['dest_schema_name'], item['dest_table_name']].join('.')
97
+ item
98
+ destination = [item['dest_ds_id']. item['dest_schema_name'], item['dest_table_name']].join('.')
99
+ item = e
100
+ e.keys
101
+ e = items.first
102
+ c
103
+ exit
104
+ item = items.first
105
+ item = items.firsr
106
+ items.first['source_config']['dbtable']
107
+ items.first['source_config']['db_table']
108
+ items.first['source_config']['db_table']['ds_id']
109
+ items.first.keys
110
+ c
111
+ items
112
+ exit
113
+ e.map { |v| v['source_type']}.uniq
114
+ x["source_type"]
115
+ x["dest_schema_name"]
116
+ x["source_config"]
117
+ x["title"]
118
+ x.keys
119
+ x = e.first
120
+ e = @this.all
121
+ e = @this.execute("308")
122
+ exit
123
+ ex
124
+ e = @this.execute("308")
125
+ exit
126
+ @this.execute("308")
127
+ transform_id
128
+ exit
129
+ @this.method(:execute).source_location
130
+ @this
131
+ e = @this.execute(308)
132
+ c
133
+ exit
134
+ end
135
+ })
136
+ mode: v['settings']['mode']
137
+ v.slice(*%w{ id title owner_name created_at last_run }).merge({
138
+ @this.all.map do |v|
139
+ x.slice(*%w{ id title owner_name created_at last_run })
140
+ x.slice("id")
141
+ x.slice
142
+ x.keys
143
+ x
144
+ x.splice(%w{ id title owner_name created_at last_run })
145
+ x.slice(%w{ id title owner_name created_at last_run })
146
+ x = e.first
147
+ v = e.first
148
+ e
149
+ v = e.first
150
+ e = @this.all
151
+ exit
152
+ puts e.first["schedules"]
153
+ puts e.first["settings"]["mode"]
154
+ puts e.first["settings"]
155
+ puts e.first["tenant_id"]
156
+ puts e.first["tenant_id]
157
+ puts e.first["query"]
158
+ e.first["owner_name"]
159
+ e.first["description"]
160
+ e.first["title"]
161
+ e.first["id"]
162
+ e.first[:id]
163
+ e.first.keys
164
+ e.first
165
+ e = @this.all
166
+ @this.all
167
+ exit
168
+ JSON.parse(data.body)
169
+ JSON
170
+ data.body
171
+ data = e.all
172
+ e.all
173
+ e = Resource.new('data_sources', Holistics.client)
174
+ exit
175
+ e.all
176
+ e.list
177
+ e
178
+ e.name
179
+ e = Resource.new('data_sources', Holistics.client)
180
+ e = _
181
+ Resource.new('data_sources', Holistics.client)
182
+ Resource.new('data_sources')
183
+ Resource
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.15.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at phamminhthanh69@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in holistics-cli.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Holistics CLI
2
+
3
+ CommandLine Interface to [Holistics API](https://docs.holistics.io/api/)
4
+
5
+ > Dislaim: The official Holistics-CLI is quite limit for me, so I made this gem as an alternative
6
+
7
+ ## Installation
8
+
9
+ $ gem install holistics-cli
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ $ holistics
15
+ Commands:
16
+ holistics config # Init or update config
17
+ holistics help [COMMAND] # Describe available commands or one specific command
18
+ holistics imports # Import jobs
19
+ holistics jobs # Submitted jobs
20
+ holistics sources # Data sources
21
+ holistics transforms # Data transformations
22
+ holistics version # Show version information
23
+ ```
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pmint93/holistics-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Holistics project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/holistics/blob/master/CODE_OF_CONDUCT.md).
42
+
43
+ ## Related
44
+
45
+ * [Official Holistics-CLI](https://docs.holistics.io/holistics-cli/)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "holistics"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/holistics ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'holistics'
4
+
5
+ Holistics::CLI.start(ARGV)
data/holistics.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'holistics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'holistics-cli'
8
+ spec.version = Holistics::VERSION
9
+ spec.authors = ['Thanh Pham Minh']
10
+ spec.email = ['phamminhthanh69@gmail.com']
11
+
12
+ spec.summary = 'Holistics CommandLine Interface'
13
+ spec.description = 'CommandLine Interface for Holistics.io, proxy request through Holistics HTTP API'
14
+ spec.homepage = 'https://github.com/pmint93/holistics-cli'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = ['holistics']
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'byebug', '~> 9.0'
28
+
29
+ spec.add_runtime_dependency 'thor', '~> 0.19.4'
30
+ spec.add_runtime_dependency 'colorize', '0.8.1'
31
+ spec.add_runtime_dependency 'table_print', '1.5.6'
32
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
33
+ spec.add_runtime_dependency 'faraday', '~> 0.11.0'
34
+ end
@@ -0,0 +1,53 @@
1
+ require 'faraday'
2
+ require 'uri'
3
+
4
+ module Holistics
5
+ class Client
6
+
7
+ DEFAULT_ENDPOINT = 'https://api.holistics.io'.freeze
8
+
9
+ def initialize(endpoint, token)
10
+ @conn = Faraday.new(:url => (endpoint || DEFAULT_ENDPOINT)) do |faraday|
11
+ faraday.request :url_encoded # form-encode POST params
12
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
13
+ end
14
+ @token = token
15
+ end
16
+
17
+ def get(path, options = {})
18
+ options[:params] ||= {}
19
+ options[:headers] ||= {}
20
+ response = @conn.get do |req|
21
+ req.url path
22
+ req.headers.merge(options[:headers])
23
+ req.params = options[:params].merge({ '_utoken': @token })
24
+ end
25
+ [response.status, response.body]
26
+ end
27
+
28
+ def post(path, options = {})
29
+ options[:params] ||= {}
30
+ options[:headers] ||= {}
31
+ options[:headers].merge!('Content-Type': 'application/json')
32
+ response = @conn.post do |req|
33
+ req.url path
34
+ req.headers.merge!(options[:headers])
35
+ req.params['_utoken'] = @token
36
+ req.body = options[:params].to_s
37
+ end
38
+ [response.status, response.body]
39
+ end
40
+
41
+ def delete(path, options = {})
42
+ options[:params] ||= {}
43
+ options[:headers] ||= {}
44
+ options[:headers].merge!('Content-Type': 'application/json')
45
+ response = @conn.delete do |req|
46
+ req.url path
47
+ req.headers.merge!(options[:headers])
48
+ req.body = options[:params].merge({ '_utoken': @token }).to_s
49
+ end
50
+ [response.status, response.body]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ require 'nokogiri'
2
+
3
+ module Holistics
4
+ module Helper
5
+
6
+ class << self
7
+
8
+ def csrf_token(endpoint)
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ module Holistics
2
+ class Imports < SubcommandBase
3
+ def initialize(*args)
4
+ @this = Model::JobDefinition.new(Holistics.client, 'data_imports')
5
+ super
6
+ end
7
+ def self.help(*args)
8
+ super
9
+ puts <<-INSTRUCTION
10
+ Examples:
11
+ holistics imports list # List all import jobs
12
+
13
+ INSTRUCTION
14
+ end
15
+
16
+ desc 'list', 'List all import jobs'
17
+ def list
18
+ puts "`imports list` called with options: #{options}" if Holistics.debug?
19
+ tp(
20
+ @this.all.map do |item|
21
+ source = case item['source_type']
22
+ when 'dbtable'
23
+ source_config = item['source_config'][item['source_type']]
24
+ "(#{source_config['ds_id']}) #{source_config['fqname']}"
25
+ else
26
+ # TODO: add another source types
27
+ item['source_label']
28
+ end
29
+ destination = "(#{item['dest_ds_id']}) " + [item['dest_schema_name'], item['dest_table_name']].map(&:to_s).join('.')
30
+ last_run_status = if item['last_run_job']
31
+ case item['last_run_job']['status']
32
+ when 'success' then item['last_run_job']['status'].green
33
+ when 'failed' then item['last_run_job']['status'].red
34
+ else
35
+ item['last_run_job']['status']
36
+ end
37
+ else
38
+ 'unknown'.yellow
39
+ end
40
+ {
41
+ id: item['id'],
42
+ title: item['title'],
43
+ owner: item['owner_name'],
44
+ source: source,
45
+ destination: destination,
46
+ created_at: DateTime.parse(item['created_at']).to_formatted_s(:short),
47
+ last_run: DateTime.parse(item['last_run']).to_formatted_s(:short),
48
+ last_run_status: last_run_status
49
+ }
50
+ end
51
+ )
52
+ end
53
+
54
+ # desc 'info ID', 'Show a import job by id'
55
+ # def info(id)
56
+ # puts "`imports info #{id}` called with options: #{options}" if Holistics.debug?
57
+ # tp(@this.find(id))
58
+ # end
59
+
60
+ desc 'execute', 'Execute a import job by ID'
61
+ def execute(id)
62
+ puts "`imports execute #{id}` called with options: #{options}" if Holistics.debug?
63
+ result = @this.execute(id)
64
+ puts 'Job ID: ' + result['job_id'].to_s.yellow
65
+ puts 'Status: ' + Holistics::Utils.colorize(result['status'])
66
+ invoke 'holistics:jobs:logs', [result['job_id']], { watch: true }
67
+ end
68
+ map %w[exec] => :execute
69
+
70
+ # desc 'delete ID', 'Remove a import job by id'
71
+ # def delete(id)
72
+ # puts "`imports delete #{id}` called with options: #{options}" if Holistics.debug?
73
+ # tp(@this.remove(id))
74
+ # end
75
+
76
+ end
77
+ end
@@ -0,0 +1,97 @@
1
+ module Holistics
2
+ class Jobs < SubcommandBase
3
+ def initialize(*args)
4
+ super
5
+ @this = Model::Job.new(Holistics.client, 'jobs')
6
+ end
7
+ def self.help(*args)
8
+ super
9
+ puts <<-INSTRUCTION
10
+ Examples:
11
+ holistics jobs list -t transform # List all transform jobs
12
+
13
+ INSTRUCTION
14
+ end
15
+
16
+ desc 'list', 'List all jobs'
17
+ method_option :source_type, aliases: '-t', desc: 'Filter by job type: DataImport, DataTransform, ...'
18
+ def list
19
+ puts "`jobs list` called with options: #{options}" if Holistics.debug?
20
+ tp(
21
+ @this.all.map do |item|
22
+ {
23
+ id: item['id'],
24
+ source_method: item['source_method'],
25
+ title: item['title'],
26
+ created_at: DateTime.parse(item['created_at']).to_formatted_s(:short),
27
+ source_type: item['source_type'],
28
+ source_id: item['source_id'],
29
+ # start_time: DateTime.parse(item['start_time']).to_formatted_s(:short),
30
+ # end_time: DateTime.parse(item['end_time']).to_formatted_s(:short),
31
+ duration: Time.at(item['duration']).utc.strftime("%H:%M:%S"),
32
+ # cancelledable
33
+ user: item['user']['name'],
34
+ status: Holistics::Utils.colorize(item['status'])
35
+ }
36
+ end
37
+ )
38
+ end
39
+
40
+ desc 'info ID', 'Show a job by ID'
41
+ def info(id)
42
+ puts "`jobs info #{id}` called with options: #{options}" if Holistics.debug?
43
+ item = @this.find(id)
44
+ puts "Job ID: " + item['id'].to_s.yellow
45
+ {
46
+ status: Holistics::Utils.colorize(item['status']),
47
+ source_method: item['source_method'],
48
+ source_type: item['source_type'],
49
+ source_id: item['source_id'],
50
+ created_at: DateTime.parse(item['created_at']).to_formatted_s(:short),
51
+ user_id: item['user_id'],
52
+ start_time: DateTime.parse(item['start_time']).to_formatted_s(:short),
53
+ end_time: DateTime.parse(item['end_time']).to_formatted_s(:short),
54
+ tenant_id: item['tenant_id'],
55
+ duration: Time.at(item['duration']).utc.strftime("%H:%M:%S")
56
+ }.each { |k, v| puts "\t" + [k,v].join(": ") }
57
+ end
58
+
59
+ desc 'logs ID', 'Show job logs by ID'
60
+ method_option :watch, aliases: '-f', desc: 'Watch for new logs', type: :boolean
61
+ method_option :number, aliases: '-n', desc: 'Watch for new logs', type: :numeric
62
+ def logs(id)
63
+ puts "`jobs logs #{id}` called with options: #{options}" if Holistics.debug?
64
+ if options[:watch]
65
+ last_id = 0
66
+ loop do
67
+ data = @this.logs(id, { 'last_id': last_id })
68
+ print_logs(data['logs'])
69
+ last_id = data['logs'].last['id'] if data['logs'].length > 0
70
+ break unless data['has_more']
71
+ sleep 0.5
72
+ end
73
+ else
74
+ data = @this.logs(id)
75
+ print_logs(data['logs'], options[:number])
76
+ end
77
+ end
78
+
79
+ # desc 'cancel', 'Cancel a running job'
80
+ # def cancel(id)
81
+ # puts "Comming soon".yellow
82
+ # end
83
+
84
+ private
85
+
86
+ def print_logs(log_lines, line_count = 0)
87
+ line_count ||= 0
88
+ log_lines ||= []
89
+ log_lines[(-[line_count, log_lines.length].min)..-1]
90
+ log_lines.each do |log_line|
91
+ t = log_line['timestamp'] || Time.now.utc
92
+ puts "#{t}; #{log_line['level']}: #{log_line['message']}"
93
+ end
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,10 @@
1
+ module Holistics
2
+ module Model
3
+ class Job < Resource
4
+ def logs(id, params = {})
5
+ status, body = @client.get("/jobs/#{id}/logs.json", { params: params })
6
+ handle_http_result(status, body)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Holistics
2
+ module Model
3
+ class JobDefinition < Resource
4
+ def execute(id)
5
+ status, body = @client.post("/#{@name}/#{id}/execute.json")
6
+ handle_http_result(status, body)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ module Holistics
2
+ module Model
3
+ class Resource
4
+ attr_accessor :name
5
+ attr_accessor :errors
6
+
7
+ def initialize(client, name)
8
+ @client = client
9
+ @name = name
10
+ end
11
+
12
+ def all(params = {})
13
+ status, body = @client.get("/#{@name}.json", { params: params })
14
+ handle_http_result(status, body)
15
+ end
16
+
17
+ def find(id, params = {})
18
+ status, body = @client.get("/#{@name}/#{id}.json", { params: params })
19
+ handle_http_result(status, body)
20
+ end
21
+
22
+ def delete(id, params = {})
23
+ status, body = @client.delete("/#{@name}/#{id}.json", { params: params })
24
+ handle_http_result(status, body)
25
+ end
26
+
27
+ private
28
+
29
+ def handle_http_result(status, body)
30
+ self.errors = nil
31
+ result = JSON.parse(body)
32
+ if status == 200
33
+ result
34
+ else
35
+ self.errors = [result['error']].concat(result['errors'] || []).compact
36
+ STDERR.puts self.errors.join("\n").red
37
+ exit 1
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ module Holistics
2
+ class Sources < SubcommandBase
3
+ def initialize(*args)
4
+ super
5
+ @this = Model::Resource.new(Holistics.client, 'data_sources')
6
+ end
7
+ def self.help(*args)
8
+ super
9
+ puts <<-INSTRUCTION
10
+ Examples:
11
+ holistics sources list # List all data sources
12
+
13
+ INSTRUCTION
14
+ end
15
+
16
+ desc 'list', 'List all data sources'
17
+ def list
18
+ puts "`sources list` called with options: #{options}" if Holistics.debug?
19
+ tp(@this.all)
20
+ end
21
+
22
+ desc 'info ID', 'Show a data source by ID'
23
+ def info(id)
24
+ puts "`sources info #{id}` called with options: #{options}" if Holistics.debug?
25
+ item = @this.find(id)
26
+ puts "Source ID: " + item['id'].to_s.yellow
27
+ {
28
+ name: item['name'],
29
+ dbtype: item['dbtype'],
30
+ slug: item['slug'],
31
+ settings: item['settings']
32
+ }.each { |k, v| puts "\t" + [k,v].join(": ") }
33
+ end
34
+
35
+ # desc 'delete ID', 'Remove a data source by ID'
36
+ # def delete(id)
37
+ # puts "`sources delete #{id}` called with options: #{options}" if Holistics.debug?
38
+ # tp(@this.remove(id))
39
+ # end
40
+
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ module Holistics
2
+ class SubcommandBase < Thor
3
+ def self.banner(command, namespace = nil, subcommand = false)
4
+ "#{basename} #{subcommand_prefix} #{command.usage}"
5
+ end
6
+
7
+ def self.subcommand_prefix
8
+ self.name.gsub(%r{.*::}, '').gsub(%r{^[A-Z]}) { |match| match[0].downcase }.gsub(%r{[A-Z]}) { |match| "_#{match[0].downcase}" }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ module Holistics
2
+ class Transforms < SubcommandBase
3
+ def initialize(*args)
4
+ super
5
+ @this = Model::JobDefinition.new(Holistics.client, 'data_transforms')
6
+ end
7
+ def self.help(*args)
8
+ super
9
+ puts <<-INSTRUCTION
10
+ Examples:
11
+ holistics transforms list # List all data transformations
12
+
13
+ INSTRUCTION
14
+ end
15
+
16
+ desc 'list', 'List all data transformations'
17
+ def list(ds_id = nil)
18
+ puts "`transforms list` called with options: #{options}" if Holistics.debug?
19
+ tp(
20
+ @this.all.map do |item|
21
+ item.slice(*%w{id title owner_name}).merge({
22
+ mode: item['settings']['mode'],
23
+ created_at: DateTime.parse(item['created_at']).to_formatted_s(:short),
24
+ last_run: DateTime.parse(item['last_run']).to_formatted_s(:short)
25
+ })
26
+ end
27
+ )
28
+ end
29
+
30
+ desc 'info ID', 'Show a data transform by ID'
31
+ def info(id)
32
+ puts "`transform info #{id}` called with options: #{options}" if Holistics.debug?
33
+ tp(@this.find(id))
34
+ end
35
+
36
+ desc 'execute ID', 'Execute a transform job by ID'
37
+ def execute(id)
38
+ puts "`transforms execute #{id}` called with options: #{options}" if Holistics.debug?
39
+ result = @this.execute(id)
40
+ puts 'Job ID: ' + result['job_id'].to_s.yellow
41
+ puts 'Status: ' + Holistics::Utils.colorize(result['status'])
42
+ invoke 'holistics:jobs:logs', [result['job_id']], { watch: true }
43
+ end
44
+ map %w[exec] => :execute
45
+
46
+ # desc 'delete ID', 'Remove a data transform by ID'
47
+ # def delete(id)
48
+ # puts "`transform delete #{id}` called with options: #{options}" if Holistics.debug?
49
+ # tp(@this.remove(id))
50
+ # end
51
+
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ module Holistics
2
+ module Utils
3
+ class << self
4
+ COLORIZE_MAPPING = {
5
+ green: %w{active success ok},
6
+ red: %w{fail failure error cancelled},
7
+ yellow: %w{new pending unknown}
8
+ }
9
+ def colorize(text)
10
+ color = COLORIZE_MAPPING.find { |color, values| values.include?(text) }
11
+ color ? text.method(color[0]).call : text
12
+ end
13
+ def duration secs
14
+ [[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
15
+ if secs > 0
16
+ secs, n = secs.divmod(count)
17
+ "#{n.to_i} #{name}"
18
+ end
19
+ }.compact.reverse.join(' ')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Holistics
2
+ VERSION = '0.1.1'
3
+ end
data/lib/holistics.rb ADDED
@@ -0,0 +1,121 @@
1
+ require 'thor'
2
+ require 'colorize'
3
+ require 'json'
4
+ require 'table_print'
5
+ require 'fileutils'
6
+ require 'active_support/all'
7
+
8
+ # require 'byebug'
9
+
10
+ require 'holistics/version'
11
+ require 'holistics/subcommand_base'
12
+ require 'holistics/utils'
13
+ require 'holistics/client'
14
+ require 'holistics/models/resource'
15
+ require 'holistics/models/job_definition'
16
+ require 'holistics/models/job'
17
+ require 'holistics/sources'
18
+ require 'holistics/imports'
19
+ require 'holistics/transforms'
20
+ require 'holistics/jobs'
21
+
22
+ module Holistics
23
+
24
+ CONFIG_FILE = (ENV['HOME'] + '/.holistics/config').freeze
25
+
26
+ @@client = nil
27
+
28
+ def self.client=(client)
29
+ @@client = client
30
+ end
31
+
32
+ def self.client
33
+ @@client
34
+ end
35
+
36
+ def self.debug?
37
+ ENV['HOLISTICS_DEBUG'] == 'true'
38
+ end
39
+
40
+ class CLI < Thor
41
+
42
+ def initialize(args = [], local_options = {}, config = {})
43
+ require_config! unless %w{help config version}.include? config[:current_command].name
44
+ super
45
+ end
46
+
47
+ map %w[--version -v] => :version
48
+
49
+ desc 'version', 'Show version information'
50
+ def version
51
+ puts "\nHolistics CommandLine Interface version #{Holistics::VERSION}".yellow
52
+ end
53
+
54
+ desc 'config', 'Init or update config'
55
+ def config
56
+ token = nil
57
+ current_config = configured? ? read_config : {}
58
+ current_token = current_config[:token]
59
+ new_token = ask "Your Holistics token [#{current_token.light_black}]: "
60
+ new_token = nil if new_token.blank?
61
+ unless token = new_token || current_token
62
+ puts 'Failed to config, empty token provided !'
63
+ exit 1
64
+ else
65
+ write_config(:token => token)
66
+ end
67
+ end
68
+
69
+ desc 'sources', 'Data sources'
70
+ subcommand 'sources', Sources
71
+ map %w[source] => :sources
72
+
73
+ desc 'imports', 'Import jobs'
74
+ subcommand 'imports', Imports
75
+ map %w[import] => :imports
76
+
77
+ desc 'transforms', 'Data transformations'
78
+ subcommand 'transforms', Transforms
79
+ map %w[transform] => :transforms
80
+
81
+ desc 'jobs', 'Submitted jobs'
82
+ subcommand 'jobs', Jobs
83
+ map %w[job] => :jobs
84
+
85
+ private
86
+
87
+ def configured?
88
+ File.exists?(Holistics::CONFIG_FILE)
89
+ end
90
+
91
+ def require_config!
92
+ unless configured?
93
+ puts "Missing config, run #{'holistics config'.yellow} to init your"
94
+ exit 1
95
+ end
96
+ Holistics.client ||= Holistics::Client.new(nil, read_config[:token])
97
+ end
98
+
99
+ def read_config
100
+ result = {}
101
+ File.read(Holistics::CONFIG_FILE).split("\n").map do |line|
102
+ k, v = line.split("=").map(&:strip)
103
+ result[k.to_sym] = v
104
+ end
105
+ result
106
+ end
107
+
108
+ def write_config(config = {})
109
+ dir = Holistics::CONFIG_FILE.split('/')[0..-2].join('/')
110
+ unless File.directory?(dir)
111
+ FileUtils::mkdir dir
112
+ FileUtils.touch Holistics::CONFIG_FILE
113
+ puts 'Create ' + Holistics::CONFIG_FILE.green
114
+ end
115
+ File.open(Holistics::CONFIG_FILE, 'w+') do |file|
116
+ file.write config.map { |k,v| "#{k} = #{v}" }.join
117
+ end
118
+ puts "Config updated !"
119
+ end
120
+ end
121
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: holistics-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Thanh Pham Minh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: colorize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: table_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.5.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.5.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.2'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.11.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.11.0
139
+ description: CommandLine Interface for Holistics.io, proxy request through Holistics
140
+ HTTP API
141
+ email:
142
+ - phamminhthanh69@gmail.com
143
+ executables:
144
+ - holistics
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".byebug_history"
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".travis.yml"
152
+ - CODE_OF_CONDUCT.md
153
+ - Gemfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - bin/console
158
+ - bin/setup
159
+ - exe/holistics
160
+ - holistics.gemspec
161
+ - lib/holistics.rb
162
+ - lib/holistics/client.rb
163
+ - lib/holistics/helper.rb
164
+ - lib/holistics/imports.rb
165
+ - lib/holistics/jobs.rb
166
+ - lib/holistics/models/job.rb
167
+ - lib/holistics/models/job_definition.rb
168
+ - lib/holistics/models/resource.rb
169
+ - lib/holistics/sources.rb
170
+ - lib/holistics/subcommand_base.rb
171
+ - lib/holistics/transforms.rb
172
+ - lib/holistics/utils.rb
173
+ - lib/holistics/version.rb
174
+ homepage: https://github.com/pmint93/holistics-cli
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.12
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Holistics CommandLine Interface
198
+ test_files: []