kontena-cli 1.4.2 → 1.4.3.rc1

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
  SHA256:
3
- metadata.gz: 76466bba61423d4a43ef601327a87c9cb75b41e6c5b50f7aee2082d1963e7b97
4
- data.tar.gz: f0e3ac1f4834dc8e34b506353b73bb259de4c971459b700fb6a9d631f97e9de7
3
+ metadata.gz: 2c89aaf80a9dadce77e13ea22f0625d29a9a3aab7d32c4509b810fbe9249922f
4
+ data.tar.gz: 0321b6425831606908933ed2385e38a4982430ad7f6b6e14438b41a2b85aa1d7
5
5
  SHA512:
6
- metadata.gz: 6f439ebc6e887a909d231125e91e04118b354c2836821445e8a121af79f84a169a20f05af23338a36d6abdf246af00fe3605b572aedad7124a88cbb42896cfad
7
- data.tar.gz: 96155c93f018bc53c498b9d04c943ebe238817f012cbd62f4fd594b5dab6e7c1557bf4ab9c4421985768534399aec40286583442c00a735d4885b3878ce0cb41
6
+ metadata.gz: 0f4d405d097a668e02dcf85edee1d8da793e4ceffb988f188b9b3069ab762cb645ec95be3c6abe8633d54571dec44087684e04c1d4e25c178d83cabe7ada00cb
7
+ data.tar.gz: 5ff4310c6e174dd1723c0a5ab6df3525f73e8f49e8b07b09e5198e1ecb4ef3430450f5d2265560f67186c30e807cab5f44c11b38f325a42f3d46e6b9621ac38a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.2
1
+ 1.4.3.rc1
@@ -4,7 +4,7 @@ module Kontena::Cli::Certificate
4
4
  include Kontena::Cli::Common
5
5
  include Kontena::Cli::GridOptions
6
6
 
7
- BANNER = "This command is now deprecated in favor of 'kontena certificate request' command".colorize(:red)
7
+ BANNER = Kontena.pastel.yellow("[DEPRECATED] This command is now deprecated in favor of 'kontena certificate request' command")
8
8
 
9
9
  banner BANNER
10
10
 
@@ -14,7 +14,7 @@ module Kontena::Cli::Certificate
14
14
 
15
15
 
16
16
  def execute
17
- puts BANNER
17
+ warn BANNER
18
18
 
19
19
  require_api_url
20
20
  token = require_token
@@ -7,7 +7,7 @@ class Kontena::Cli::CertificateCommand < Kontena::Command
7
7
  subcommand "register", "Register to LetsEncrypt", load_subcommand('certificate/register_command')
8
8
  subcommand "authorize", "Create DNS authorization for domain", load_subcommand('certificate/authorize_command')
9
9
  subcommand "request", "Request certificate for domain", load_subcommand('certificate/request_command')
10
- subcommand "get", "Get certificate for domain", load_subcommand('certificate/get_command')
10
+ subcommand "get", "Get certificate for domain [DEPRECATED]", load_subcommand('certificate/get_command')
11
11
  subcommand "import", "Import certificate from file", load_subcommand('certificate/import_command')
12
12
  subcommand ["remove", "rm"], "Remove certificate for domain", load_subcommand('certificate/remove_command')
13
13
 
@@ -1,9 +1,13 @@
1
1
 
2
2
  class Kontena::Cli::CloudCommand < Kontena::Command
3
+ include Kontena::Cli::Common
4
+
3
5
  subcommand "login", "Authenticate to Kontena Cloud", load_subcommand('cloud/login_command')
4
6
  subcommand "logout", "Logout from Kontena Cloud", load_subcommand('cloud/logout_command')
5
7
  subcommand "master", "Master specific commands", load_subcommand('cloud/master_command')
6
8
 
7
- def execute
9
+ def subcommand_missing(name)
10
+ return super(name) unless %w(platform node org organization image-repository ir region token).include?(name)
11
+ exit_with_error "The #{pastel.cyan('cloud')} plugin has not been installed. Use: #{pastel.cyan('kontena plugin install cloud')}"
8
12
  end
9
- end
13
+ end
@@ -1,4 +1,4 @@
1
- require 'io/console'
1
+ require 'tty-screen'
2
2
  require 'kontena-websocket-client'
3
3
 
4
4
  module Kontena::Cli::Helpers
