qtc-sdk 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/Changelog.md +23 -18
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +22 -22
  6. data/README.md +44 -44
  7. data/Rakefile +1 -1
  8. data/bin/qtc-cli +13 -13
  9. data/lib/qtc-sdk.rb +1 -1
  10. data/lib/qtc/cli/commands.rb +15 -15
  11. data/lib/qtc/cli/common.rb +146 -146
  12. data/lib/qtc/cli/eds/base.rb +27 -27
  13. data/lib/qtc/cli/eds/commands.rb +20 -20
  14. data/lib/qtc/cli/eds/instances.rb +30 -30
  15. data/lib/qtc/cli/mar/apps.rb +116 -116
  16. data/lib/qtc/cli/mar/base.rb +60 -60
  17. data/lib/qtc/cli/mar/commands.rb +266 -221
  18. data/lib/qtc/cli/mar/debug.rb +88 -88
  19. data/lib/qtc/cli/mar/domains.rb +35 -35
  20. data/lib/qtc/cli/mar/env.rb +38 -38
  21. data/lib/qtc/cli/mar/repository.rb +24 -24
  22. data/lib/qtc/cli/mar/slugs.rb +80 -0
  23. data/lib/qtc/cli/mar/ssl_certificates.rb +40 -40
  24. data/lib/qtc/cli/mar/stack.rb +29 -29
  25. data/lib/qtc/cli/mdb/base.rb +47 -47
  26. data/lib/qtc/cli/mdb/commands.rb +43 -43
  27. data/lib/qtc/cli/mdb/instances.rb +79 -79
  28. data/lib/qtc/cli/platform/clouds.rb +33 -33
  29. data/lib/qtc/cli/platform/commands.rb +132 -132
  30. data/lib/qtc/cli/platform/datacenters.rb +23 -23
  31. data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
  32. data/lib/qtc/cli/platform/user.rb +25 -25
  33. data/lib/qtc/cli/platform/vpn.rb +93 -93
  34. data/lib/qtc/client.rb +170 -170
  35. data/lib/qtc/eds/client.rb +116 -116
  36. data/lib/qtc/eds/collection.rb +124 -124
  37. data/lib/qtc/eds/user_collection.rb +13 -13
  38. data/lib/qtc/eds/usergroup_collection.rb +41 -41
  39. data/lib/qtc/errors.rb +13 -13
  40. data/lib/qtc/version.rb +3 -3
  41. data/qtc-sdk.gemspec +28 -28
  42. data/spec/unit/qtc/client_spec.rb +147 -147
  43. metadata +4 -3
