cyclid-client 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cyclid/cli/admin.rb +3 -0
- data/lib/cyclid/cli/admin/job.rb +45 -0
- data/lib/cyclid/cli/admin/organization.rb +7 -7
- data/lib/cyclid/cli/admin/user.rb +7 -7
- data/lib/cyclid/cli/formatter.rb +73 -0
- data/lib/cyclid/cli/job.rb +36 -8
- data/lib/cyclid/cli/organization.rb +11 -10
- data/lib/cyclid/cli/organization/config.rb +9 -9
- data/lib/cyclid/cli/organization/member.rb +5 -5
- data/lib/cyclid/cli/secret.rb +1 -1
- data/lib/cyclid/cli/stage.rb +6 -6
- data/lib/cyclid/cli/user.rb +62 -6
- data/lib/cyclid/client.rb +6 -4
- data/lib/cyclid/client/api.rb +2 -0
- data/lib/cyclid/client/job.rb +19 -0
- data/lib/cyclid/config.rb +26 -1
- data/lib/cyclid/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 078b4e179f24bb0cd378bcd6993fd834bdcb4555
|
4
|
+
data.tar.gz: 0abab651a16850f267229149a11ebd59e58b089e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6635460d43ba93794cf903263d3b0f6341965b79cdd17ef5b1f5c06b5a42df653205c0c997039198a88f55c1ba143397c7f03f70037208e2db305cbf17108026
|
7
|
+
data.tar.gz: 696dd68c6329ac1159616b6174445543ab0c9ee162e2b1f0c9404a3401cdea245b505eed71e76d5c4eecea013f77707f71d84316289ae801ada9b711a495672b
|
data/lib/cyclid/cli/admin.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright 2016 Liqwyd Ltd.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Cyclid
|
17
|
+
module Cli
|
18
|
+
# 'admin job' sub-commands
|
19
|
+
class AdminJob < Thor
|
20
|
+
desc 'list NAME', 'List all jobs for the organization NAME'
|
21
|
+
def list(name)
|
22
|
+
stats = client.job_stats(name)
|
23
|
+
all = client.job_list(name, limit: stats['total'])
|
24
|
+
jobs = all['records']
|
25
|
+
|
26
|
+
jobs.each do |job|
|
27
|
+
Formatter.colorize 'Name', (job['job_name'] || '')
|
28
|
+
Formatter.colorize "\tJob", job['id'].to_s
|
29
|
+
Formatter.colorize "\tVersion", (job['job_version'] || '')
|
30
|
+
end
|
31
|
+
rescue StandardError => ex
|
32
|
+
abort "Failed to get job list: #{ex}"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'stats NAME', 'Show statistics about jobs for the organization NAME'
|
36
|
+
def stats(name)
|
37
|
+
stats = client.job_stats(name)
|
38
|
+
|
39
|
+
Formatter.colorize 'Total jobs', stats['total'].to_s
|
40
|
+
rescue StandardError => ex
|
41
|
+
abort "Failed to get job list: #{ex}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -36,16 +36,16 @@ module Cyclid
|
|
36
36
|
public_key = OpenSSL::PKey::RSA.new(der_key)
|
37
37
|
|
38
38
|
# Pretty print the organization details
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
Formatter.colorize 'Name', org['name']
|
40
|
+
Formatter.colorize 'Owner Email', org['owner_email']
|
41
|
+
Formatter.colorize 'Public Key', public_key.to_pem
|
42
|
+
Formatter.colorize 'Members:'
|
43
43
|
if org['users'].any?
|
44
44
|
org['users'].each do |user|
|
45
|
-
puts "\t#{user}"
|
45
|
+
Formatter.puts "\t#{user}"
|
46
46
|
end
|
47
47
|
else
|
48
|
-
puts "\tNone"
|
48
|
+
Formatter.puts "\tNone"
|
49
49
|
end
|
50
50
|
rescue StandardError => ex
|
51
51
|
abort "Failed to get organization: #{ex}"
|
@@ -107,7 +107,7 @@ module Cyclid
|
|
107
107
|
if options[:force]
|
108
108
|
delete = true
|
109
109
|
else
|
110
|
-
|
110
|
+
Formatter.ask "Delete organization #{name}: are you sure? (Y/n)"
|
111
111
|
delete = STDIN.getc.chr.casecmp('y').zero?
|
112
112
|
end
|
113
113
|
abort unless delete
|
@@ -32,16 +32,16 @@ module Cyclid
|
|
32
32
|
user = client.user_get(username)
|
33
33
|
|
34
34
|
# Pretty print the user details
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
Formatter.colorize 'Username', user['username']
|
36
|
+
Formatter.colorize 'Name', (user['name'] || '')
|
37
|
+
Formatter.colorize 'Email', user['email']
|
38
|
+
Formatter.colorize 'Organizations:'
|
39
39
|
if user['organizations'].any?
|
40
40
|
user['organizations'].each do |org|
|
41
|
-
puts "\t#{org}"
|
41
|
+
Formatter.puts "\t#{org}"
|
42
42
|
end
|
43
43
|
else
|
44
|
-
puts "\tNone"
|
44
|
+
Formatter.puts "\tNone"
|
45
45
|
end
|
46
46
|
rescue StandardError => ex
|
47
47
|
abort "Failed to get user: #{ex}"
|
@@ -127,7 +127,7 @@ module Cyclid
|
|
127
127
|
if options[:force]
|
128
128
|
delete = true
|
129
129
|
else
|
130
|
-
|
130
|
+
Formatter.ask "Delete user #{username}: are you sure? (Y/n)"
|
131
131
|
delete = STDIN.getc.chr.casecmp('y').zero?
|
132
132
|
end
|
133
133
|
abort unless delete
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright 2016 Liqwyd Ltd.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'colorize'
|
17
|
+
|
18
|
+
module Cyclid
|
19
|
+
module Cli
|
20
|
+
# Output formatter
|
21
|
+
module Formatter
|
22
|
+
# Output with no additional formatting
|
23
|
+
class Base
|
24
|
+
class << self
|
25
|
+
def puts(title, *args)
|
26
|
+
t = if args.empty?
|
27
|
+
title
|
28
|
+
else
|
29
|
+
"#{title}: "
|
30
|
+
end
|
31
|
+
Kernel.puts t + args.join
|
32
|
+
end
|
33
|
+
alias colorize puts
|
34
|
+
|
35
|
+
def ask(question)
|
36
|
+
print "#{question}: "
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Output with XTerm compatible color
|
42
|
+
class Terminal < Base
|
43
|
+
class << self
|
44
|
+
def colorize(title, *args)
|
45
|
+
t = if args.empty?
|
46
|
+
title
|
47
|
+
else
|
48
|
+
"#{title}: "
|
49
|
+
end
|
50
|
+
Kernel.puts t.colorize(:cyan) + args.join
|
51
|
+
end
|
52
|
+
|
53
|
+
def ask(question)
|
54
|
+
print "#{question}: ".colorize(:red)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class << self
|
60
|
+
def method_missing(method, *args, &block) # rubocop:disable Style/MethodMissing
|
61
|
+
@formatter ||= get
|
62
|
+
@formatter.send(method, *args, &block)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def get
|
68
|
+
STDOUT.tty? ? Terminal : Base
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/cyclid/cli/job.rb
CHANGED
@@ -63,7 +63,7 @@ module Cyclid
|
|
63
63
|
end
|
64
64
|
|
65
65
|
job_info = client.job_submit(client.config.organization, job, job_type)
|
66
|
-
|
66
|
+
Formatter.colorize 'Job', job_info['job_id'].to_s
|
67
67
|
rescue StandardError => ex
|
68
68
|
abort "Failed to submit job: #{ex}"
|
69
69
|
end
|
@@ -78,13 +78,17 @@ module Cyclid
|
|
78
78
|
started = job['started'].nil? ? nil : Time.parse(job['started'])
|
79
79
|
ended = job['ended'].nil? ? nil : Time.parse(job['ended'])
|
80
80
|
|
81
|
+
# Calculate the duration if the job contains a valid start & end time
|
82
|
+
duration = (Time.new(0) + (ended - started) if started && ended)
|
83
|
+
|
81
84
|
# Pretty-print the job details (without the log)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
Formatter.colorize 'Job', job['id'].to_s
|
86
|
+
Formatter.colorize 'Name', (job['job_name'] || '')
|
87
|
+
Formatter.colorize 'Version', (job['job_version'] || '')
|
88
|
+
Formatter.colorize 'Started', (started ? started.asctime : '')
|
89
|
+
Formatter.colorize 'Ended', (ended ? ended.asctime : '')
|
90
|
+
Formatter.colorize 'Duration', duration.strftime('%H:%M:%S') if duration
|
91
|
+
Formatter.colorize 'Status', status
|
88
92
|
rescue StandardError => ex
|
89
93
|
abort "Failed to get job status: #{ex}"
|
90
94
|
end
|
@@ -97,7 +101,7 @@ module Cyclid
|
|
97
101
|
status = Cyclid::API::Constants::JOB_STATUSES[status_id]
|
98
102
|
|
99
103
|
# Pretty-print the job status
|
100
|
-
|
104
|
+
Formatter.colorize 'Status', status
|
101
105
|
rescue StandardError => ex
|
102
106
|
abort "Failed to get job status: #{ex}"
|
103
107
|
end
|
@@ -110,6 +114,30 @@ module Cyclid
|
|
110
114
|
rescue StandardError => ex
|
111
115
|
abort "Failed to get job log: #{ex}"
|
112
116
|
end
|
117
|
+
|
118
|
+
desc 'list', 'List all jobs'
|
119
|
+
def list
|
120
|
+
stats = client.job_stats(client.config.organization)
|
121
|
+
all = client.job_list(client.config.organization, limit: stats['total'])
|
122
|
+
jobs = all['records']
|
123
|
+
|
124
|
+
jobs.each do |job|
|
125
|
+
Formatter.colorize 'Name', (job['job_name'] || '')
|
126
|
+
Formatter.colorize "\tJob", job['id'].to_s
|
127
|
+
Formatter.colorize "\tVersion", (job['job_version'] || '')
|
128
|
+
end
|
129
|
+
rescue StandardError => ex
|
130
|
+
abort "Failed to get job list: #{ex}"
|
131
|
+
end
|
132
|
+
|
133
|
+
desc 'stats', 'Show statistics about jobs'
|
134
|
+
def stats
|
135
|
+
stats = client.job_stats(client.config.organization)
|
136
|
+
|
137
|
+
Formatter.colorize 'Total jobs', stats['total'].to_s
|
138
|
+
rescue StandardError => ex
|
139
|
+
abort "Failed to get job list: #{ex}"
|
140
|
+
end
|
113
141
|
end
|
114
142
|
end
|
115
143
|
end
|
@@ -31,10 +31,10 @@ module Cyclid
|
|
31
31
|
public_key = OpenSSL::PKey::RSA.new(der_key)
|
32
32
|
|
33
33
|
# Pretty print the organization details
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
Formatter.colorize 'Name', org['name']
|
35
|
+
Formatter.colorize 'Owner Email', org['owner_email']
|
36
|
+
Formatter.colorize 'Public Key', public_key.to_pem
|
37
|
+
Formatter.colorize 'Members'
|
38
38
|
if org['users'].any?
|
39
39
|
org['users'].each do |user|
|
40
40
|
puts "\t#{user}"
|
@@ -70,11 +70,12 @@ module Cyclid
|
|
70
70
|
# Create a Config from this file and display the details
|
71
71
|
config = Cyclid::Client::Config.new(path: fname)
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
Formatter.colorize File.basename(fname)
|
74
|
+
scheme = config.tls ? URI::HTTPS : URI::HTTP
|
75
|
+
uri = scheme.build(host: config.server, port: config.port)
|
76
|
+
Formatter.colorize "\tURL", uri.to_s
|
77
|
+
Formatter.colorize "\tOrganization", config.organization
|
78
|
+
Formatter.colorize "\tUsername", config.username
|
78
79
|
rescue StandardError => ex
|
79
80
|
$stderr.puts "Failed to load config file #{fname}: #{ex}"
|
80
81
|
end
|
@@ -114,7 +115,7 @@ module Cyclid
|
|
114
115
|
# The configuration file exists and appears to be sane, so switch the
|
115
116
|
# 'config' symlink to point to it.
|
116
117
|
Dir.chdir(CYCLID_CONFIG_DIR) do
|
117
|
-
File.delete('config')
|
118
|
+
File.delete('config') if File.exist?('config')
|
118
119
|
File.symlink(name, 'config')
|
119
120
|
end
|
120
121
|
end
|
@@ -30,32 +30,32 @@ module Cyclid
|
|
30
30
|
case type
|
31
31
|
when 'string', 'integer'
|
32
32
|
data = config[name] || 'Not set'
|
33
|
-
|
33
|
+
Formatter.colorize setting['description'], data
|
34
34
|
when 'password'
|
35
35
|
data = config[name] ? '*' * config[name].length : 'Not set'
|
36
|
-
|
36
|
+
Formatter.colorize setting['description'], data
|
37
37
|
when 'boolean'
|
38
38
|
data = config[name] || 'Not set'
|
39
|
-
|
39
|
+
Formatter.colorize setting['description'], (data ? 'true' : 'false')
|
40
40
|
when 'list'
|
41
|
-
|
41
|
+
Formatter.colorize setting['description']
|
42
42
|
data = config[name]
|
43
43
|
if data.empty?
|
44
|
-
puts "\tNone"
|
44
|
+
Formatter.puts "\tNone"
|
45
45
|
else
|
46
46
|
data.each do |item|
|
47
|
-
puts "\t#{item}"
|
47
|
+
Formatter.puts "\t#{item}"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
when 'hash-list'
|
51
|
-
|
51
|
+
Formatter.colorize setting['description']
|
52
52
|
data = config[name]
|
53
53
|
if data.empty?
|
54
|
-
puts "\tNone"
|
54
|
+
Formatter.puts "\tNone"
|
55
55
|
else
|
56
56
|
data.each do |item|
|
57
57
|
item.each do |k, v|
|
58
|
-
puts "\t#{k}: #{v}"
|
58
|
+
Formatter.puts "\t#{k}: #{v}"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -82,11 +82,11 @@ module Cyclid
|
|
82
82
|
user = client.org_user_get(client.config.organization, user)
|
83
83
|
|
84
84
|
# Pretty print the user details
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
Formatter.colorize 'Username', user['username']
|
86
|
+
Formatter.colorize 'Email: ', user['email']
|
87
|
+
Formatter.colorize 'Permissions'
|
88
88
|
user['permissions'].each do |k, v|
|
89
|
-
|
89
|
+
Formatter.colorize "\t#{k.capitalize}", v.to_s
|
90
90
|
end
|
91
91
|
rescue StandardError => ex
|
92
92
|
abort "Failed to get user: #{ex}"
|
@@ -110,7 +110,7 @@ module Cyclid
|
|
110
110
|
if options[:force]
|
111
111
|
true
|
112
112
|
else
|
113
|
-
|
113
|
+
Formatter.ask "Remove user #{user}: are you sure? (Y/n)"
|
114
114
|
STDIN.getc.chr.casecmp('y').zero?
|
115
115
|
end
|
116
116
|
end
|
data/lib/cyclid/cli/secret.rb
CHANGED
@@ -34,7 +34,7 @@ module Cyclid
|
|
34
34
|
# Encrypt with the public key
|
35
35
|
encrypted = public_key.public_encrypt(secret)
|
36
36
|
|
37
|
-
|
37
|
+
Formatter.colorize 'Secret', Base64.strict_encode64(encrypted)
|
38
38
|
rescue StandardError => ex
|
39
39
|
abort "Failed to encrypt secret: #{ex}"
|
40
40
|
end
|
data/lib/cyclid/cli/stage.rb
CHANGED
@@ -21,7 +21,7 @@ module Cyclid
|
|
21
21
|
def list
|
22
22
|
stages = client.stage_list(client.config.organization)
|
23
23
|
stages.each do |stage|
|
24
|
-
puts "#{stage[:name]} v#{stage[:version]}"
|
24
|
+
Formatter.puts "#{stage[:name]} v#{stage[:version]}"
|
25
25
|
end
|
26
26
|
rescue StandardError => ex
|
27
27
|
abort "Failed to get stages: #{ex}"
|
@@ -33,14 +33,14 @@ module Cyclid
|
|
33
33
|
|
34
34
|
# Pretty print the stage details
|
35
35
|
stages.each do |stage|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
Formatter.colorize 'Name', stage['name']
|
37
|
+
Formatter.colorize 'Version', stage['version']
|
38
|
+
Formatter.colorize 'Steps'
|
39
39
|
stage['steps'].each do |step|
|
40
|
-
|
40
|
+
Formatter.colorize"\t\tAction", step['action']
|
41
41
|
step.delete('action')
|
42
42
|
step.each do |k, v|
|
43
|
-
|
43
|
+
Formatter.colorize "\t\t#{k.capitalize}: ", v.to_s
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/cyclid/cli/user.rb
CHANGED
@@ -25,16 +25,16 @@ module Cyclid
|
|
25
25
|
user = client.user_get(client.config.username)
|
26
26
|
|
27
27
|
# Pretty print the user details
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
Formatter.colorize 'Username', user['username']
|
29
|
+
Formatter.colorize 'Name', (user['name'] || '')
|
30
|
+
Formatter.colorize 'Email', user['email']
|
31
|
+
Formatter.colorize 'Organizations'
|
32
32
|
if user['organizations'].any?
|
33
33
|
user['organizations'].each do |org|
|
34
|
-
puts "\t#{org}"
|
34
|
+
Formatter.puts "\t#{org}"
|
35
35
|
end
|
36
36
|
else
|
37
|
-
puts "\tNone"
|
37
|
+
Formatter.puts "\tNone"
|
38
38
|
end
|
39
39
|
rescue StandardError => ex
|
40
40
|
abort "Failed to get user: #{ex}"
|
@@ -80,6 +80,62 @@ module Cyclid
|
|
80
80
|
abort "Failed to modify user: #{ex}"
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
desc 'authenticate', 'Authenticate your client with a server'
|
85
|
+
long_desc <<-LONGDESC
|
86
|
+
Authenticate against a Cyclid server with your username & password and
|
87
|
+
create your client configuration files.
|
88
|
+
|
89
|
+
The --server option sets the Cyclid server URL. The default is 'https://api.cyclid.io'
|
90
|
+
|
91
|
+
The --username option sets your username to authenticate with.
|
92
|
+
LONGDESC
|
93
|
+
|
94
|
+
option :server, aliases: '-s'
|
95
|
+
option :username, aliases: '-u'
|
96
|
+
def authenticate
|
97
|
+
url = options[:server] || 'https://api.cyclid.io'
|
98
|
+
username = options[:username]
|
99
|
+
|
100
|
+
# Get the username if one wasn't provided
|
101
|
+
if username.nil?
|
102
|
+
print 'Username: '
|
103
|
+
username = STDIN.gets.chomp
|
104
|
+
end
|
105
|
+
|
106
|
+
# Get the users password
|
107
|
+
print 'Password: '
|
108
|
+
password = STDIN.noecho(&:gets).chomp
|
109
|
+
puts
|
110
|
+
|
111
|
+
# Create a client that can authenticate with HTTP BASIC
|
112
|
+
Formatter.colorize "Authenticating #{username} with #{url}"
|
113
|
+
|
114
|
+
basic_client = Cyclid::Client::Tilapia.new(auth: Cyclid::Client::AuthMethods::AUTH_BASIC,
|
115
|
+
url: url,
|
116
|
+
username: username,
|
117
|
+
password: password,
|
118
|
+
log_level: debug?)
|
119
|
+
|
120
|
+
# Get the user information
|
121
|
+
user = basic_client.user_get(username)
|
122
|
+
|
123
|
+
# Ensure the configuration directory exists
|
124
|
+
Dir.mkdir(CYCLID_CONFIG_DIR, 0o700) unless Dir.exist? CYCLID_CONFIG_DIR
|
125
|
+
|
126
|
+
# Generate a configuration file for each organization
|
127
|
+
user['organizations'].each do |org|
|
128
|
+
Formatter.colorize "Creating configuration file for organization #{org}"
|
129
|
+
|
130
|
+
org_config = File.new(File.join(CYCLID_CONFIG_DIR, org), 'w+', 0o600)
|
131
|
+
org_config.write "url: #{url}\n"
|
132
|
+
org_config.write "organization: #{org}\n"
|
133
|
+
org_config.write "username: #{username}\n"
|
134
|
+
org_config.write "secret: #{user['secret']}\n"
|
135
|
+
end
|
136
|
+
rescue StandardError => ex
|
137
|
+
abort "Failed to authenticate user: #{ex}"
|
138
|
+
end
|
83
139
|
end
|
84
140
|
end
|
85
141
|
end
|
data/lib/cyclid/client.rb
CHANGED
@@ -83,10 +83,12 @@ module Cyclid
|
|
83
83
|
private
|
84
84
|
|
85
85
|
# Build a URI for the configured server & required resource
|
86
|
-
def server_uri(path)
|
87
|
-
URI::
|
88
|
-
|
89
|
-
|
86
|
+
def server_uri(path, query = nil)
|
87
|
+
scheme = @config.tls ? URI::HTTPS : URI::HTTP
|
88
|
+
scheme.build(host: @config.server,
|
89
|
+
port: @config.port,
|
90
|
+
path: URI.escape(path),
|
91
|
+
query: query ? URI.escape(query) : nil)
|
90
92
|
end
|
91
93
|
|
92
94
|
def method_missing(method, *args, &block) # rubocop:disable Style/MethodMissing
|
data/lib/cyclid/client/api.rb
CHANGED
data/lib/cyclid/client/job.rb
CHANGED
@@ -84,6 +84,25 @@ module Cyclid
|
|
84
84
|
|
85
85
|
return res_data
|
86
86
|
end
|
87
|
+
|
88
|
+
def job_stats(organization)
|
89
|
+
uri = server_uri("/organizations/#{organization}/jobs", 'stats_only=true')
|
90
|
+
res_data = api_get(uri)
|
91
|
+
@logger.debug res_data
|
92
|
+
|
93
|
+
return res_data
|
94
|
+
end
|
95
|
+
|
96
|
+
def job_list(organization, args = {})
|
97
|
+
# Convert the args hash into a query string
|
98
|
+
query = args.map { |k, v| "#{k}=#{v}" }.join('&')
|
99
|
+
|
100
|
+
uri = server_uri("/organizations/#{organization}/jobs", query)
|
101
|
+
res_data = api_get(uri)
|
102
|
+
@logger.debug res_data
|
103
|
+
|
104
|
+
return res_data
|
105
|
+
end
|
87
106
|
end
|
88
107
|
end
|
89
108
|
end
|
data/lib/cyclid/config.rb
CHANGED
@@ -14,13 +14,23 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
16
|
require 'yaml'
|
17
|
+
require 'uri'
|
17
18
|
require 'cyclid/auth_methods'
|
18
19
|
|
19
20
|
module Cyclid
|
20
21
|
module Client
|
21
22
|
# Cyclid client per-organization configuration
|
22
23
|
class Config
|
23
|
-
attr_reader :auth,
|
24
|
+
attr_reader :auth,
|
25
|
+
:server,
|
26
|
+
:port,
|
27
|
+
:tls,
|
28
|
+
:organization,
|
29
|
+
:username,
|
30
|
+
:secret,
|
31
|
+
:password,
|
32
|
+
:token,
|
33
|
+
:path
|
24
34
|
# @!attribute [r] auth
|
25
35
|
# @return [Fixnum] the authentication method. (Default is AUTH_HMAC)
|
26
36
|
# @!attribute [r] server
|
@@ -71,19 +81,34 @@ module Cyclid
|
|
71
81
|
end
|
72
82
|
|
73
83
|
# Set defaults from the options
|
84
|
+
@url = options[:url] || nil
|
74
85
|
@server = options[:server] || nil
|
75
86
|
@port = options[:port] || nil
|
87
|
+
@tls = options[:tls] || nil
|
76
88
|
@organization = options[:organization] || nil
|
77
89
|
@username = options[:username] || nil
|
78
90
|
|
79
91
|
# Get anything provided in the config file
|
80
92
|
if @config
|
93
|
+
@url ||= @config['url']
|
81
94
|
@server ||= @config['server']
|
82
95
|
@port ||= @config['port'] || 8361
|
96
|
+
@tls ||= @config['tls'] || false
|
83
97
|
@organization ||= @config['organization']
|
84
98
|
@username ||= @config['username']
|
85
99
|
end
|
86
100
|
|
101
|
+
# Parse the URL if one was given
|
102
|
+
if @url
|
103
|
+
uri = URI.parse(@url)
|
104
|
+
|
105
|
+
# Items parsed from the uri always over-write any individual
|
106
|
+
# configuration settings
|
107
|
+
@server = uri.host
|
108
|
+
@port = uri.port
|
109
|
+
@tls = uri.scheme == 'https' ? true : false
|
110
|
+
end
|
111
|
+
|
87
112
|
# Server & Username *must* be set
|
88
113
|
raise 'server address must be provided' if @server.nil?
|
89
114
|
raise 'username must be provided' if @username.nil? and @auth != AUTH_NONE
|
data/lib/cyclid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyclid-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Van Der Vliet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -108,8 +108,10 @@ files:
|
|
108
108
|
- lib/cyclid/auth_methods.rb
|
109
109
|
- lib/cyclid/cli.rb
|
110
110
|
- lib/cyclid/cli/admin.rb
|
111
|
+
- lib/cyclid/cli/admin/job.rb
|
111
112
|
- lib/cyclid/cli/admin/organization.rb
|
112
113
|
- lib/cyclid/cli/admin/user.rb
|
114
|
+
- lib/cyclid/cli/formatter.rb
|
113
115
|
- lib/cyclid/cli/job.rb
|
114
116
|
- lib/cyclid/cli/organization.rb
|
115
117
|
- lib/cyclid/cli/organization/config.rb
|