kontena-cli 0.15.5 → 0.16.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +0 -3
- data/Gemfile +3 -0
- data/LOGO +8 -0
- data/VERSION +1 -1
- data/kontena-cli.gemspec +2 -3
- data/lib/kontena/callback.rb +57 -0
- data/lib/kontena/callbacks/.gitkeep +0 -0
- data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +27 -0
- data/lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb +20 -0
- data/lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb +15 -0
- data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +124 -0
- data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +53 -0
- data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +32 -0
- data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +49 -0
- data/lib/kontena/callbacks/master/deploy/90_suggest_inviting_yourself_after_deploy.rb +24 -0
- data/lib/kontena/cli/app_command.rb +2 -1
- data/lib/kontena/cli/apps/build_command.rb +1 -1
- data/lib/kontena/cli/apps/common.rb +6 -1
- data/lib/kontena/cli/apps/config_command.rb +1 -1
- data/lib/kontena/cli/apps/deploy_command.rb +1 -1
- data/lib/kontena/cli/apps/init_command.rb +3 -5
- data/lib/kontena/cli/apps/list_command.rb +1 -1
- data/lib/kontena/cli/apps/logs_command.rb +1 -1
- data/lib/kontena/cli/apps/monitor_command.rb +1 -1
- data/lib/kontena/cli/apps/remove_command.rb +2 -3
- data/lib/kontena/cli/apps/restart_command.rb +1 -1
- data/lib/kontena/cli/apps/scale_command.rb +1 -1
- data/lib/kontena/cli/apps/show_command.rb +1 -1
- data/lib/kontena/cli/apps/start_command.rb +1 -1
- data/lib/kontena/cli/apps/stop_command.rb +1 -1
- data/lib/kontena/cli/apps/yaml/reader.rb +3 -13
- data/lib/kontena/cli/apps/yaml/validator.rb +0 -4
- data/lib/kontena/cli/apps/yaml/validator_v2.rb +1 -5
- data/lib/kontena/cli/certificate/authorize_command.rb +1 -1
- data/lib/kontena/cli/certificate/get_command.rb +1 -1
- data/lib/kontena/cli/certificate/register_command.rb +1 -1
- data/lib/kontena/cli/certificate_command.rb +1 -1
- data/lib/kontena/cli/cloud/login_command.rb +128 -0
- data/lib/kontena/cli/cloud/master/add_command.rb +54 -0
- data/lib/kontena/cli/cloud/master/delete_command.rb +20 -0
- data/lib/kontena/cli/cloud/master/list_command.rb +29 -0
- data/lib/kontena/cli/cloud/master/show_command.rb +23 -0
- data/lib/kontena/cli/cloud/master/update_command.rb +58 -0
- data/lib/kontena/cli/cloud/master_command.rb +21 -0
- data/lib/kontena/cli/cloud_command.rb +10 -0
- data/lib/kontena/cli/common.rb +230 -88
- data/lib/kontena/cli/config.rb +537 -0
- data/lib/kontena/cli/container_command.rb +1 -1
- data/lib/kontena/cli/containers/exec_command.rb +1 -1
- data/lib/kontena/cli/containers/inspect_command.rb +1 -1
- data/lib/kontena/cli/etcd/get_command.rb +1 -1
- data/lib/kontena/cli/etcd/list_command.rb +1 -1
- data/lib/kontena/cli/etcd/mkdir_command.rb +1 -1
- data/lib/kontena/cli/etcd/remove_command.rb +1 -1
- data/lib/kontena/cli/etcd/set_command.rb +1 -1
- data/lib/kontena/cli/etcd_command.rb +1 -1
- data/lib/kontena/cli/external_registries/add_command.rb +1 -1
- data/lib/kontena/cli/external_registries/delete_command.rb +1 -1
- data/lib/kontena/cli/external_registries/list_command.rb +1 -1
- data/lib/kontena/cli/external_registries/remove_command.rb +1 -1
- data/lib/kontena/cli/external_registry_command.rb +1 -1
- data/lib/kontena/cli/grid_command.rb +1 -1
- data/lib/kontena/cli/grids/audit_log_command.rb +6 -5
- data/lib/kontena/cli/grids/cloud_config_command.rb +1 -1
- data/lib/kontena/cli/grids/common.rb +1 -1
- data/lib/kontena/cli/grids/create_command.rb +8 -4
- data/lib/kontena/cli/grids/current_command.rb +1 -1
- data/lib/kontena/cli/grids/env_command.rb +1 -1
- data/lib/kontena/cli/grids/list_command.rb +35 -10
- data/lib/kontena/cli/grids/logs_command.rb +1 -1
- data/lib/kontena/cli/grids/remove_command.rb +2 -2
- data/lib/kontena/cli/grids/show_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnet_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/add_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +1 -1
- data/lib/kontena/cli/grids/trusted_subnets/remove_command.rb +1 -1
- data/lib/kontena/cli/grids/update_command.rb +1 -1
- data/lib/kontena/cli/grids/use_command.rb +11 -6
- data/lib/kontena/cli/grids/user_command.rb +1 -1
- data/lib/kontena/cli/grids/users/add_command.rb +1 -1
- data/lib/kontena/cli/grids/users/list_command.rb +1 -1
- data/lib/kontena/cli/grids/users/remove_command.rb +1 -1
- data/lib/kontena/cli/localhost_web_server.rb +93 -0
- data/lib/kontena/cli/login_command.rb +5 -118
- data/lib/kontena/cli/logout_command.rb +33 -2
- data/lib/kontena/cli/master/audit_log_command.rb +19 -0
- data/lib/kontena/cli/master/config/export_command.rb +47 -0
- data/lib/kontena/cli/master/config/get_command.rb +24 -0
- data/lib/kontena/cli/master/config/import_command.rb +69 -0
- data/lib/kontena/cli/master/config/set_command.rb +19 -0
- data/lib/kontena/cli/master/config/unset_command.rb +20 -0
- data/lib/kontena/cli/master/config_command.rb +24 -0
- data/lib/kontena/cli/master/create_command.rb +76 -0
- data/lib/kontena/cli/master/current_command.rb +10 -2
- data/lib/kontena/cli/master/join_command.rb +20 -0
- data/lib/kontena/cli/master/list_command.rb +4 -4
- data/lib/kontena/cli/master/login_command.rb +274 -0
- data/lib/kontena/cli/master/use_command.rb +8 -19
- data/lib/kontena/cli/master/users/invite_command.rb +33 -6
- data/lib/kontena/cli/master/users/list_command.rb +2 -2
- data/lib/kontena/cli/master/users/remove_command.rb +1 -1
- data/lib/kontena/cli/master/users/role_command.rb +1 -1
- data/lib/kontena/cli/master/users/roles/add_command.rb +18 -16
- data/lib/kontena/cli/master/users/roles/remove_command.rb +1 -1
- data/lib/kontena/cli/master/users_command.rb +1 -1
- data/lib/kontena/cli/master_command.rb +21 -1
- data/lib/kontena/cli/node_command.rb +1 -1
- data/lib/kontena/cli/nodes/label_command.rb +1 -1
- data/lib/kontena/cli/nodes/labels/add_command.rb +1 -1
- data/lib/kontena/cli/nodes/labels/remove_command.rb +1 -1
- data/lib/kontena/cli/nodes/list_command.rb +1 -1
- data/lib/kontena/cli/nodes/remove_command.rb +1 -1
- data/lib/kontena/cli/nodes/show_command.rb +1 -1
- data/lib/kontena/cli/nodes/ssh_command.rb +1 -1
- data/lib/kontena/cli/nodes/update_command.rb +1 -1
- data/lib/kontena/cli/plugin_command.rb +1 -1
- data/lib/kontena/cli/plugins/install_command.rb +2 -2
- data/lib/kontena/cli/plugins/list_command.rb +2 -2
- data/lib/kontena/cli/plugins/search_command.rb +1 -1
- data/lib/kontena/cli/plugins/uninstall_command.rb +2 -2
- data/lib/kontena/cli/registry/create_command.rb +2 -4
- data/lib/kontena/cli/registry/delete_command.rb +1 -1
- data/lib/kontena/cli/registry/remove_command.rb +1 -1
- data/lib/kontena/cli/registry_command.rb +1 -1
- data/lib/kontena/cli/service_command.rb +1 -1
- data/lib/kontena/cli/services/container_command.rb +1 -1
- data/lib/kontena/cli/services/containers_command.rb +1 -1
- data/lib/kontena/cli/services/create_command.rb +1 -1
- data/lib/kontena/cli/services/delete_command.rb +1 -1
- data/lib/kontena/cli/services/deploy_command.rb +1 -1
- data/lib/kontena/cli/services/env_command.rb +1 -1
- data/lib/kontena/cli/services/envs/add_command.rb +1 -1
- data/lib/kontena/cli/services/envs/list_command.rb +1 -1
- data/lib/kontena/cli/services/envs/remove_command.rb +1 -1
- data/lib/kontena/cli/services/link_command.rb +1 -1
- data/lib/kontena/cli/services/list_command.rb +1 -1
- data/lib/kontena/cli/services/logs_command.rb +1 -1
- data/lib/kontena/cli/services/monitor_command.rb +1 -1
- data/lib/kontena/cli/services/remove_command.rb +1 -1
- data/lib/kontena/cli/services/restart_command.rb +1 -1
- data/lib/kontena/cli/services/scale_command.rb +1 -1
- data/lib/kontena/cli/services/secret_command.rb +1 -1
- data/lib/kontena/cli/services/secrets/link_command.rb +1 -1
- data/lib/kontena/cli/services/secrets/unlink_command.rb +1 -1
- data/lib/kontena/cli/services/services_helper.rb +6 -3
- data/lib/kontena/cli/services/show_command.rb +1 -1
- data/lib/kontena/cli/services/start_command.rb +1 -1
- data/lib/kontena/cli/services/stats_command.rb +1 -1
- data/lib/kontena/cli/services/stop_command.rb +1 -1
- data/lib/kontena/cli/services/unlink_command.rb +1 -1
- data/lib/kontena/cli/services/update_command.rb +1 -1
- data/lib/kontena/cli/spinner.rb +122 -0
- data/lib/kontena/cli/stack_command.rb +1 -1
- data/lib/kontena/cli/stacks/create_command.rb +1 -1
- data/lib/kontena/cli/stacks/deploy_command.rb +1 -1
- data/lib/kontena/cli/stacks/list_command.rb +1 -1
- data/lib/kontena/cli/stacks/remove_command.rb +1 -1
- data/lib/kontena/cli/stacks/show_command.rb +1 -1
- data/lib/kontena/cli/stacks/update_command.rb +1 -1
- data/lib/kontena/cli/vault/list_command.rb +1 -1
- data/lib/kontena/cli/vault/read_command.rb +1 -1
- data/lib/kontena/cli/vault/remove_command.rb +1 -1
- data/lib/kontena/cli/vault/update_command.rb +1 -1
- data/lib/kontena/cli/vault/write_command.rb +1 -1
- data/lib/kontena/cli/vault_command.rb +1 -1
- data/lib/kontena/cli/version.rb +1 -1
- data/lib/kontena/cli/version_command.rb +1 -1
- data/lib/kontena/cli/vpn/config_command.rb +1 -1
- data/lib/kontena/cli/vpn/create_command.rb +2 -4
- data/lib/kontena/cli/vpn/delete_command.rb +1 -1
- data/lib/kontena/cli/vpn/remove_command.rb +1 -1
- data/lib/kontena/cli/vpn_command.rb +1 -1
- data/lib/kontena/cli/whoami_command.rb +16 -13
- data/lib/kontena/client.rb +410 -90
- data/lib/kontena/command.rb +172 -0
- data/lib/kontena/main_command.rb +7 -8
- data/lib/kontena/presets/github_auth_provider.yml +11 -0
- data/lib/kontena/presets/kontena_auth_provider.yml +11 -0
- data/lib/kontena_cli.rb +51 -1
- data/spec/kontena/cli/app/deploy_command_spec.rb +14 -44
- data/spec/kontena/cli/app/scale_spec.rb +1 -1
- data/spec/kontena/cli/app/yaml/reader_spec.rb +0 -48
- data/spec/kontena/cli/common_spec.rb +63 -59
- data/spec/kontena/cli/grids/use_command_spec.rb +43 -0
- data/spec/kontena/cli/master/current_command_spec.rb +3 -24
- data/spec/kontena/cli/master/use_command_spec.rb +2 -27
- data/spec/kontena/cli/master/users/invite_command_spec.rb +4 -18
- data/spec/kontena/cli/master/users/roles/add_command_spec.rb +2 -16
- data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +2 -13
- data/spec/kontena/cli/services/restart_command_spec.rb +1 -1
- data/spec/kontena/cli/services/update_command_spec.rb +5 -5
- data/spec/kontena/client_spec.rb +104 -35
- data/spec/kontena/config_spec.rb +65 -0
- data/spec/spec_helper.rb +25 -3
- data/spec/support/client_helpers.rb +10 -3
- data/spec/support/requirements_helper.rb +32 -0
- metadata +61 -48
- data/lib/kontena/cli/register_command.rb +0 -23
- data/lib/kontena/cli/user/forgot_password_command.rb +0 -16
- data/lib/kontena/cli/user/reset_password_command.rb +0 -23
- data/lib/kontena/cli/user/verify_command.rb +0 -20
- data/lib/kontena/cli/user_command.rb +0 -13
- data/spec/fixtures/kontena-malformed-yaml.yml +0 -6
- data/spec/fixtures/kontena-not-hash-service-config.yml +0 -3
- data/spec/kontena/cli/login_command_spec.rb +0 -32
- data/spec/kontena/cli/register_command_spec.rb +0 -57
@@ -156,28 +156,6 @@ describe Kontena::Cli::Apps::YAML::Reader do
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
context 'when yaml file is malformed' do
|
160
|
-
it 'exits the execution' do
|
161
|
-
allow(File).to receive(:read)
|
162
|
-
.with(absolute_yaml_path)
|
163
|
-
.and_return(fixture('kontena-malformed-yaml.yml'))
|
164
|
-
expect {
|
165
|
-
subject.execute
|
166
|
-
}.to raise_error(SystemExit)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'when service config is not hash' do
|
171
|
-
it 'returns error' do
|
172
|
-
allow(File).to receive(:read)
|
173
|
-
.with(absolute_yaml_path)
|
174
|
-
.and_return(fixture('kontena-not-hash-service-config.yml'))
|
175
|
-
|
176
|
-
outcome = subject.execute
|
177
|
-
expect(outcome[:errors].size).to eq(1)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
159
|
describe '#v2?' do
|
182
160
|
context 'version 1' do
|
183
161
|
it 'returns false' do
|
@@ -429,30 +407,4 @@ describe Kontena::Cli::Apps::YAML::Reader do
|
|
429
407
|
end
|
430
408
|
end
|
431
409
|
end
|
432
|
-
|
433
|
-
describe '#stack_name' do
|
434
|
-
it 'returns nil for v1' do
|
435
|
-
allow(File).to receive(:read)
|
436
|
-
.with(absolute_yaml_path('kontena.yml'))
|
437
|
-
.and_return(fixture('kontena.yml'))
|
438
|
-
name = subject.stack_name
|
439
|
-
expect(name).to be_nil
|
440
|
-
end
|
441
|
-
|
442
|
-
it 'returns name for v2 if defined' do
|
443
|
-
allow(File).to receive(:read)
|
444
|
-
.with(absolute_yaml_path('kontena.yml'))
|
445
|
-
.and_return(fixture('kontena_v2.yml'))
|
446
|
-
name = subject.stack_name
|
447
|
-
expect(name).to eq('test-project')
|
448
|
-
end
|
449
|
-
|
450
|
-
it 'returns nil for v2 if not defined' do
|
451
|
-
allow(File).to receive(:read)
|
452
|
-
.with(absolute_yaml_path('kontena.yml'))
|
453
|
-
.and_return(fixture('docker-compose.yml'))
|
454
|
-
name = subject.stack_name
|
455
|
-
expect(name).to be_nil
|
456
|
-
end
|
457
|
-
end
|
458
410
|
end
|
@@ -9,35 +9,44 @@ describe Kontena::Cli::Common do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
before(:each) do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
RSpec::Mocks.space.proxy_for(File).reset
|
13
|
+
Kontena::Cli::Config.reset_instance
|
14
|
+
end
|
15
|
+
|
16
|
+
def mock_config(cfg_hash)
|
17
|
+
expect(File).to receive(:readable?).and_return(true)
|
18
|
+
expect(File).to receive(:exist?).and_return(true)
|
19
|
+
expect(File).to receive(:read).and_return(cfg_hash.to_json)
|
16
20
|
end
|
17
21
|
|
18
22
|
describe '#current_grid' do
|
19
23
|
it 'returns nil by default' do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
mock_config({
|
25
|
+
'current_server' => 'alias',
|
26
|
+
'servers' => [
|
27
|
+
{'name' => 'some_master', 'url' => 'some_master'},
|
28
|
+
{'name' => 'alias', 'url' => 'someurl'}
|
29
|
+
]
|
30
|
+
})
|
31
|
+
|
26
32
|
expect(subject.current_grid).to eq(nil)
|
27
33
|
end
|
28
34
|
|
29
35
|
it 'returns grid from env' do
|
30
|
-
|
36
|
+
allow(ENV).to receive(:[]).with(anything).and_return(nil)
|
37
|
+
allow(ENV).to receive(:[]).with('DEBUG').and_call_original
|
38
|
+
allow(ENV).to receive(:[]).with('KONTENA_GRID').and_return('foo')
|
31
39
|
expect(subject.current_grid).to eq('foo')
|
32
40
|
end
|
33
41
|
|
34
42
|
it 'returns grid from json' do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
mock_config({
|
44
|
+
'current_server' => 'alias',
|
45
|
+
'servers' => [
|
46
|
+
{'name' => 'some_master', 'url' => 'some_master'},
|
47
|
+
{'name' => 'alias', 'url' => 'someurl', 'grid' => 'foo_grid'}
|
48
|
+
]
|
49
|
+
})
|
41
50
|
expect(subject.current_grid).to eq('foo_grid')
|
42
51
|
end
|
43
52
|
|
@@ -55,7 +64,8 @@ describe Kontena::Cli::Common do
|
|
55
64
|
end
|
56
65
|
|
57
66
|
it 'return url from env' do
|
58
|
-
|
67
|
+
allow(ENV).to receive(:[]).with(anything).and_return(nil)
|
68
|
+
allow(ENV).to receive(:[]).with('KONTENA_URL').and_return('https://domain.com')
|
59
69
|
expect(subject.api_url).to eq('https://domain.com')
|
60
70
|
end
|
61
71
|
end
|
@@ -66,22 +76,17 @@ describe Kontena::Cli::Common do
|
|
66
76
|
subject.require_token
|
67
77
|
}.to raise_error(ArgumentError)
|
68
78
|
end
|
69
|
-
|
70
|
-
it 'return token from env' do
|
71
|
-
expect(ENV).to receive(:[]).with('KONTENA_TOKEN').and_return('secret_token')
|
72
|
-
expect(subject.require_token).to eq('secret_token')
|
73
|
-
end
|
74
79
|
end
|
75
80
|
|
76
81
|
describe '#current_master' do
|
77
82
|
it 'return correct master info' do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
mock_config({
|
84
|
+
'current_server' => 'alias',
|
85
|
+
'servers' => [
|
86
|
+
{'name' => 'some_master', 'url' => 'some_master'},
|
87
|
+
{'name' => 'alias', 'url' => 'someurl'}
|
88
|
+
]
|
89
|
+
})
|
85
90
|
expect(subject.current_master['url']).to eq('someurl')
|
86
91
|
expect(subject.current_master['name']).to eq('alias')
|
87
92
|
end
|
@@ -89,51 +94,50 @@ describe Kontena::Cli::Common do
|
|
89
94
|
|
90
95
|
describe '#settings' do
|
91
96
|
it 'migrates old settings' do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
"url": "https://master.domain.com:8443",
|
98
|
-
"grid": "my-grid",
|
99
|
-
"token": "kontena-token"
|
97
|
+
mock_config({
|
98
|
+
"server" => {
|
99
|
+
"url" => "https://master.domain.com:8443",
|
100
|
+
"grid" => "my-grid",
|
101
|
+
"token" => "kontena-token"
|
100
102
|
}
|
101
|
-
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
subject.settings
|
103
|
+
})
|
104
|
+
expect(File).to receive(:write) do |filename, content|
|
105
|
+
expect(File.basename(filename)).to eq(".kontena_client.json")
|
106
|
+
config_hash = JSON.parse(content)
|
107
|
+
expect(config_hash['servers']).to be_kind_of(Array)
|
108
|
+
expect(config_hash['servers'].first).to be_kind_of(Hash)
|
109
|
+
expect(config_hash['servers'].first['name']).to eq("default")
|
110
|
+
expect(config_hash['servers'].first['url']).to eq("https://master.domain.com:8443")
|
111
|
+
expect(config_hash['servers'].first['token']).to eq("kontena-token")
|
112
|
+
expect(config_hash['servers'].first['grid']).to eq("my-grid")
|
113
|
+
expect(config_hash['current_server']).to be_kind_of(String)
|
114
|
+
expect(config_hash['current_server']).to eq("default")
|
115
|
+
end
|
116
|
+
subject.config.write
|
116
117
|
end
|
117
118
|
|
118
119
|
end
|
119
120
|
|
120
121
|
describe '#error' do
|
121
122
|
it 'prints error message to stderr if given and raise error' do
|
122
|
-
|
123
|
-
|
123
|
+
begin
|
124
|
+
expect{subject.error('error message!')}.to output('error message').to_stderr
|
125
|
+
rescue SystemExit => ex
|
126
|
+
expect(ex.status).to be 1
|
127
|
+
end
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
127
131
|
describe '#confirm_command' do
|
128
132
|
it 'returns true if input matches' do
|
129
|
-
allow(subject).to receive(:
|
133
|
+
allow(subject).to receive(:ask).and_return('name-to-confirm')
|
130
134
|
|
131
135
|
expect(subject.confirm_command('name-to-confirm')).to be_truthy
|
132
136
|
expect{subject.confirm_command('name-to-confirm')}.to_not raise_error
|
133
137
|
end
|
134
138
|
|
135
139
|
it 'raises error unless input matches' do
|
136
|
-
expect(subject).to receive(:
|
140
|
+
expect(subject).to receive(:ask).and_return('wrong-name')
|
137
141
|
expect(subject).to receive(:error).with(/did not match/)
|
138
142
|
|
139
143
|
subject.confirm_command('name-to-confirm')
|
@@ -142,14 +146,14 @@ describe Kontena::Cli::Common do
|
|
142
146
|
|
143
147
|
describe '#confirm' do
|
144
148
|
it 'returns true if confirmed' do
|
145
|
-
allow(subject).to receive(:
|
149
|
+
allow(subject.prompt).to receive(:yes?).and_return(true)
|
146
150
|
|
147
151
|
expect(subject.confirm).to be_truthy
|
148
152
|
expect{subject.confirm}.to_not raise_error
|
149
153
|
end
|
150
154
|
|
151
155
|
it 'raises error unless confirmed' do
|
152
|
-
expect(subject).to receive(:
|
156
|
+
expect(subject.prompt).to receive(:yes?).and_return(false)
|
153
157
|
expect(subject).to receive(:error).with(/Aborted/)
|
154
158
|
|
155
159
|
subject.confirm
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
require_relative "../../../spec_helper"
|
3
|
+
require 'kontena/cli/grids/use_command'
|
4
|
+
|
5
|
+
describe Kontena::Cli::Grids::UseCommand do
|
6
|
+
|
7
|
+
include RequirementsHelper
|
8
|
+
|
9
|
+
let(:client) do
|
10
|
+
Kontena::Client.new('https://foo', {access_token: 'abcd1234'})
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:subject) do
|
14
|
+
described_class.new(File.basename($0))
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:server) do
|
18
|
+
Kontena::Cli::Config::Server.new(url: 'https://localhost', token: 'abcd1234')
|
19
|
+
end
|
20
|
+
|
21
|
+
expect_to_require_current_master
|
22
|
+
|
23
|
+
describe "#use" do
|
24
|
+
before(:each) do
|
25
|
+
expect(subject).to receive(:client).and_return(client)
|
26
|
+
expect(Kontena::Cli::Config.instance).to receive(:write).and_return(true)
|
27
|
+
expect(Kontena::Cli::Config.instance).to receive(:require_current_master).and_return(server)
|
28
|
+
expect(Kontena::Cli::Config.instance).to receive(:current_master).and_return(server)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the current grid in config" do
|
32
|
+
expect(server).to receive(:grid=).with('foo')
|
33
|
+
expect(client).to receive(:get).and_return(
|
34
|
+
{ 'grids' => [
|
35
|
+
{ 'name' => 'foo' }
|
36
|
+
]
|
37
|
+
}
|
38
|
+
)
|
39
|
+
subject.run(['foo'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -2,52 +2,31 @@ require_relative "../../../spec_helper"
|
|
2
2
|
require 'kontena/cli/master/current_command'
|
3
3
|
|
4
4
|
describe Kontena::Cli::Master::CurrentCommand do
|
5
|
-
|
6
|
-
|
7
|
-
'servers' => [
|
8
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
9
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
|
10
|
-
]
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
5
|
+
include ClientHelpers
|
6
|
+
|
14
7
|
let(:subject) { described_class.new(File.basename($0)) }
|
15
8
|
|
16
9
|
describe '#execute' do
|
17
10
|
it 'puts master name and URL' do
|
18
|
-
allow(subject).to receive(:settings).and_return(settings)
|
19
|
-
|
20
11
|
expect {
|
21
12
|
subject.run([])
|
22
13
|
}.to output(/alias.*someurl/).to_stdout
|
23
14
|
end
|
24
15
|
|
25
16
|
it 'only outputs name if name-flag is set' do
|
26
|
-
allow(subject).to receive(:settings).and_return(settings)
|
27
|
-
|
28
17
|
expect {
|
29
18
|
subject.run(['--name'])
|
30
19
|
}.to output("alias\n").to_stdout
|
31
20
|
end
|
32
21
|
|
33
22
|
it 'does not raise error when logged in' do
|
34
|
-
allow(subject).to receive(:settings).and_return(settings)
|
35
|
-
|
36
23
|
expect {
|
37
24
|
subject.run([])
|
38
25
|
}.to_not raise_error
|
39
26
|
end
|
40
27
|
|
41
28
|
it 'raises error when not logged in' do
|
42
|
-
|
43
|
-
{
|
44
|
-
'current_server' => nil,
|
45
|
-
'servers' => [
|
46
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
47
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
|
48
|
-
]
|
49
|
-
}
|
50
|
-
)
|
29
|
+
expect(subject.config).to receive(:current_master).and_return(nil)
|
51
30
|
|
52
31
|
expect {
|
53
32
|
subject.run([])
|
@@ -3,41 +3,16 @@ require 'kontena/cli/master/use_command'
|
|
3
3
|
|
4
4
|
describe Kontena::Cli::Master::UseCommand do
|
5
5
|
|
6
|
+
include ClientHelpers
|
7
|
+
|
6
8
|
let(:subject) do
|
7
9
|
described_class.new(File.basename($0))
|
8
10
|
end
|
9
11
|
|
10
|
-
let(:client) { spy(:client) }
|
11
|
-
|
12
|
-
let(:valid_settings) do
|
13
|
-
{'current_server' => 'alias',
|
14
|
-
'servers' => [
|
15
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
16
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
|
17
|
-
]
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
12
|
describe '#use' do
|
22
13
|
it 'should update current master' do
|
23
|
-
allow(subject).to receive(:client).and_return(client)
|
24
|
-
allow(subject).to receive(:settings).and_return(valid_settings)
|
25
|
-
expect(subject).to receive(:current_master=).with('some_master')
|
26
|
-
subject.run(['some_master'])
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should fetch grid list from master' do
|
30
|
-
allow(subject).to receive(:require_token).and_return('token')
|
31
|
-
allow(subject).to receive(:client).and_return(client)
|
32
|
-
allow(subject).to receive(:settings).and_return(valid_settings)
|
33
14
|
expect(subject).to receive(:current_master=).with('some_master')
|
34
|
-
expect(client).to receive(:get).with('grids')
|
35
15
|
subject.run(['some_master'])
|
36
16
|
end
|
37
|
-
|
38
|
-
it 'should abort with error message if master is not configured' do
|
39
|
-
expect { subject.run(['not_existing']) }.to raise_error(
|
40
|
-
SystemExit, /Could not resolve master with name: not_existing/)
|
41
|
-
end
|
42
17
|
end
|
43
18
|
end
|
@@ -4,30 +4,16 @@ require 'kontena/cli/master/users/invite_command'
|
|
4
4
|
|
5
5
|
describe Kontena::Cli::Master::Users::InviteCommand do
|
6
6
|
|
7
|
+
include ClientHelpers
|
8
|
+
|
7
9
|
let(:subject) do
|
8
10
|
described_class.new(File.basename($0))
|
9
11
|
end
|
10
12
|
|
11
|
-
let(:valid_settings) do
|
12
|
-
{'current_server' => 'alias',
|
13
|
-
'servers' => [
|
14
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
15
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
|
16
|
-
]
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:client) { spy(:client) }
|
21
|
-
|
22
13
|
describe "#invite" do
|
23
|
-
before(:each) do
|
24
|
-
allow(subject).to receive(:client).and_return(client)
|
25
|
-
allow(subject).to receive(:settings).and_return(valid_settings)
|
26
|
-
end
|
27
|
-
|
28
14
|
it 'makes invitation request for all given users' do
|
29
|
-
expect(client).to receive(:post).with("
|
30
|
-
expect(client).to receive(:post).with("
|
15
|
+
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'john@example.org', response_type: "invite"}).once
|
16
|
+
expect(client).to receive(:post).with("/oauth2/authorize", {email: 'jane@example.org', response_type: "invite"}).once
|
31
17
|
|
32
18
|
subject.run(['john@example.org', 'jane@example.org'])
|
33
19
|
end
|
@@ -4,27 +4,13 @@ require 'kontena/cli/master/users/roles/add_command'
|
|
4
4
|
|
5
5
|
describe Kontena::Cli::Master::Users::Roles::AddCommand do
|
6
6
|
|
7
|
+
include ClientHelpers
|
8
|
+
|
7
9
|
let(:subject) do
|
8
10
|
described_class.new(File.basename($0))
|
9
11
|
end
|
10
12
|
|
11
|
-
let(:client) { spy(:client) }
|
12
|
-
|
13
|
-
let(:valid_settings) do
|
14
|
-
{'current_server' => 'alias',
|
15
|
-
'servers' => [
|
16
|
-
{'name' => 'some_master', 'url' => 'some_master'},
|
17
|
-
{'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
|
18
|
-
]
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
13
|
describe "#add-role" do
|
23
|
-
before(:each) do
|
24
|
-
allow(subject).to receive(:client).and_return(client)
|
25
|
-
allow(subject).to receive(:settings).and_return(valid_settings)
|
26
|
-
end
|
27
|
-
|
28
14
|
it 'makes add role request for all given users' do
|
29
15
|
expect(client).to receive(:post).with("users/john@example.org/roles", {role: 'role'}).once
|
30
16
|
expect(client).to receive(:post).with("users/jane@example.org/roles", {role: 'role'}).once
|