@@ -107,7 +107,7 @@ module Kontena::Cli::Helpers
107
107
  Thread.new do
108
108
  begin
109
109
  if tty
110
- console_height, console_width = IO.console.winsize
110
+ console_height, console_width = TTY::Screen.size
111
111
  websocket_exec_write(ws, 'tty_size' => {
112
112
  width: console_width, height: console_height
113
113
  })
@@ -28,7 +28,7 @@ module Kontena::Cli::Master::Token
28
28
 
29
29
  if self.expires_in?
30
30
  if current_master.token.expires_at.to_i > 0
31
- puts Time.now.utc.to_i - current_master.token.expires_at
31
+ puts current_master.token.expires_at - Time.now.utc.to_i
32
32
  end
33
33
  exit 0
34
34
  end
@@ -24,10 +24,10 @@ module Kontena::Cli::Stacks
24
24
  requires_current_master_token
25
25
 
26
26
  def execute
27
- set_env_variables(stack_name, current_grid)
28
-
29
27
  install_dependencies unless skip_dependencies?
30
28
 
29
+ set_env_variables(stack_name, current_grid)
30
+
31
31
  stack # runs validations
32
32
 
33
33
  hint_on_validation_notifications(reader.notifications)
@@ -42,6 +42,7 @@ module Kontena::Cli::Stacks
42
42
  def install_dependencies
43
43
  dependencies = loader.dependencies
44
44
  return if dependencies.nil?
45
+
45
46
  dependencies.each do |dependency|
46
47
  target_name = "#{stack_name}-#{dependency['name']}"
47
48
  caret "Installing dependency #{pastel.cyan(dependency['stack'])} as #{pastel.cyan(target_name)}"
@@ -56,6 +57,7 @@ module Kontena::Cli::Stacks
56
57
  cmd << dependency['stack']
57
58
  Kontena.run!(cmd)
58
59
  end
60
+
59
61
  end
60
62
 
61
63
  def create_stack
@@ -7,8 +7,7 @@ module Kontena::Cli::Stacks::Registry
7
7
 
8
8
  banner "Pushes (uploads) a stack to the stack registry"
9
9
 
10
- include Kontena::Cli::Stacks::Common::StackFileOrNameParam
11
- include Kontena::Cli::Stacks::Common::StackValuesFromOption
10
+ parameter "[FILE]", "Kontena stack file path", default: "kontena.yml", attribute_name: :source
12
11
 
13
12
  requires_current_account_token
14
13
 
@@ -20,17 +19,22 @@ module Kontena::Cli::Stacks::Registry
20
19
  end
21
20
 
22
21
  def includes_local_extends?
23
- stack.fetch(:services) { {} }.any? { |svc| svc['extends'] && svc[:extends]['file'] }
22
+ loader.yaml.fetch('services', {}).any? { |_, svc| svc.key?('extends') && svc['extends'].key?('file') }
24
23
  end
25
24
 
26
25
  def execute
27
- set_env_variables(stack_name, 'validate', 'validate-platform')
28
-
26
+ exit_with_error "Can only perform push from local files" unless loader.origin == "file"
29
27
  exit_with_error "Stack file contains dependencies to local files" if includes_local_dependencies?
30
28
  exit_with_error "Stack file has services that extend from local files" if includes_local_extends?
31
29
 
32
- spinner("Pushing #{pastel.cyan(source)} to stacks registry as #{loader.stack_name}") do
33
- stacks_client.push(stack_name, loader.stack_name.version, loader.content) unless dry_run?
30
+ spinner("Pushing #{pastel.cyan(source)} to stack registry as #{loader.stack_name}") do
31
+ unless dry_run?
32
+ stacks_client.push(
33
+ loader.stack_name.stack_name,
34
+ loader.stack_name.version,
35
+ loader.content
36
+ )
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -29,8 +29,6 @@ module Kontena::Cli::Stacks
29
29
 
30
30
  # @return [Kontena::Cli::Stacks::ChangeResolver]
31
31
  def execute
32
- set_env_variables(stack_name, current_grid)
33
-
34
32
  old_data = spinner "Reading stack #{pastel.cyan(stack_name)} from master" do
35
33
  gather_master_data(stack_name)
36
34
  end
@@ -39,13 +39,6 @@ module Kontena::Cli::Stacks
39
39
  end
40
40
 
41
41
  def execute