@@ -1,40 +1,40 @@
1
- require 'base64'
2
- require_relative 'base'
3
-
4
- module Qtc
5
- module Cli
6
- class Mar::SslCertificates < Mar::Base
7
-
8
-
9
- def create(options)
10
- raise ArgumentError.new("--key=#{options.key} is not a file") unless File.exists?(File.expand_path(options.key))
11
- raise ArgumentError.new("--cert=#{options.cert} is not a file") unless File.exists?(File.expand_path(options.cert))
12
- unless options.chain.nil?
13
- raise ArgumentError.new("--chain=#{options.chain} is not a file") unless File.exists?(File.expand_path(options.chain))
14
- end
15
-
16
- instance_id = resolve_instance_id(options)
17
- instance_data = instance_info(instance_id)
18
- if instance_data
19
- data = {
20
- name: instance_id,
21
- privateKey: File.read(File.expand_path(options.key)),
22
- certificateBody: File.read(File.expand_path(options.cert))
23
- }
24
- unless options.chain.nil?
25
- data[:certificateChain] = File.read(File.expand_path(options.chain))
26
- end
27
- client.post("/apps/#{instance_id}/ssl_certificate", data, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
28
- end
29
- end
30
-
31
- def destroy(options)
32
- instance_id = resolve_instance_id(options)
33
- instance_data = instance_info(instance_id)
34
- if instance_data
35
- client.delete("/apps/#{instance_id}/ssl_certificate", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
36
- end
37
- end
38
- end
39
- end
40
- end
1
+ require 'base64'
2
+ require_relative 'base'
3
+
4
+ module Qtc
5
+ module Cli
6
+ class Mar::SslCertificates < Mar::Base
7
+
8
+
9
+ def create(options)
10
+ raise ArgumentError.new("--key=#{options.key} is not a file") unless File.exists?(File.expand_path(options.key))
11
+ raise ArgumentError.new("--cert=#{options.cert} is not a file") unless File.exists?(File.expand_path(options.cert))
12
+ unless options.chain.nil?
13
+ raise ArgumentError.new("--chain=#{options.chain} is not a file") unless File.exists?(File.expand_path(options.chain))
14
+ end
15
+
16
+ instance_id = resolve_instance_id(options)
17
+ instance_data = instance_info(instance_id)
18
+ if instance_data
19
+ data = {
20
+ name: instance_id,
21
+ privateKey: File.read(File.expand_path(options.key)),
22
+ certificateBody: File.read(File.expand_path(options.cert))
23
+ }
24
+ unless options.chain.nil?
25
+ data[:certificateChain] = File.read(File.expand_path(options.chain))
26
+ end
27
+ client.post("/apps/#{instance_id}/ssl_certificate", data, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
28
+ end
29
+ end
30
+
31
+ def destroy(options)
32
+ instance_id = resolve_instance_id(options)
33
+ instance_data = instance_info(instance_id)
34
+ if instance_data
35
+ client.delete("/apps/#{instance_id}/ssl_certificate", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,29 +1,29 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mar::Stack < Mar::Base
6
-
7
- def update(name, options)
8
- instance_id = resolve_instance_id(options)
9
- instance_data = instance_info(instance_id)
10
- if instance_data
11
- client.put("/apps/#{instance_id}", {stack: name}, nil, {'Authorization' => "Bearer #{current_cloud_token}"})
12
- puts "Stack is now set to: #{name}"
13
- puts "Next release on #{instance_data['name']} will use #{name} stack."
14
- puts "Use `git push <remote> master` to create new release on #{name}"
15
- end
16
- end
17
-
18
- def show(options)
19
- instance_id = resolve_instance_id(options)
20
- instance_data = instance_info(instance_id)
21
- if instance_data
22
- env_vars = client.get("/apps/#{instance_id}/env_vars", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
- puts "App is using stack: #{env_vars['STACK']}"
24
- puts ""
25
- end
26
- end
27
- end
28
- end
29
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mar::Stack < Mar::Base
6
+
7
+ def update(name, options)
8
+ instance_id = resolve_instance_id(options)
9
+ instance_data = instance_info(instance_id)
10
+ if instance_data
11
+ client.put("/apps/#{instance_id}", {stack: name}, nil, {'Authorization' => "Bearer #{current_cloud_token}"})
12
+ puts "Stack is now set to: #{name}"
13
+ puts "Next release on #{instance_data['name']} will use #{name} stack."
14
+ puts "Use `git push <remote> master` to create new release on #{name}"
15
+ end
16
+ end
17
+
18
+ def show(options)
19
+ instance_id = resolve_instance_id(options)
20
+ instance_data = instance_info(instance_id)
21
+ if instance_data
22
+ env_vars = client.get("/apps/#{instance_id}/env_vars", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
+ puts "App is using stack: #{env_vars['STACK']}"
24
+ puts ""
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,47 +1,47 @@
1
- require_relative '../../client'
2
- require_relative '../common'
3
-
4
- module Qtc
5
- module Cli
6
- module Mdb
7
- class Base
8
- include Cli::Common
9
-
10
- protected
11
-
12
- ##
13
- # @param [String] instance_id
14
- # @return [String,NilClass]
15
- def resolve_datacenter_id(instance_id)
16
- match = instance_id.to_s.match(/^(mdb-\w+-\w+)-\w+/)
17
- if match[1]
18
- match[1]
19
- end
20
- end
21
-
22
- def mdb_datacenter_id
23
- "mdb-#{current_cloud_dc}"
24
- end
25
-
26
- ##
27
- # @return [Qtc::Client]
28
- def client
29
- if @client.nil?
30
- @client = Qtc::Client.new(base_url)
31
- end
32
-
33
- @client
34
- end
35
-
36
- def base_url
37
- datacenters = inifile['datacenters'] || {}
38
- if !self.datacenter_id.nil? && datacenters.has_key?(self.datacenter_id)
39
- "#{datacenters[self.datacenter_id]}/v1"
40
- else
41
- raise ArgumentError.new('Unknown datacenter. Please run qtc-cli datacenters to get latest list of your datacenters')
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
1
+ require_relative '../../client'
2
+ require_relative '../common'
3
+
4
+ module Qtc
5
+ module Cli
6
+ module Mdb
7
+ class Base
8
+ include Cli::Common
9
+
10
+ protected
11
+
12
+ ##
13
+ # @param [String] instance_id
14
+ # @return [String,NilClass]
15
+ def resolve_datacenter_id(instance_id)
16
+ match = instance_id.to_s.match(/^(mdb-\w+-\w+)-\w+/)
17
+ if match[1]
18
+ match[1]
19
+ end
20
+ end
21
+
22
+ def mdb_datacenter_id
23
+ "mdb-#{current_cloud_dc}"
24
+ end
25
+
26
+ ##
27
+ # @return [Qtc::Client]
28
+ def client
29
+ if @client.nil?
30
+ @client = Qtc::Client.new(base_url)
31
+ end
32
+
33
+ @client
34
+ end
35
+
36
+ def base_url
37
+ datacenters = inifile['datacenters'] || {}
38
+ if !self.datacenter_id.nil? && datacenters.has_key?(self.datacenter_id)
39
+ "#{datacenters[self.datacenter_id]}/v1"
40
+ else
41
+ raise ArgumentError.new('Unknown datacenter. Please run qtc-cli datacenters to get latest list of your datacenters')
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,43 +1,43 @@
1
- require_relative 'instances'
2
-
3
- command 'mdb list' do |c|
4
- c.syntax = 'qtc-cli mdb list'
5
- c.description = 'List all MDB instances'
6
- c.action do |args, options|
7
- Qtc::Cli::Mdb::Instances.new.list
8
- end
9
- end
10
-
11
- command 'mdb show' do |c|
12
- c.syntax = 'qtc-cli mdb show'
13
- c.description = 'Show MDB instance info'
14
- c.option '--id ID', String, 'MDB instance id'
15
- c.action do |args, options|
16
- Qtc::Cli::Mdb::Instances.new.show(options)
17
- end
18
- end
19
-
20
- command 'mdb create' do |c|
21
- c.syntax = 'qtc-cli mdb create NAME'
22
- c.description = 'Create a new MDB instance'
23
- c.option '--type TYPE', String, 'MDB type'
24
- c.option '--size SIZE', String, 'MDB size'
25
- c.action do |args, options|
26
- raise ArgumentError.new('NAME is required') if args[0].nil?
27
- raise ArgumentError.new('--type is required (example: mysql:5.6)') if options.type.nil?
28
- Qtc::Cli::Mdb::Instances.new.create(args[0], options)
29
- end
30
- end
31
-
32
- command 'mdb logs' do |c|
33
- c.syntax = 'qtc-cli mdb logs'
34
- c.description = 'Show MDB logs'
35
- c.option '--id ID', String, 'MDB instance id'
36
- c.option '--timestamp', String, 'Include timestamp'
37
- c.option '--stream', String, 'stdout or stderr'
38
- c.option '--limit LIMIT', Integer, 'Limit'
39
- c.option '--offset OFFSET', Integer, 'Offset'
40
- c.action do |args, options|
41
- Qtc::Cli::Mdb::Instances.new.logs(options)
42
- end
43
- end
1
+ require_relative 'instances'
2
+
3
+ command 'mdb list' do |c|
4
+ c.syntax = 'qtc-cli mdb list'
5
+ c.description = 'List all MDB instances'
6
+ c.action do |args, options|
7
+ Qtc::Cli::Mdb::Instances.new.list
8
+ end
9
+ end
10
+
11
+ command 'mdb show' do |c|
12
+ c.syntax = 'qtc-cli mdb show'
13
+ c.description = 'Show MDB instance info'
14
+ c.option '--id ID', String, 'MDB instance id'
15
+ c.action do |args, options|
16
+ Qtc::Cli::Mdb::Instances.new.show(options)
17
+ end
18
+ end
19
+
20
+ command 'mdb create' do |c|
21
+ c.syntax = 'qtc-cli mdb create NAME'
22
+ c.description = 'Create a new MDB instance'
23
+ c.option '--type TYPE', String, 'MDB type'
24
+ c.option '--size SIZE', String, 'MDB size'
25
+ c.action do |args, options|
26
+ raise ArgumentError.new('NAME is required') if args[0].nil?
27
+ raise ArgumentError.new('--type is required (example: mysql:5.6)') if options.type.nil?
28
+ Qtc::Cli::Mdb::Instances.new.create(args[0], options)
29
+ end
30
+ end
31
+
32
+ command 'mdb logs' do |c|
33
+ c.syntax = 'qtc-cli mdb logs'
34
+ c.description = 'Show MDB logs'
35
+ c.option '--id ID', String, 'MDB instance id'
36
+ c.option '--timestamp', String, 'Include timestamp'
37
+ c.option '--stream', String, 'stdout or stderr'
38
+ c.option '--limit LIMIT', Integer, 'Limit'
39
+ c.option '--offset OFFSET', Integer, 'Offset'
40
+ c.action do |args, options|
41
+ Qtc::Cli::Mdb::Instances.new.logs(options)
42
+ end
43
+ end
@@ -1,79 +1,79 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mdb::Instances < Mdb::Base
6
- include Qtc::Cli::Common
7
-
8
- def list
9
- instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mdb'})
10
- template = "%-20.20s %-30.30s %-20.20s"
11
- puts template % ["ID", "NAME", "TAGS"]
12
- instances['results'].each do |instance|
13
- puts template % [instance['id'], instance['name'], instance['tags'].join(',')]
14
- end
15
- end
16
-
17
- def show(options)
18
- raise ArgumentError.new('--id is required') if options.id.nil?
19
-
20
- self.datacenter_id = self.resolve_datacenter_id(options.id)
21
- instance_id = options.id
22
- instance_data = instance_info(instance_id)
23
- if instance_data
24
- result = client.get("/services/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
25
- puts "Id: #{result['id']}"
26
- puts "Name: #{result['name']}"
27
- puts "Type: #{result['image']['name']}"
28
- puts "Size: #{result['size'].to_i * 256}MB"
29
- puts "State: #{result['state']}"
30
- puts "Ip address: #{result['ip_address']}"
31
- puts "Port: #{result['port']}"
32
- if result['username']
33
- puts "Username: #{result['username']}"
34
- end
35
- if result['password']
36
- puts "Password: #{result['password']}"
37
- end
38
- end
39
- end
40
-
41
- def create(name, options)
42
- sizes = {'256m' => 1, '512m' => 2, '768m' => 3, '1024m' => 4}
43
- size = sizes[options.size.to_s.to_sym] || 1
44
- data = {
45
- name: name,
46
- serviceProviderId: 'mdb',
47
- config: {
48
- runtimeSize: size,
49
- serviceImage: "qtcs/#{options.type}"
50
- }
51
- }
52
- response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
53
- puts response['id']
54
- end
55
-
56
- def logs(options)
57
- raise ArgumentError.new('--id is required') if options.id.nil?
58
-
59
- self.datacenter_id = self.resolve_datacenter_id(options.id)
60
- offset = options.offset || 0
61
- limit = options.limit || 100
62
- stream = options.stream || nil
63
-
64
- instance_id = options.id
65
- instance_data = instance_info(instance_id)
66
- if instance_data
67
- result = client.get("/services/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
68
- result['results'].each do |r|
69
- line = ''
70
- line << "[#{r['time']}] " if options.timestamp == true
71
- line << r['log']
72
- puts line
73
- end
74
- end
75
- end
76
-
77
- end
78
- end
79
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mdb::Instances < Mdb::Base
6
+ include Qtc::Cli::Common
7
+
8
+ def list
9
+ instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mdb'})
10
+ template = "%-20.20s %-30.30s %-20.20s"
11
+ puts template % ["ID", "NAME", "TAGS"]
12
+ instances['results'].each do |instance|
13
+ puts template % [instance['id'], instance['name'], instance['tags'].join(',')]
14
+ end
15
+ end
16
+
17
+ def show(options)
18
+ raise ArgumentError.new('--id is required') if options.id.nil?
19
+
20
+ self.datacenter_id = self.resolve_datacenter_id(options.id)
21
+ instance_id = options.id
22
+ instance_data = instance_info(instance_id)
23
+ if instance_data
24
+ result = client.get("/services/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
25
+ puts "Id: #{result['id']}"
26
+ puts "Name: #{result['name']}"
27
+ puts "Type: #{result['image']['name']}"
28
+ puts "Size: #{result['size'].to_i * 256}MB"
29
+ puts "State: #{result['state']}"
30
+ puts "Ip address: #{result['ip_address']}"
31
+ puts "Port: #{result['port']}"
32
+ if result['username']
33
+ puts "Username: #{result['username']}"
34
+ end
35
+ if result['password']
36
+ puts "Password: #{result['password']}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def create(name, options)
42
+ sizes = {'256m' => 1, '512m' => 2, '768m' => 3, '1024m' => 4}
43
+ size = sizes[options.size.to_s.to_sym] || 1
44
+ data = {
45
+ name: name,
46
+ serviceProviderId: 'mdb',
47
+ config: {
48
+ runtimeSize: size,
49
+ serviceImage: "qtcs/#{options.type}"
50
+ }
51
+ }
52
+ response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
53
+ puts response['id']
54
+ end
55
+
56
+ def logs(options)
57
+ raise ArgumentError.new('--id is required') if options.id.nil?
58
+
59
+ self.datacenter_id = self.resolve_datacenter_id(options.id)
60
+ offset = options.offset || 0
61
+ limit = options.limit || 100
62
+ stream = options.stream || nil
63
+
64
+ instance_id = options.id
65
+ instance_data = instance_info(instance_id)
66
+ if instance_data
67
+ result = client.get("/services/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
68
+ result['results'].each do |r|
69
+ line = ''
70
+ line << "[#{r['time']}] " if options.timestamp == true
71
+ line << r['log']
72
+ puts line
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+ end