qtc-sdk 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/Changelog.md +18 -14
  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 +221 -221
  18. data/lib/qtc/cli/mar/debug.rb +88 -87
  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/ssl_certificates.rb +40 -40
  23. data/lib/qtc/cli/mar/stack.rb +29 -29
  24. data/lib/qtc/cli/mdb/base.rb +47 -47
  25. data/lib/qtc/cli/mdb/commands.rb +43 -43
  26. data/lib/qtc/cli/mdb/instances.rb +79 -79
  27. data/lib/qtc/cli/platform/clouds.rb +33 -33
  28. data/lib/qtc/cli/platform/commands.rb +132 -132
  29. data/lib/qtc/cli/platform/datacenters.rb +23 -23
  30. data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
  31. data/lib/qtc/cli/platform/user.rb +25 -25
  32. data/lib/qtc/cli/platform/vpn.rb +93 -93
  33. data/lib/qtc/client.rb +170 -170
  34. data/lib/qtc/eds/client.rb +116 -116
  35. data/lib/qtc/eds/collection.rb +124 -124
  36. data/lib/qtc/eds/user_collection.rb +13 -13
  37. data/lib/qtc/eds/usergroup_collection.rb +41 -41
  38. data/lib/qtc/errors.rb +13 -13
  39. data/lib/qtc/version.rb +3 -3
  40. data/qtc-sdk.gemspec +28 -28
  41. data/spec/unit/qtc/client_spec.rb +147 -147
  42. metadata +18 -18
@@ -1,35 +1,35 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mar::Domains < Mar::Base
6
-
7
- def list(options)
8
- instance_id = resolve_instance_id(options)
9
- instance_data = instance_info(instance_id)
10
- if instance_data
11
- result = client.get("/apps/#{instance_id}/domains", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
12
- result['results'].each do |r|
13
- print color("* #{r['name']}", :bold)
14
- end
15
- end
16
- end
17
-
18
- def create(name, options)
19
- instance_id = resolve_instance_id(options)
20
- instance_data = instance_info(instance_id)
21
- if instance_data
22
- client.post("/apps/#{instance_id}/domains", {name: name}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
- end
24
- end
25
-
26
- def destroy(name, options)
27
- instance_id = resolve_instance_id(options)
28
- instance_data = instance_info(instance_id)
29
- if instance_data
30
- client.delete("/apps/#{instance_id}/domains/#{name}", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
31
- end
32
- end
33
- end
34
- end
35
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mar::Domains < Mar::Base
6
+
7
+ def list(options)
8
+ instance_id = resolve_instance_id(options)
9
+ instance_data = instance_info(instance_id)
10
+ if instance_data
11
+ result = client.get("/apps/#{instance_id}/domains", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
12
+ result['results'].each do |r|
13
+ print color("* #{r['name']}", :bold)
14
+ end
15
+ end
16
+ end
17
+
18
+ def create(name, options)
19
+ instance_id = resolve_instance_id(options)
20
+ instance_data = instance_info(instance_id)
21
+ if instance_data
22
+ client.post("/apps/#{instance_id}/domains", {name: name}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
+ end
24
+ end
25
+
26
+ def destroy(name, options)
27
+ instance_id = resolve_instance_id(options)
28
+ instance_data = instance_info(instance_id)
29
+ if instance_data
30
+ client.delete("/apps/#{instance_id}/domains/#{name}", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,38 +1,38 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mar::Env < Mar::Base
6
-
7
- def set(vars, options)
8
- instance_id = resolve_instance_id(options)
9
- env_vars = {}
10
- vars.each do |type|
11
- arr = type.strip.split('=', 2)
12
- if arr[0]
13
- if arr[1].nil? || arr[1] == ''
14
- env_vars[arr[0]] = nil
15
- else
16
- env_vars[arr[0]] = arr[1]
17
- end
18
- end
19
- end
20
- instance_data = instance_info(instance_id)
21
- if instance_data
22
- client.put("/apps/#{instance_id}/env_vars", env_vars, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
- end
24
- end
25
-
26
- def show(options)
27
- instance_id = resolve_instance_id(options)
28
- instance_data = instance_info(instance_id)
29
- if instance_data
30
- env_vars = client.get("/apps/#{instance_id}/env_vars", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
31
- env_vars.each do |key, value|
32
- puts "#{key}=#{value}"
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mar::Env < Mar::Base
6
+
7
+ def set(vars, options)
8
+ instance_id = resolve_instance_id(options)
9
+ env_vars = {}
10
+ vars.each do |type|
11
+ arr = type.strip.split('=', 2)
12
+ if arr[0]
13
+ if arr[1].nil? || arr[1] == ''
14
+ env_vars[arr[0]] = nil
15
+ else
16
+ env_vars[arr[0]] = arr[1]
17
+ end
18
+ end
19
+ end
20
+ instance_data = instance_info(instance_id)
21
+ if instance_data
22
+ client.put("/apps/#{instance_id}/env_vars", env_vars, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
23
+ end
24
+ end
25
+
26
+ def show(options)
27
+ instance_id = resolve_instance_id(options)
28
+ instance_data = instance_info(instance_id)
29
+ if instance_data
30
+ env_vars = client.get("/apps/#{instance_id}/env_vars", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
31
+ env_vars.each do |key, value|
32
+ puts "#{key}=#{value}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,24 +1,24 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mar::Repository < Mar::Base
6
-
7
- def purge_cache(options)
8
- instance_id = resolve_instance_id(options)
9
- instance_data = instance_info(instance_id)
10
- if instance_data
11
- client.delete("/apps/#{instance_id}/build_cache", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
12
- end
13
- end
14
-
15
- def reset(options)
16
- instance_id = resolve_instance_id(options)
17
- instance_data = instance_info(instance_id)
18
- if instance_data
19
- client.delete("/apps/#{instance_id}/repository", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
20
- end
21
- end
22
- end
23
- end
24
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mar::Repository < Mar::Base
6
+
7
+ def purge_cache(options)
8
+ instance_id = resolve_instance_id(options)
9
+ instance_data = instance_info(instance_id)
10
+ if instance_data
11
+ client.delete("/apps/#{instance_id}/build_cache", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
12
+ end
13
+ end
14
+
15
+ def reset(options)
16
+ instance_id = resolve_instance_id(options)
17
+ instance_data = instance_info(instance_id)
18
+ if instance_data
19
+ client.delete("/apps/#{instance_id}/repository", nil, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -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