kontena-plugin-cloud 1.1.0.pre1 → 1.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf7c44e18f0d2ff2e277810974bf39f749257e3c
4
- data.tar.gz: 2e2f5ba2d90c7a520af0841a5cafe24f64ac149e
3
+ metadata.gz: af9decdc6b9827d74da53fb8039b726ba270138f
4
+ data.tar.gz: b3353bfcb5b6d8100afbcd0b9bb39635110a468b
5
5
  SHA512:
6
- metadata.gz: 95f186f517ada7984687d566dca28a211e3afdb834485c774ea9bc801ea06896a86abb1893e5c384360a8b85dedf81631baabc7d40d5e560b4d3caa3131ee344
7
- data.tar.gz: 1fad2520e64dd6082a03357012fad9696b9b95e8aefe4630e8389903fd5454fb887c787879aad0b0e1eb32549fa252ee48b18b7b24a839f41fe83ce980f7315c
6
+ metadata.gz: d424c65f38efea82051a7a2fb19b600d14ac80db0fb688aa052a9d37b70140840ac78348483804597ed7da4af9708b67e014337b3d356051e190e23e339c31ff
7
+ data.tar.gz: 4a8ec649931f6bc6ed58fee238832f1947d0991a26b9bad4a26ec49c3701d959da815ceb5c67db28903adb4dc073210391a8ef18a2a57789049edb01ffb45aad
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.10
4
+ - 2.2.6
5
+ - 2.3.3
6
+ - 2.4.1
7
+ env:
8
+ - secure: "lGCbWI8Tmi8rjXkMe4ogIBKvRt4IQ/aNGclP/X7ZzCHwlIobSZTqYw5m3SUSsthPUIhApfmQRxET/3/w4QrGO5GXbNr31G8anT7tMh/+ZLNjZ8R22ZN/JGyT4iR8B0wyyBMsw7VXVmkyRO6uMODDqF2ctAlwppWksMfAy4Fhi7zECwRtyhEwK4il7vx+A+Sk3bG520xNoTHYmPhteTjP7ANKy7SpvNvlXIMIqAOUEyLbGCZzMWsUsPEwVZLI1qjrPCDFAI5ez1yzDJ9023PYgfSJ2jiOUQE1X9uDuhFEswumYWjDEOfpVQ8a6eqNzha6NK6VpG1n0WxHzEnDW2Ea7M9ZrwXqgBNhc/vuM9SOjot3EmrK2lwYaTKyXQVIIJGFkU9/PLLDXqfoHHz0sXyIYsCNORFLclbKZmznx0dVrAlR4LtGP64OoFwE5b8yJCSlcwl7Cd0qqdccuJyTeccwo3+P73jwxvvg9DsN2xgbZFMzdidLSXWYOkf+Vib4okWGiEEsmG1gNtRQzwvNaoWqQ3Svqr90OEtY7jrdm8kMcqq+SmjBJn5ZNP8xUGOh187tx/FHff/YufrlbgNFASffbOOWCNmnYC1isWp95rBOfjS3PZLAFhgvdQVyl3CqSV0UKpZV7y6Ujq8JcnZh2VO0f1FZfIcRWRG94StFN+XJ4lE="
9
+ cache: bundler
10
+ script: bundle install && bundle exec rspec spec/
11
+ deploy:
12
+ provider: rubygems
13
+ api_key: $GEM_TOKEN
14
+ gem: kontena-plugin-cloud
15
+ on:
16
+ tags: true
17
+ rvm: 2.4.1
@@ -64,9 +64,8 @@ class Kontena::Cli::MasterCodeExchanger
64
64
  response = @api_client.request(method: method, body: body, path: path, headers: headers)
65
65
  content_type = response.headers.dig('Content-Type') || ''
66
66
  content_length = response.headers.dig('Content-Length').to_i
67
-
68
67
  body = if content_type.include?('json') && content_length > 0
69
- JSON.parse(response.body)
68
+ JSON.parse(response.body) rescue response.body
70
69
  else
71
70
  response.body
72
71
  end
@@ -0,0 +1,8 @@
1
+ require_relative 'cloud_api_model'
2
+
3
+ module Kontena::Cli::Models
4
+ class Organization
5
+ include CloudApiModel
6
+
7
+ end
8
+ end
@@ -9,11 +9,15 @@ module Kontena::Cli::Models
9
9
  end
10
10
 
11
11
  def online?
12
- state.to_s == 'online'.freeze
12
+ state.to_s == 'running'.freeze
13
13
  end