42
- if online?
43
- set_env_variables(stack_name, require_current_grid)
44
- else
45
- config.current_master = nil
46
- set_env_variables(stack_name, 'validate', 'validate-platform')
47
- end
48
-
49
42
  if dependency_tree?
50
43
  puts ::YAML.dump('name' => stack_name, 'stack' => source, 'depends' => stack['dependencies'])
51
44
  exit 0
@@ -53,6 +46,13 @@ module Kontena::Cli::Stacks
53
46
 
54
47
  validate_dependencies if dependencies?
55
48
 
49
+ if online?
50
+ set_env_variables(stack_name, require_current_grid)
51
+ else
52
+ config.current_master = nil
53
+ set_env_variables(stack_name, 'validate', 'validate-platform')
54
+ end
55
+
56
56
  stack # runs validations
57
57
 
58
58
  hint_on_validation_notifications(reader.notifications, dependencies? ? loader.source : nil)
@@ -6,8 +6,7 @@ module Kontena::Cli::Stacks
6
6
  def resolve
7
7
  return nil unless current_master && current_grid
8
8
  require 'kontena/cli/stacks/show_command'
9
- read_command = Kontena::Cli::Stacks::ShowCommand.new([self.stack])
10
- stack = read_command.fetch_stack(self.stack)
9
+ stack = client.get("stacks/#{current_grid}/#{self.stack}")
11
10
  service = stack['services'].find { |s| s['name'] == hint }
12
11
  if service
13
12
  service['instances']
@@ -63,7 +63,7 @@ module Kontena::Cli::Stacks
63
63
  # Values that are set always when parsing stacks
64
64
  # @return [Hash] a hash of key value pairs
65
65
  def default_envs
