kontena-cli 1.2.2 → 1.3.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +1 -1
- data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +1 -1
- data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +7 -2
- data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +2 -3
- data/lib/kontena/callbacks/master/deploy/56_set_server_provider_after_deploy.rb +2 -2
- data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +5 -10
- data/lib/kontena/callbacks/master/deploy/70_invite_self_after_deploy.rb +10 -16
- data/lib/kontena/cli/app_command.rb +2 -0
- data/lib/kontena/cli/cloud/master/add_command.rb +19 -10
- data/lib/kontena/cli/common.rb +2 -32
- data/lib/kontena/cli/grids/trusted_subnets/add_command.rb +6 -6
- data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +3 -4
- data/lib/kontena/cli/grids/trusted_subnets/remove_command.rb +7 -7
- data/lib/kontena/cli/master/create_command.rb +2 -3
- data/lib/kontena/cli/master/init_cloud_command.rb +1 -1
- data/lib/kontena/cli/master/join_command.rb +3 -1
- data/lib/kontena/cli/master/ssh_command.rb +2 -6
- data/lib/kontena/cli/master/token/current_command.rb +1 -1
- data/lib/kontena/cli/master/user/invite_command.rb +2 -2
- data/lib/kontena/cli/master/user_command.rb +0 -2
- data/lib/kontena/cli/nodes/ssh_command.rb +1 -3
- data/lib/kontena/cli/stack_command.rb +2 -0
- data/lib/kontena/cli/stacks/common.rb +1 -1
- data/lib/kontena/cli/stacks/install_command.rb +1 -1
- data/lib/kontena/cli/stacks/restart_command.rb +23 -0
- data/lib/kontena/cli/stacks/stop_command.rb +23 -0
- data/lib/kontena/cli/stacks/upgrade_command.rb +1 -1
- data/lib/kontena/cli/stacks/yaml/validations.rb +1 -1
- data/lib/kontena/cli/vault/export_command.rb +2 -2
- data/lib/kontena/cli/vault/import_command.rb +4 -10
- data/lib/kontena/main_command.rb +1 -1
- data/lib/kontena/plugin_manager.rb +16 -1
- data/lib/kontena_cli.rb +23 -14
- data/spec/kontena/cli/cloud/master/add_command_spec.rb +5 -5
- data/spec/kontena/cli/grids/trusted_subnets/add_command_spec.rb +20 -4
- data/spec/kontena/cli/grids/trusted_subnets/list_command_spec.rb +12 -7
- data/spec/kontena/cli/grids/trusted_subnets/remove_command_spec.rb +20 -4
- data/spec/kontena/cli/master/init_cloud_command_spec.rb +1 -1
- data/spec/kontena/cli/master/user/invite_command_spec.rb +2 -2
- data/spec/kontena/cli/nodes/ssh_command_spec.rb +43 -0
- data/spec/kontena/cli/stacks/restart_command_spec.rb +16 -0
- data/spec/kontena/cli/stacks/stop_command_spec.rb +16 -0
- data/spec/kontena/cli/stacks/upgrade_command_spec.rb +2 -2
- data/spec/kontena/cli/stacks/yaml/validator_v3_spec.rb +22 -2
- data/spec/kontena/cli/vault/export_spec.rb +6 -6
- data/spec/kontena/cli/vault/import_spec.rb +11 -12
- data/spec/kontena/kontena_cli_spec.rb +40 -5
- data/spec/spec_helper.rb +9 -7
- metadata +12 -4
@@ -167,8 +167,23 @@ module Kontena
|
|
167
167
|
if File.exist?(plugin) && !plugins.find{ |p| p.name == spec.name }
|
168
168
|
begin
|
169
169
|
if spec_has_valid_dependency?(spec)
|
170
|
+
loaded_features_before = $LOADED_FEATURES.dup
|
171
|
+
load_path_before = $LOAD_PATH.dup
|
172
|
+
|
173
|
+
ENV["DEBUG"] && $stderr.puts("Activating plugin #{spec.name}")
|
174
|
+
spec.activate
|
175
|
+
spec.activate_dependencies
|
176
|
+
|
170
177
|
ENV["DEBUG"] && $stderr.puts("Loading plugin #{spec.name}")
|
171
|
-
|
178
|
+
require(plugin)
|
179
|
+
|
180
|
+
if ENV['DEBUG'] == 'plugin'
|
181
|
+
added_features = ($LOADED_FEATURES - loaded_features_before).map {|feat| "- #{feat}"}
|
182
|
+
added_paths = ($LOAD_PATH - load_path_before).map {|feat| "- #{feat}"}
|
183
|
+
$stderr.puts "Plugin manager loaded features for #{spec.name}: \n#{added_features.join("\n")}" unless added_features.empty?
|
184
|
+
$stderr.puts "Plugin manager load paths added for #{spec.name}: \n#{added_paths.join("\n")}" unless added_paths.empty?
|
185
|
+
end
|
186
|
+
|
172
187
|
plugins << spec
|
173
188
|
else
|
174
189
|
plugin_name = spec.name.sub('kontena-plugin-', '')
|
data/lib/kontena_cli.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
module Kontena
|
2
|
-
# Run a kontena command like it was launched from the command line.
|
3
|
-
#
|
4
|
-
# @example
|
5
|
-
# Kontena.run("grid list --help")
|
2
|
+
# Run a kontena command like it was launched from the command line. Re-raises any exceptions,
|
3
|
+
# except a SystemExit with status 0, which is considered a success.
|
6
4
|
#
|
7
5
|
# @param [String,Array<String>] command_line
|
8
|
-
# @return
|
9
|
-
def self.run(*cmdline
|
6
|
+
# @return command result or nil
|
7
|
+
def self.run!(*cmdline)
|
10
8
|
if cmdline.first.kind_of?(Array)
|
11
9
|
command = cmdline.first
|
12
10
|
elsif cmdline.size == 1 && cmdline.first.include?(' ')
|
@@ -14,19 +12,30 @@ module Kontena
|
|
14
12
|
else
|
15
13
|
command = cmdline
|
16
14
|
end
|
17
|
-
ENV["DEBUG"] && puts("Running Kontena.run(#{command.inspect}
|
15
|
+
ENV["DEBUG"] && puts("Running Kontena.run(#{command.inspect}")
|
18
16
|
result = Kontena::MainCommand.new(File.basename(__FILE__)).run(command)
|
19
17
|
ENV["DEBUG"] && puts("Command completed, result: #{result.inspect} status: 0")
|
20
|
-
|
21
|
-
return result if returning == :result
|
18
|
+
result
|
22
19
|
rescue SystemExit => ex
|
23
|
-
ENV["DEBUG"] && $stderr.puts("Command
|
24
|
-
|
20
|
+
ENV["DEBUG"] && $stderr.puts("Command caused SystemExit, result: #{result.inspect} status: #{ex.status}")
|
21
|
+
return true if ex.status.zero?
|
22
|
+
raise ex
|
25
23
|
rescue => ex
|
26
|
-
ENV["DEBUG"] && $stderr.puts("Command raised #{ex} with message: #{ex.message}\n#{ex.backtrace.join("\n ")}")
|
27
|
-
|
24
|
+
ENV["DEBUG"] && $stderr.puts("Command raised #{ex.class.name} with message: #{ex.message}\n#{ex.backtrace.join("\n ")}")
|
25
|
+
raise ex
|
28
26
|
end
|
29
27
|
|
28
|
+
# Run a kontena command and return true if the command did not raise or exit with a non-zero exit code. Raises nothing.
|
29
|
+
# @param [String,Array<String>] command_line
|
30
|
+
# @return [TrueClass,FalseClass] success
|
31
|
+
def self.run(*cmdline)
|
32
|
+
result = run!(*cmdline)
|
33
|
+
result.nil? ? true : result
|
34
|
+
rescue SystemExit => ex
|
35
|
+
ex.status.zero?
|
36
|
+
rescue
|
37
|
+
false
|
38
|
+
end
|
30
39
|
|
31
40
|
# @return [String] x.y
|
32
41
|
def self.minor_version
|
@@ -115,4 +124,4 @@ require 'kontena/client'
|
|
115
124
|
require 'kontena/stacks_cache'
|
116
125
|
require 'kontena/plugin_manager'
|
117
126
|
require 'kontena/main_command'
|
118
|
-
require 'kontena/cli/spinner'
|
127
|
+
require 'kontena/cli/spinner'
|
@@ -95,8 +95,8 @@ describe Kontena::Cli::Cloud::Master::AddCommand do
|
|
95
95
|
subject.provider = 'provider'
|
96
96
|
subject.version = '10.10.10'
|
97
97
|
|
98
|
-
expect(Kontena).to receive(:run).with(
|
99
|
-
expect(Kontena).to receive(:run).with(
|
98
|
+
expect(Kontena).to receive(:run!).with(%w(master config import --force --preset kontena_auth_provider))
|
99
|
+
expect(Kontena).to receive(:run!).with(%w(master config set oauth2.client_id=123 oauth2.client_secret=345 server.root_url=foofoofoo server.name=foofoo cloud.provider_is_kontena=true))
|
100
100
|
|
101
101
|
subject.register_current
|
102
102
|
end
|
@@ -108,9 +108,9 @@ describe Kontena::Cli::Cloud::Master::AddCommand do
|
|
108
108
|
subject.version = '10.10.10'
|
109
109
|
subject.cloud_master_id = 'abcd'
|
110
110
|
|
111
|
-
expect(Kontena).to receive(:run).with(
|
112
|
-
expect(Kontena).to receive(:run).with(
|
113
|
-
expect(Kontena).to receive(:run).with(
|
111
|
+
expect(Kontena).to receive(:run!).with(%w(cloud master update --provider provider --version 10.10.10 abcd)).and_return(true)
|
112
|
+
expect(Kontena).to receive(:run!).with(%w(master config import --force --preset kontena_auth_provider)).and_return(true)
|
113
|
+
expect(Kontena).to receive(:run!).with(%w(master config set oauth2.client_id=123 oauth2.client_secret=345 server.root_url=foofoofoo server.name=foofoo cloud.provider_is_kontena=true)).and_return(true)
|
114
114
|
|
115
115
|
subject.register_current
|
116
116
|
end
|
@@ -4,24 +4,40 @@ require "kontena/cli/grids/trusted_subnets/add_command"
|
|
4
4
|
describe Kontena::Cli::Grids::TrustedSubnets::AddCommand do
|
5
5
|
|
6
6
|
include ClientHelpers
|
7
|
+
include RequirementsHelper
|
8
|
+
|
9
|
+
expect_to_require_current_master
|
7
10
|
|
8
11
|
describe '#execute' do
|
9
|
-
it 'requires
|
12
|
+
it 'requires subnet as param' do
|
10
13
|
expect {
|
11
14
|
subject.run([])
|
12
15
|
}.to raise_error(Clamp::UsageError)
|
13
16
|
end
|
14
17
|
|
15
18
|
it 'adds subnet to grid' do
|
16
|
-
allow(client).to receive(:get).with("grids/
|
19
|
+
allow(client).to receive(:get).with("grids/test-grid").and_return(
|
20
|
+
'trusted_subnets' => ['192.168.12.0/24']
|
21
|
+
)
|
22
|
+
expect(client).to receive(:put).with(
|
23
|
+
'grids/test-grid', hash_including({trusted_subnets: [
|
24
|
+
'192.168.12.0/24', '10.12.0.0/19'
|
25
|
+
]})
|
26
|
+
)
|
27
|
+
subject.run(['10.12.0.0/19'])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'supports the --grid option' do
|
31
|
+
allow(subject).to receive(:current_grid).and_call_original
|
32
|
+
allow(client).to receive(:get).with("grids/ingrid").and_return(
|
17
33
|
'trusted_subnets' => ['192.168.12.0/24']
|
18
34
|
)
|
19
35
|
expect(client).to receive(:put).with(
|
20
|
-
'grids/
|
36
|
+
'grids/ingrid', hash_including({trusted_subnets: [
|
21
37
|
'192.168.12.0/24', '10.12.0.0/19'
|
22
38
|
]})
|
23
39
|
)
|
24
|
-
subject.run(['
|
40
|
+
subject.run(['--grid', 'ingrid', '10.12.0.0/19'])
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -4,19 +4,24 @@ require "kontena/cli/grids/trusted_subnets/list_command"
|
|
4
4
|
describe Kontena::Cli::Grids::TrustedSubnets::ListCommand do
|
5
5
|
|
6
6
|
include ClientHelpers
|
7
|
+
include RequirementsHelper
|
7
8
|
|
8
|
-
|
9
|
-
it 'requires grid as param' do
|
10
|
-
expect {
|
11
|
-
subject.run([])
|
12
|
-
}.to raise_error(Clamp::UsageError)
|
13
|
-
end
|
9
|
+
expect_to_require_current_master
|
14
10
|
|
11
|
+
describe '#execute' do
|
15
12
|
it 'requests grid details from master' do
|
16
13
|
expect(client).to receive(:get).with("grids/test-grid").and_return('trusted_subnets' => [
|
17
14
|
'192.168.0.1/24',
|
18
15
|
])
|
19
|
-
expect{subject.run([
|
16
|
+
expect{subject.run([])}.to output("192.168.0.1/24\n").to_stdout
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'supports the --grid option' do
|
20
|
+
allow(subject).to receive(:current_grid).and_call_original
|
21
|
+
expect(client).to receive(:get).with("grids/ingrid").and_return('trusted_subnets' => [
|
22
|
+
'192.168.0.1/24',
|
23
|
+
])
|
24
|
+
expect{subject.run(['--grid', 'ingrid'])}.to output("192.168.0.1/24\n").to_stdout
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -4,24 +4,40 @@ require "kontena/cli/grids/trusted_subnets/remove_command"
|
|
4
4
|
describe Kontena::Cli::Grids::TrustedSubnets::RemoveCommand do
|
5
5
|
|
6
6
|
include ClientHelpers
|
7
|
+
include RequirementsHelper
|
8
|
+
|
9
|
+
expect_to_require_current_master
|
7
10
|
|
8
11
|
describe '#execute' do
|
9
|
-
it 'requires
|
12
|
+
it 'requires subnet as param' do
|
10
13
|
expect {
|
11
14
|
subject.run([])
|
12
15
|
}.to raise_error(Clamp::UsageError)
|
13
16
|
end
|
14
17
|
|
15
18
|
it 'removes subnet from grid' do
|
16
|
-
allow(client).to receive(:get).with("grids/
|
19
|
+
allow(client).to receive(:get).with("grids/test-grid").and_return(
|
20
|
+
'trusted_subnets' => ['192.168.12.0/24', '192.168.50.0/24']
|
21
|
+
)
|
22
|
+
expect(client).to receive(:put).with(
|
23
|
+
'grids/test-grid', hash_including({trusted_subnets: [
|
24
|
+
'192.168.12.0/24'
|
25
|
+
]})
|
26
|
+
)
|
27
|
+
subject.run(['--force', '192.168.50.0/24'])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'supports the --grid option' do
|
31
|
+
allow(subject).to receive(:current_grid).and_call_original
|
32
|
+
allow(client).to receive(:get).with("grids/ingrid").and_return(
|
17
33
|
'trusted_subnets' => ['192.168.12.0/24', '192.168.50.0/24']
|
18
34
|
)
|
19
35
|
expect(client).to receive(:put).with(
|
20
|
-
'grids/
|
36
|
+
'grids/ingrid', hash_including({trusted_subnets: [
|
21
37
|
'192.168.12.0/24'
|
22
38
|
]})
|
23
39
|
)
|
24
|
-
subject.run(['--force', '
|
40
|
+
subject.run(['--force', '--grid', 'ingrid', '192.168.50.0/24'])
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -20,7 +20,7 @@ describe Kontena::Cli::Master::InitCloudCommand do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'runs the invite self after deploy callback' do
|
23
|
-
expect(Kontena).to receive(:run).with(
|
23
|
+
expect(Kontena).to receive(:run!).with(%w(cloud master add --current --force)).and_return(true)
|
24
24
|
expect_any_instance_of(Kontena::Callbacks::InviteSelfAfterDeploy).to receive(:after).and_return(true)
|
25
25
|
subject.run(['--force'])
|
26
26
|
end
|
@@ -7,8 +7,8 @@ describe Kontena::Cli::Master::User::InviteCommand do
|
|
7
7
|
|
8
8
|
describe "#invite" do
|
9
9
|
it 'makes invitation request for all given users' do
|
10
|
-
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'john@example.org', external_id: nil, response_type: "invite"}).once
|
11
|
-
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'jane@example.org', external_id: nil, response_type: "invite"}).once
|
10
|
+
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'john@example.org', external_id: nil, response_type: "invite"}).once.and_return(Hash.new { "foo" })
|
11
|
+
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'jane@example.org', external_id: nil, response_type: "invite"}).once.and_return(Hash.new { "bar" })
|
12
12
|
|
13
13
|
subject.run(['john@example.org', 'jane@example.org'])
|
14
14
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'kontena/cli/nodes/ssh_command'
|
2
|
+
|
3
|
+
describe Kontena::Cli::Nodes::SshCommand do
|
4
|
+
include ClientHelpers
|
5
|
+
|
6
|
+
let :node do
|
7
|
+
{
|
8
|
+
'labels' => [],
|
9
|
+
'public_ip' => '192.0.2.10',
|
10
|
+
'private_ip' => '10.0.8.10',
|
11
|
+
'overlay_ip' => '10.81.0.1',
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
allow(client).to receive(:get).with('nodes/test-grid/test-node').and_return(node)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "uses the public IP by default" do
|
20
|
+
expect(subject).to receive(:exec).with('ssh', 'core@192.0.2.10')
|
21
|
+
subject.run ['test-node']
|
22
|
+
end
|
23
|
+
|
24
|
+
it "uses the private IP" do
|
25
|
+
expect(subject).to receive(:exec).with('ssh', 'core@10.0.8.10')
|
26
|
+
subject.run ['--private-ip', 'test-node']
|
27
|
+
end
|
28
|
+
|
29
|
+
it "uses the overlay IP" do
|
30
|
+
expect(subject).to receive(:exec).with('ssh', 'core@10.81.0.1')
|
31
|
+
subject.run ['--internal-ip', 'test-node']
|
32
|
+
end
|
33
|
+
|
34
|
+
it "passes through the command to SSH" do
|
35
|
+
expect(subject).to receive(:exec).with('ssh', 'core@192.0.2.10', 'ls', '-l')
|
36
|
+
subject.run ['test-node', 'ls', '-l']
|
37
|
+
end
|
38
|
+
|
39
|
+
it "passes through arguments to SSH" do
|
40
|
+
expect(subject).to receive(:exec).with('ssh', 'core@192.0.2.10', '-F', 'ssh/config' 'ls', '-l')
|
41
|
+
subject.run ['test-node', '-F', 'ssh/config' 'ls', '-l']
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "kontena/cli/stacks/restart_command"
|
2
|
+
|
3
|
+
describe Kontena::Cli::Stacks::RestartCommand do
|
4
|
+
include ClientHelpers
|
5
|
+
include RequirementsHelper
|
6
|
+
|
7
|
+
expect_to_require_current_master
|
8
|
+
expect_to_require_current_master_token
|
9
|
+
|
10
|
+
describe '#execute' do
|
11
|
+
it 'sends stop request to server' do
|
12
|
+
expect(client).to receive(:post).with('stacks/test-grid/foo/restart', {})
|
13
|
+
subject.run(['foo'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "kontena/cli/stacks/stop_command"
|
2
|
+
|
3
|
+
describe Kontena::Cli::Stacks::StopCommand do
|
4
|
+
include ClientHelpers
|
5
|
+
include RequirementsHelper
|
6
|
+
|
7
|
+
expect_to_require_current_master
|
8
|
+
expect_to_require_current_master_token
|
9
|
+
|
10
|
+
describe '#execute' do
|
11
|
+
it 'sends stop request to server' do
|
12
|
+
expect(client).to receive(:post).with('stacks/test-grid/foo/stop', {})
|
13
|
+
subject.run(['foo'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -89,7 +89,7 @@ describe Kontena::Cli::Stacks::UpgradeCommand do
|
|
89
89
|
allow(client).to receive(:put).with(
|
90
90
|
'stacks/test-grid/stack-a', anything
|
91
91
|
).and_return({})
|
92
|
-
expect(Kontena).to receive(:run).with(['stack', 'deploy', 'stack-a']).once
|
92
|
+
expect(Kontena).to receive(:run!).with(['stack', 'deploy', 'stack-a']).once
|
93
93
|
subject.run(['stack-a', './path/to/kontena.yml'])
|
94
94
|
end
|
95
95
|
|
@@ -101,7 +101,7 @@ describe Kontena::Cli::Stacks::UpgradeCommand do
|
|
101
101
|
allow(client).to receive(:put).with(
|
102
102
|
'stacks/test-grid/stack-a', anything
|
103
103
|
).and_return({})
|
104
|
-
expect(Kontena).not_to receive(:run).with(['stack', 'deploy', 'stack-a'])
|
104
|
+
expect(Kontena).not_to receive(:run!).with(['stack', 'deploy', 'stack-a'])
|
105
105
|
subject.run(['--no-deploy', 'stack-a', './path/to/kontena.yml'])
|
106
106
|
end
|
107
107
|
end
|
@@ -108,20 +108,40 @@ describe Kontena::Cli::Stacks::YAML::ValidatorV3 do
|
|
108
108
|
expect(result.errors.key?('environment')).to be_falsey
|
109
109
|
result = subject.validate_options('environment' => { 'KEY' => 'VALUE' })
|
110
110
|
expect(result.errors.key?('environment')).to be_falsey
|
111
|
+
result = subject.validate_options('environment' => ['KEY=VALUE', 'KEY2=VALUE2', 'KEY3='])
|
112
|
+
expect(result.errors.key?('environment')).to be_falsey
|
111
113
|
end
|
112
114
|
|
113
115
|
it 'fails validation if environment array includes items without equals sign' do
|
114
|
-
result = subject.validate_options('environment' => ['KEY=VALUE', 'KEY2=VALUE2'])
|
115
|
-
expect(result.errors.key?('environment')).to be_falsey
|
116
116
|
result = subject.validate_options('environment' => ['KEY=VALUE', 'KEY2 VALUE'])
|
117
117
|
expect(result.errors.key?('environment')).to be_truthy
|
118
118
|
end
|
119
119
|
|
120
|
+
it "fails validation if environment has invalid key prefix" do
|
121
|
+
result = subject.validate_options('environment' => ['=VALUE'])
|
122
|
+
expect(result.errors.key?('environment')).to be_truthy
|
123
|
+
end
|
124
|
+
|
125
|
+
it "fails validation if environemnt has invalid key prefix with valud key prefix in value" do
|
126
|
+
result = subject.validate_options('environment' => ['=VALUE=VALUE2'])
|
127
|
+
expect(result.errors.key?('environment')).to be_truthy
|
128
|
+
end
|
129
|
+
|
130
|
+
it "fails validation if environment contains invalid key prefix with valid key prefix in multi-line value" do
|
131
|
+
result = subject.validate_options('environment' => ['=ASDF\nKEY=VALUE'])
|
132
|
+
expect(result.errors.key?('environment')).to be_truthy
|
133
|
+
end
|
134
|
+
|
120
135
|
it 'passes validation if environment array includes items with booleans or nils' do
|
121
136
|
result = subject.validate_options('environment' => { 'KEY' => true, 'KEY2' => false, 'KEY3' => nil })
|
122
137
|
expect(result.errors.key?('environment')).to be_falsey
|
123
138
|
end
|
124
139
|
|
140
|
+
it 'passes validation if environment array includes items with multi-line values' do
|
141
|
+
result = subject.validate_options('environment' => [ "KEY=foo\nbar" ])
|
142
|
+
expect(result.errors.key?('environment')).to be_falsey
|
143
|
+
end
|
144
|
+
|
125
145
|
context 'validates secrets' do
|
126
146
|
it 'must be array' do
|
127
147
|
result = subject.validate_options('secrets' => {})
|
@@ -15,16 +15,16 @@ describe Kontena::Cli::Vault::ExportCommand do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'goes through the list of vault keys and outputs a yaml' do
|
18
|
-
expect(Kontena).to receive(:run).with(
|
19
|
-
expect(Kontena).to receive(:run).with(
|
20
|
-
expect(Kontena).to receive(:run).with(
|
18
|
+
expect(Kontena).to receive(:run!).with(['vault', 'ls', '--return']).and_return(['foo', 'bar'])
|
19
|
+
expect(Kontena).to receive(:run!).with(['vault', 'read', '--return', 'bar']).and_return('barbar')
|
20
|
+
expect(Kontena).to receive(:run!).with(['vault', 'read', '--return', 'foo']).and_return('foofoo')
|
21
21
|
expect{subject.run([])}.to output(/bar: barbar\nfoo: foofoo/).to_stdout
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'goes through the list of vault keys and outputs a json' do
|
25
|
-
expect(Kontena).to receive(:run).with(
|
26
|
-
expect(Kontena).to receive(:run).with(
|
27
|
-
expect(Kontena).to receive(:run).with(
|
25
|
+
expect(Kontena).to receive(:run!).with(['vault', 'ls', '--return']).and_return(['foo', 'bar'])
|
26
|
+
expect(Kontena).to receive(:run!).with(['vault', 'read', '--return', 'bar']).and_return('barbar')
|
27
|
+
expect(Kontena).to receive(:run!).with(['vault', 'read', '--return', 'foo']).and_return('foofoo')
|
28
28
|
expect{subject.run(['--json'])}.to output(/\"bar\":\"barbar\",\"foo\":\"foofoo\"/).to_stdout
|
29
29
|
end
|
30
30
|
|
@@ -30,39 +30,38 @@ describe Kontena::Cli::Vault::ImportCommand do
|
|
30
30
|
|
31
31
|
it 'runs vault write for kv-pairs in yaml' do
|
32
32
|
expect(File).to receive(:read).with('foo.yml').and_return("foo: bar\nbar: foo\n")
|
33
|
-
expect(Kontena).to receive(:run).with(
|
34
|
-
expect(Kontena).to receive(:run).with(
|
33
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'foo', 'bar']).and_return(true)
|
34
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'bar', 'foo']).and_return(true)
|
35
35
|
subject.run(['--force', 'foo.yml'])
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'runs vault rm for kv-pairs with null value in yaml' do
|
39
39
|
expect(File).to receive(:read).with('foo.yml').and_return("foo: bar\nbar: null\n")
|
40
|
-
expect(Kontena).to receive(:run).with(
|
41
|
-
expect(Kontena).to receive(:run).with(
|
40
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'foo', 'bar']).and_return(true)
|
41
|
+
expect(Kontena).to receive(:run).with(['vault', 'rm', '--silent', '--force', 'bar']).and_return(true)
|
42
42
|
subject.run(['--force', 'foo.yml'])
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'runs vault rm for kv-pairs with empty value in yaml when --empty-is-null' do
|
46
46
|
expect(File).to receive(:read).with('foo.yml').and_return("foo: bar\nbar:\n")
|
47
|
-
expect(Kontena).to receive(:run).with(
|
48
|
-
expect(Kontena).to receive(:run).with(
|
47
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'foo', 'bar']).and_return(true)
|
48
|
+
expect(Kontena).to receive(:run).with(['vault', 'rm', '--silent', '--force', 'bar']).and_return(true)
|
49
49
|
subject.run(['--force', '--empty-is-null', 'foo.yml'])
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'does not run vault rm for kv-pairs with empty value in yaml when no --empty-is-null' do
|
53
53
|
expect(File).to receive(:read).with('foo.yml').and_return("foo: bar\nbar: \"\"\n")
|
54
|
-
expect(Kontena).to receive(:run).with(
|
55
|
-
expect(Kontena).to receive(:run).with(
|
56
|
-
expect(Kontena).not_to receive(:run).with(
|
54
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'foo', 'bar']).and_return(true)
|
55
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'bar', '']).and_return(true)
|
56
|
+
expect(Kontena).not_to receive(:run).with(['vault', 'rm', '--silent', '--force', 'bar'])
|
57
57
|
subject.run(['--force', 'foo.yml'])
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'doesnt vault rm for kv-pairs with null value in yaml when --skip-null used' do
|
61
61
|
expect(File).to receive(:read).with('foo.yml').and_return("foo: bar\nbar: null\n")
|
62
|
-
expect(Kontena).to receive(:run).with(
|
63
|
-
expect(Kontena).not_to receive(:run).with(
|
62
|
+
expect(Kontena).to receive(:run).with(['vault', 'update', '--upsert', '--silent', 'foo', 'bar']).and_return(true)
|
63
|
+
expect(Kontena).not_to receive(:run).with(['vault', 'rm', '--silent', '--force', 'bar'])
|
64
64
|
subject.run(['--force', '--skip-null', 'foo.yml'])
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
68
67
|
|
@@ -30,24 +30,59 @@ describe Kontena do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe '#run' do
|
33
|
+
describe '#run!' do
|
34
34
|
let(:whoami) { double(:whoami) }
|
35
35
|
|
36
36
|
before(:each) do
|
37
37
|
expect(Kontena::Cli::WhoamiCommand).to receive(:new).and_return(whoami)
|
38
|
-
expect(whoami).to receive(:run).with(['--bash-completion-path']).and_return(true)
|
39
38
|
end
|
40
39
|
|
41
40
|
it 'accepts a command line as string' do
|
42
|
-
|
41
|
+
expect(whoami).to receive(:run).with(['--bash-completion-path']).and_return(true)
|
42
|
+
Kontena.run!('whoami --bash-completion-path')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'accepts a command line as a list of parameters' do
|
46
|
-
|
46
|
+
expect(whoami).to receive(:run).with(['--bash-completion-path']).and_return(true)
|
47
|
+
Kontena.run!('whoami', '--bash-completion-path')
|
47
48
|
end
|
48
49
|
|
49
50
|
it 'accepts a command line as an array' do
|
50
|
-
|
51
|
+
expect(whoami).to receive(:run).with(['--bash-completion-path']).and_return(true)
|
52
|
+
Kontena.run!(['whoami', '--bash-completion-path'])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'Returns true if the command exits with SystemExit status 0' do
|
56
|
+
expect(whoami).to receive(:run) { exit 0 }
|
57
|
+
expect(Kontena.run!(['whoami'])).to be_truthy
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'Re-raises the SystemExit when command exits with non-zero status' do
|
61
|
+
expect(whoami).to receive(:run) { exit 1 }
|
62
|
+
expect{Kontena.run!(['whoami'])}.to exit_with_error.status(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#run' do
|
67
|
+
let(:whoami) { double(:whoami) }
|
68
|
+
|
69
|
+
before(:each) do
|
70
|
+
expect(Kontena::Cli::WhoamiCommand).to receive(:new).and_return(whoami)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'Returns false when status is 1' do
|
74
|
+
expect(whoami).to receive(:run) { exit 1 }
|
75
|
+
expect(Kontena.run(['whoami'])).to be_falsey
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'Returns true when status is 0' do
|
79
|
+
expect(whoami).to receive(:run) { exit 0 }
|
80
|
+
expect(Kontena.run(['whoami'])).to be_truthy
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'Returns true when nothing was raised' do
|
84
|
+
expect(whoami).to receive(:run).and_return(nil)
|
85
|
+
expect(Kontena.run(['whoami'])).to be_truthy
|
51
86
|
end
|
52
87
|
end
|
53
88
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -49,14 +49,16 @@ RSpec.configure do |config|
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
unless ENV["DEBUG"]
|
53
|
+
config.before(:each) do
|
54
|
+
$stdout = StringIO.new
|
55
|
+
$stderr = StringIO.new
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
config.after(:each) do
|
59
|
+
$stdout = STDOUT
|
60
|
+
$stderr = STDERR
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|