14
14
 
15
15
  def organization
16
16
  @api_data.dig('relationships', 'organization', 'data', 'id')
17
17
  end
18
+
19
+ def to_path
20
+ "#{self.organization}/#{self.name}"
21
+ end
18
22
  end
19
23
  end
@@ -0,0 +1,21 @@
1
+ require_relative '../../../cli/models/organization'
2
+
3
+ module Kontena::Plugin::Cloud::Organization::Common
4
+
5
+ def fetch_organizations
6
+ organizations = cloud_client.get("/organizations/")['data']
7
+ organizations.map do |o|
8
+ Kontena::Cli::Models::Organization.new(o)
9
+ end
10
+ end
11
+
12
+ def prompt_organization
13
+ organizations = fetch_organizations
14
+ prompt.select("Choose organization") do |menu|
15
+ organizations.each do |o|
16
+ menu.choice o.name, o.name
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -1,12 +1,14 @@
1
+ require_relative 'common'
1
2
  class Kontena::Plugin::Cloud::Organization::ListCommand < Kontena::Command
2
3
  include Kontena::Cli::Common
4
+ include Kontena::Plugin::Cloud::Organization::Common
3
5
  include Kontena::Cli::TableGenerator::Helper
4
6
 
5
7
  requires_current_account_token
6
8
 
7
9
  def execute
8
- organizations = cloud_client.get('/organizations')['data']
9
- print_table(organizations) do |row|
10
+ organizations = fetch_organizations
11
+ print_table(organizations.map{|o| o.api_data}) do |row|
10
12
  row.merge!(row['attributes'])
11
13
  row['name'] = row['name']
12
14
  row['account-status'] = row['account-status'] == 'active' ? pastel.green(row['account-status']) : row['account-status']
@@ -3,6 +3,10 @@ require_relative '../../../cli/models/platform'
3
3
 
4
4
  module Kontena::Plugin::Cloud::Platform::Common
5
5
 
6
+ def cached_platforms
7
+ @cached_platforms ||= []
8
+ end
9
+
6
10
  def fetch_platforms
7
11
  all = []
8
12
  organizations = cloud_client.get('/organizations')['data']
@@ -17,13 +21,24 @@ module Kontena::Plugin::Cloud::Platform::Common
17
21
  def fetch_platforms_for_org(org_id)
18
22
  platforms = cloud_client.get("/organizations/#{org_id}/platforms")['data']
19
23
  platforms.map do |p|
20
- Kontena::Cli::Models::Platform.new(p)
24
+ platform = Kontena::Cli::Models::Platform.new(p)
25
+ cached_platforms << platform if cached_platforms.none?{|cached| platform.id == cached.id }
26
+ platform
27
+ end
28
+ end
29
+
30
+ def prompt_platform
31
+ platforms = fetch_platforms_for_org(current_organization)
32
+ prompt.select("Choose platform") do |menu|
33
+ platforms.each do |p|
34
+ menu.choice p.name, p
35
+ end
21
36
  end
22
37
  end
23
38
 
24
39
  # @return [String, NilClass]
25
40
  def current_organization
26
- @current_organization || ENV['KONTENA_ORGANIZATION'] || (current_account && current_account.username)
41
+ @current_organization || ENV['KONTENA_ORGANIZATION']
27
42
  end
28
43
 
29
44
  def current_platform
@@ -33,17 +48,17 @@ module Kontena::Plugin::Cloud::Platform::Common
33
48
  # @param [String] name
34
49
  def require_platform(name)
35
50
  org, platform = parse_platform_name(name)
36
-
37
51
  @current_organization = org
38
-
39
- unless platform_config_exists?(name)
40
- p = find_platform_by_name(platform, org)
41
- exit_with_error("Platform not found") unless p
42
-
43
- login_to_platform(name, p.url)
52
+ p = find_platform_by_name(platform, org)
53
+ exit_with_error("Platform not found") unless p
54
+ unless platform_config_exists?(p.to_path)
55
+ spinner "Generating platform token" do
56
+ login_to_platform("#{current_organization}/#{platform}", p.url)
57
+ end
44
58
  end
45
- self.current_master = name
46
- self.current_grid = platform
59
+ self.current_master = "#{current_organization}/#{platform}"
60
+ self.current_grid = p.grid_id
61
+ p
47
62
  end
48
63
 
49
64
  # @param [String] name
@@ -64,22 +79,30 @@ module Kontena::Plugin::Cloud::Platform::Common
64
79
  end