66
- @default_envs ||= {
66
+ {
67
67
  'GRID' => env['GRID'],
68
68
  'STACK' => env['STACK'],
69
69
  'PLATFORM' => env['PLATFORM'] || env['GRID']
@@ -40,7 +40,7 @@ module Kontena
40
40
  require(path)
41
41
  Kontena.logger.debug { "Loaded plugin #{spec.name}" } if plugin_debug?
42
42
 
43
- report_tracking
43
+ report_tracking(spec)
44
44
  true
45
45
  rescue ScriptError, LoadError, StandardError => ex
46
46
  warn " [#{Kontena.pastel.red('error')}] Failed to load plugin: #{spec.name} from #{spec.gem_dir}\n\tRerun the command with environment DEBUG=true set to get the full exception."
@@ -79,7 +79,7 @@ module Kontena
79
79
  @load_path_before = $LOAD_PATH.dup
80
80
  end
81
81
 
82
- def report_tracking
82
+ def report_tracking(spec)
83
83
  return unless plugin_debug?
84
84
  added_features = ($LOADED_FEATURES - @loaded_features_before).map {|feat| "- #{feat}"}
85
85
  added_paths = ($LOAD_PATH - @load_path_before).map {|feat| "- #{feat}"}
@@ -0,0 +1,17 @@
1
+ require 'kontena/cli/cloud_command'
2
+
3
+ describe Kontena::Cli::CloudCommand do
4
+ let(:subject) { described_class.new('kontena') }
5
+
6
+
7
+ describe '#subcommand_missing' do
8
+ it 'suggests plugin install for known cloud plugin commands' do
9
+ expect{subject.run(['platform', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
10
+ expect{subject.run(['organization', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
11
+ expect{subject.run(['ir', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
12
+ expect{subject.run(['region', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
13
+ expect{subject.run(['node', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
14
+ expect{subject.run(['token', 'xyz'])}.to exit_with_error.and output(/has not been installed/).to_stderr
15
+ end
16
+ end
17
+ end
@@ -273,7 +273,7 @@ describe Kontena::Cli::Helpers::ExecHelper do
273
273
 
274
274
  it 'connects and sends messages from stdin' do
275
275
  stdin_eol = false
276
- allow(IO.console).to receive(:winsize).and_return([100, 100])
276
+ allow(TTY::Screen).to receive(:size).and_return([100, 100])
277
277
  expect(websocket_client).to receive(:send).once.with('{"tty_size":{"width":100,"height":100}}')
278
278
  expect(websocket_client).to receive(:send).once.with('{"cmd":["test-tty"]}')
279
279
 
@@ -0,0 +1,40 @@
1
+ require 'kontena/cli/master/token_command'
2
+ require 'kontena/cli/master/token/current_command'
3
+
4
+ describe Kontena::Cli::Master::Token::CurrentCommand do
5
+
6
+ include ClientHelpers
7
+ include RequirementsHelper
8
+
9
+ expect_to_require_current_master
10
+ expect_to_require_current_master_token
11
+
12
+ let(:master) { double(token: double(access_token: 'foo', refresh_token: 'bar', expires_at: Time.now.utc.to_i + 999)) }
13
+
14
+ before do
15
+ allow(subject).to receive(:current_master).and_return(master)
16
+ end
17
+
18
+ it 'runs master token show with the current token' do
19
+ expect(Kontena).to receive(:run!).with(['master', 'token', 'show', 'foo'])
20
+ subject.execute
21
+ end
22
+
23
+ describe '--token' do
24
+ it 'outputs the current access token' do
25
+ expect{subject.run(['--token'])}.to output(/\Afoo\Z/).to_stdout
26
+ end
27
+ end
28
+
29
+ describe '--refresh-token' do
30
+ it 'outputs the current refresh token' do
31
+ expect{subject.run(['--refresh-token'])}.to output(/\Abar\Z/).to_stdout
32
+ end
33
+ end
34
+
35
+ describe 'expires-in' do
36
+ it 'reports time until token expiration' do
37
+ expect{subject.run(['--expires-in'])}.to output(/\A[0-9]{3}\Z/).to_stdout
38
+ end
39
+ end
40
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,7 @@ require 'clamp'
16
16
  require 'ruby_dig'
17
17
  require 'kontena_cli'
18
18
  require 'webmock/rspec'
19
+ require 'tmpdir'
19
20
 
20
21
  RSpec.configure do |config|
21
22
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3.rc1
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-12-08 00:00:00.000000000 Z
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -570,6 +570,7 @@ files:
570
570
  - spec/kontena/cli/cloud/login_command_spec.rb
571
571
  - spec/kontena/cli/cloud/logout_command_spec.rb
572
572
  - spec/kontena/cli/cloud/master/add_command_spec.rb
573
+ - spec/kontena/cli/cloud_command_spec.rb
573
574
  - spec/kontena/cli/common_spec.rb
574
575
  - spec/kontena/cli/containers/exec_command_spec.rb
575
576
  - spec/kontena/cli/containers/list_command_spec.rb
@@ -589,6 +590,7 @@ files:
589
590
  - spec/kontena/cli/master/join_command_spec.rb
590
591
  - spec/kontena/cli/master/login_command_spec.rb
591
592
  - spec/kontena/cli/master/logout_command_spec.rb
593
+ - spec/kontena/cli/master/token/current_spec.rb
592
594
  - spec/kontena/cli/master/use_command_spec.rb
593
595
  - spec/kontena/cli/master/user/invite_command_spec.rb
594
596
  - spec/kontena/cli/master/user/remove_command_spec.rb
@@ -692,9 +694,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
692
694
  version: 2.1.0
693
695
  required_rubygems_version: !ruby/object:Gem::Requirement
694
696
  requirements:
695
- - - ">="
697
+ - - ">"
696
698
  - !ruby/object:Gem::Version
697
- version: '0'
699
+ version: 1.3.1
698
700
  requirements: []
699
701
  rubyforge_project:
700
702
  rubygems_version: 2.7.3
@@ -744,6 +746,7 @@ test_files:
744
746
  - spec/kontena/cli/cloud/login_command_spec.rb
745
747
  - spec/kontena/cli/cloud/logout_command_spec.rb
746
748
  - spec/kontena/cli/cloud/master/add_command_spec.rb
749
+ - spec/kontena/cli/cloud_command_spec.rb
747
750
  - spec/kontena/cli/common_spec.rb
748
751
  - spec/kontena/cli/containers/exec_command_spec.rb
749
752
  - spec/kontena/cli/containers/list_command_spec.rb
@@ -763,6 +766,7 @@ test_files:
763
766
  - spec/kontena/cli/master/join_command_spec.rb
764
767
  - spec/kontena/cli/master/login_command_spec.rb
765
768
  - spec/kontena/cli/master/logout_command_spec.rb
769
+ - spec/kontena/cli/master/token/current_spec.rb
766
770
  - spec/kontena/cli/master/use_command_spec.rb
767
771
  - spec/kontena/cli/master/user/invite_command_spec.rb
768
772
  - spec/kontena/cli/master/user/remove_command_spec.rb