65
80
 
66
81
  def find_platform_by_name(name, org)
67
- data = cloud_client.get("/organizations/#{org}/platforms/#{name}")['data']
68
- if data
69
- Kontena::Cli::Models::Platform.new(data)
82
+ if platform = cached_platforms.find{|p| p.name == name && p.organization == org }
83
+ platform
84
+ else
85
+ data = cloud_client.get("/organizations/#{org}/platforms/#{name}")['data']
86
+ if data
87
+ platform = Kontena::Cli::Models::Platform.new(data)
88
+ cached_platforms << platform
89
+ platform
90
+ end
70
91
  end
71
92
  end
72
93
 
73
94
  def login_to_platform(name, url)
74
95
  organization, platform = name.split('/')
75
- platform = cloud_client.get("/organizations/#{organization}/platforms/#{platform}")['data']
76
- authorization = cloud_client.post("/organizations/#{organization}/masters/#{platform.dig('attributes', 'master-id')}/authorize", {})
77
- exchanger = Kontena::Cli::MasterCodeExchanger.new(platform.dig('attributes', 'url'))
96
+ platform = find_platform_by_name(platform, organization)
97
+ authorization = cloud_client.post("/organizations/#{organization}/masters/#{platform.master_id}/authorize", {})
98
+ exchanger = Kontena::Cli::MasterCodeExchanger.new(platform.url)
78
99
  code = exchanger.exchange_code(authorization['code'])
79
100
  cmd = [
80
101
  'master', 'login', '--silent', '--no-login-info', '--skip-grid-auto-select',
81
102
  '--name', name, '--code', code, url
82
103
  ]
83
104
  Kontena.run!(cmd)
105
+ rescue => e
106
+ error e.message
84
107
  end
85
108
  end
@@ -47,7 +47,6 @@ class Kontena::Plugin::Cloud::Platform::CreateCommand < Kontena::Command
47
47
  def prompt_organization
48
48
  organizations = cloud_client.get('/organizations')['data']
49
49
  prompt.select("Choose organization:") do |menu|
50
- menu.choice "#{config.current_account.username} (you)", config.current_account.username
51
50
  organizations.each do |o|
52
51
  menu.choice o.dig('attributes', 'name')
53
52
  end
@@ -0,0 +1,9 @@
1
+ require_relative 'common'
2
+
3
+ class Kontena::Plugin::Cloud::Platform::EnvCommand < Kontena::Command
4
+ include Kontena::Cli::Common
5
+
6
+ def execute
7
+ Kontena.run!(['grid','env'])
8
+ end
9
+ end
@@ -1,9 +1,11 @@
1
1
  require_relative 'common'
2
+ require_relative '../organization/common'
2
3
 
3
4
  class Kontena::Plugin::Cloud::Platform::ListCommand < Kontena::Command
4
5
  include Kontena::Cli::Common
5
6
  include Kontena::Cli::TableGenerator::Helper
6
7
  include Kontena::Plugin::Cloud::Platform::Common
8
+ include Kontena::Plugin::Cloud::Organization::Common
7
9
 
8
10
  requires_current_account_token
9
11
 
@@ -22,13 +24,12 @@ class Kontena::Plugin::Cloud::Platform::ListCommand < Kontena::Command
22
24
  end
23
25
 
24
26
  def default_organization
25
- current_account.username
27
+ prompt_organization
26
28
  end
27
29
 
28
30
  def fields
29
31
  {
30
32
  name: 'name',
31
- organization: 'organization',
32
33
  region: 'region'
33
34
  }
34
35
  end
@@ -37,7 +38,7 @@ class Kontena::Plugin::Cloud::Platform::ListCommand < Kontena::Command
37
38
  case health
38
39
  when nil
39
40
  " ".freeze
40
- when 'online'.freeze
41
+ when 'running'.freeze
41
42
  pastel.green('⊛'.freeze)
42
43
  else
43
44
  pastel.dark('⊝'.freeze)
@@ -20,6 +20,7 @@ class Kontena::Plugin::Cloud::Platform::ShowCommand < Kontena::Command
20
20
  puts " organization: #{current_organization}"
21
21
  puts " version: #{platform.version}"
22
22
  puts " state: #{platform.state}"
23
+ puts " online: #{platform.online}"
23
24
  puts " region: #{platform.region || '-'}"
24
25
  puts " initial_size: #{platform.initial_size}"
25
26
  puts " master: #{platform.url}"
@@ -1,41 +1,28 @@
1
1
  require_relative 'common'
2
+ require_relative '../organization/common'
2
3
 
3
4
  class Kontena::Plugin::Cloud::Platform::UseCommand < Kontena::Command
4
5
  include Kontena::Cli::Common
5
6
  include Kontena::Plugin::Cloud::Platform::Common
7
+ include Kontena::Plugin::Cloud::Organization::Common
6
8
 
7
9
  requires_current_account_token
8
10
 
9
11
  parameter "[NAME]", "Platform name"
10
12
 
11
13
  def execute
12
- if name
13
- require_platform(name)
14
- platform = find_platform_by_name(current_grid, current_organization)
14
+ if name && name.include?('/')
15
+ platform = require_platform(name)
15
16
  else
17
+ @current_organization = prompt_organization
16
18
  platform = prompt_platform
19
+ require_platform(platform.to_path)
17
20
  end
18
21
 
19
- platform_name = "#{current_organization}/#{platform.name}"
20
- unless platform_config_exists?(platform_name)
21
- spinner "Generating platform token" do
22
- login_to_platform(platform_name, platform.url)
23
- end
24
- else
25
- config.current_master = platform_name
26
- config.current_master.grid = platform.grid_id
27
- config.write
28
- end
29
-
30
- puts "Using platform: #{pastel.cyan(platform_name)}"
22
+ config.current_master = platform.to_path
23
+ config.current_master.grid = platform.grid_id
24
+ config.write
25
+ puts "Using platform: #{pastel.cyan(platform.to_path)}"
31
26
  end
32
27
 
33
- def prompt_platform
34
- platforms = fetch_platforms_for_org(current_organization)
35
- prompt.select("Choose platform") do |menu|
36
- platforms.each do |p|
37
- menu.choice p.name, p
38
- end
39
- end
40
- end
41
28
  end
@@ -7,6 +7,7 @@ class Kontena::Plugin::Cloud::PlatformCommand < Kontena::Command
7
7
  subcommand ['join', 'byo'], 'Join grid as Kontena Platform', load_subcommand('kontena/plugin/cloud/platform/import_grid_command')
8
8
  subcommand 'user', 'User management commands', load_subcommand('kontena/plugin/cloud/platform/user_command')
9
9
  subcommand 'upgrade', 'Upgrade platform version', load_subcommand('kontena/plugin/cloud/platform/upgrade_command')
10
+ subcommand 'env', 'Show the current grid environment details', load_subcommand('kontena/plugin/cloud/platform/env_command')
10
11
 
11
12
  def execute
12
13
  end
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Cloud
4
- VERSION = "1.1.0.pre1"
4
+ VERSION = "1.1.0.pre2"
5
5
 
6
6
  module Organization
7
7
  module User; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.pre1
4
+ version: 1.1.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2017-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".travis.yml"
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -70,8 +71,10 @@ files:
70
71
  - lib/kontena/cli/models/cloud_api_model.rb
71
72
  - lib/kontena/cli/models/grid.rb
72
73
  - lib/kontena/cli/models/master_api_model.rb
74
+ - lib/kontena/cli/models/organization.rb
73
75
  - lib/kontena/cli/models/platform.rb
74
76
  - lib/kontena/plugin/cloud.rb
77
+ - lib/kontena/plugin/cloud/organization/common.rb
75
78
  - lib/kontena/plugin/cloud/organization/list_command.rb
76
79
  - lib/kontena/plugin/cloud/organization/remove_command.rb
77
80
  - lib/kontena/plugin/cloud/organization/show_command.rb
@@ -82,6 +85,7 @@ files:
82
85
  - lib/kontena/plugin/cloud/organization_command.rb
83
86
  - lib/kontena/plugin/cloud/platform/common.rb
84
87
  - lib/kontena/plugin/cloud/platform/create_command.rb
88
+ - lib/kontena/plugin/cloud/platform/env_command.rb
85
89
  - lib/kontena/plugin/cloud/platform/import_grid_command.rb
86
90
  - lib/kontena/plugin/cloud/platform/list_command.rb
87
91
  - lib/kontena/plugin/cloud/platform/remove_command.rb
@@ -117,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  version: 1.3.1
118
122
  requirements: []
119
123
  rubyforge_project:
120
- rubygems_version: 2.6.11
124
+ rubygems_version: 2.6.14
121
125
  signing_key:
122
126
  specification_version: 4
123
127
  summary: Kontena Cloud management for Kontena CLI