central-cli 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dockerignore +3 -0
- data/.gitignore +15 -0
- data/.rspec +6 -0
- data/.rubocop.yml +5 -0
- data/Dockerfile +15 -0
- data/Gemfile +10 -0
- data/LICENSE +191 -0
- data/README.md +39 -0
- data/Rakefile +9 -0
- data/VERSION +1 -0
- data/bin/cm +85 -0
- data/central-cli.gemspec +35 -0
- data/central-docker.sh +6 -0
- data/lib/central/cli/app_command.rb +29 -0
- data/lib/central/cli/apps/build_command.rb +24 -0
- data/lib/central/cli/apps/central_yml_generator.rb +88 -0
- data/lib/central/cli/apps/common.rb +166 -0
- data/lib/central/cli/apps/deploy_command.rb +191 -0
- data/lib/central/cli/apps/docker_compose_generator.rb +48 -0
- data/lib/central/cli/apps/docker_helper.rb +85 -0
- data/lib/central/cli/apps/dockerfile_generator.rb +15 -0
- data/lib/central/cli/apps/init_command.rb +91 -0
- data/lib/central/cli/apps/list_command.rb +68 -0
- data/lib/central/cli/apps/logs_command.rb +76 -0
- data/lib/central/cli/apps/monitor_command.rb +93 -0
- data/lib/central/cli/apps/remove_command.rb +80 -0
- data/lib/central/cli/apps/restart_command.rb +38 -0
- data/lib/central/cli/apps/scale_command.rb +31 -0
- data/lib/central/cli/apps/show_command.rb +23 -0
- data/lib/central/cli/apps/start_command.rb +39 -0
- data/lib/central/cli/apps/stop_command.rb +39 -0
- data/lib/central/cli/auth/aws/create_command.rb +34 -0
- data/lib/central/cli/auth/aws_command.rb +7 -0
- data/lib/central/cli/auth/list_command.rb +28 -0
- data/lib/central/cli/auth_command.rb +9 -0
- data/lib/central/cli/bytes_helper.rb +38 -0
- data/lib/central/cli/common.rb +148 -0
- data/lib/central/cli/container_command.rb +10 -0
- data/lib/central/cli/containers/exec_command.rb +21 -0
- data/lib/central/cli/containers/inspect_command.rb +22 -0
- data/lib/central/cli/etcd/common.rb +7 -0
- data/lib/central/cli/etcd/get_command.rb +26 -0
- data/lib/central/cli/etcd/list_command.rb +31 -0
- data/lib/central/cli/etcd/mkdir_command.rb +21 -0
- data/lib/central/cli/etcd/remove_command.rb +25 -0
- data/lib/central/cli/etcd/set_command.rb +22 -0
- data/lib/central/cli/etcd_command.rb +16 -0
- data/lib/central/cli/external_registries/add_command.rb +21 -0
- data/lib/central/cli/external_registries/delete_command.rb +15 -0
- data/lib/central/cli/external_registries/list_command.rb +27 -0
- data/lib/central/cli/external_registries/remove_command.rb +13 -0
- data/lib/central/cli/external_registry_command.rb +14 -0
- data/lib/central/cli/login_command.rb +121 -0
- data/lib/central/cli/logout_command.rb +7 -0
- data/lib/central/cli/master/aws/create_command.rb +41 -0
- data/lib/central/cli/master/aws_command.rb +7 -0
- data/lib/central/cli/master/azure/create_command.rb +39 -0
- data/lib/central/cli/master/azure_command.rb +11 -0
- data/lib/central/cli/master/digital_ocean/create_command.rb +35 -0
- data/lib/central/cli/master/digital_ocean_command.rb +11 -0
- data/lib/central/cli/master/list_command.rb +28 -0
- data/lib/central/cli/master/use_command.rb +34 -0
- data/lib/central/cli/master/users/add_role_command.rb +26 -0
- data/lib/central/cli/master/users/invite_command.rb +24 -0
- data/lib/central/cli/master/users/list_command.rb +18 -0
- data/lib/central/cli/master/users/remove_command.rb +22 -0
- data/lib/central/cli/master/users/remove_role_command.rb +25 -0
- data/lib/central/cli/master/users_command.rb +15 -0
- data/lib/central/cli/master/vagrant/create_command.rb +25 -0
- data/lib/central/cli/master/vagrant/restart_command.rb +20 -0
- data/lib/central/cli/master/vagrant/ssh_command.rb +15 -0
- data/lib/central/cli/master/vagrant/start_command.rb +20 -0
- data/lib/central/cli/master/vagrant/stop_command.rb +20 -0
- data/lib/central/cli/master/vagrant/terminate_command.rb +13 -0
- data/lib/central/cli/master/vagrant_command.rb +21 -0
- data/lib/central/cli/master_command.rb +19 -0
- data/lib/central/cli/node_command.rb +30 -0
- data/lib/central/cli/nodes/add_label_command.rb +19 -0
- data/lib/central/cli/nodes/aws/create_command.rb +40 -0
- data/lib/central/cli/nodes/aws/restart_command.rb +29 -0
- data/lib/central/cli/nodes/aws/terminate_command.rb +21 -0
- data/lib/central/cli/nodes/aws_command.rb +14 -0
- data/lib/central/cli/nodes/azure/create_command.rb +40 -0
- data/lib/central/cli/nodes/azure/restart_command.rb +31 -0
- data/lib/central/cli/nodes/azure/terminate_command.rb +21 -0
- data/lib/central/cli/nodes/azure_command.rb +14 -0
- data/lib/central/cli/nodes/digital_ocean/create_command.rb +32 -0
- data/lib/central/cli/nodes/digital_ocean/restart_command.rb +27 -0
- data/lib/central/cli/nodes/digital_ocean/terminate_command.rb +19 -0
- data/lib/central/cli/nodes/digital_ocean_command.rb +14 -0
- data/lib/central/cli/nodes/label_command.rb +12 -0
- data/lib/central/cli/nodes/labels/add_command.rb +19 -0
- data/lib/central/cli/nodes/labels/remove_command.rb +23 -0
- data/lib/central/cli/nodes/list_command.rb +62 -0
- data/lib/central/cli/nodes/remove_command.rb +16 -0
- data/lib/central/cli/nodes/remove_label_command.rb +23 -0
- data/lib/central/cli/nodes/show_command.rb +49 -0
- data/lib/central/cli/nodes/ssh_command.rb +31 -0
- data/lib/central/cli/nodes/update_command.rb +20 -0
- data/lib/central/cli/nodes/vagrant/create_command.rb +27 -0
- data/lib/central/cli/nodes/vagrant/restart_command.rb +26 -0
- data/lib/central/cli/nodes/vagrant/ssh_command.rb +21 -0
- data/lib/central/cli/nodes/vagrant/start_command.rb +26 -0
- data/lib/central/cli/nodes/vagrant/stop_command.rb +26 -0
- data/lib/central/cli/nodes/vagrant/terminate_command.rb +17 -0
- data/lib/central/cli/nodes/vagrant_command.rb +20 -0
- data/lib/central/cli/register_command.rb +21 -0
- data/lib/central/cli/registry/create_command.rb +144 -0
- data/lib/central/cli/registry/delete_command.rb +22 -0
- data/lib/central/cli/registry/remove_command.rb +19 -0
- data/lib/central/cli/registry_command.rb +11 -0
- data/lib/central/cli/service_command.rb +49 -0
- data/lib/central/cli/services/add_env_command.rb +19 -0
- data/lib/central/cli/services/add_secret_command.rb +24 -0
- data/lib/central/cli/services/container_command.rb +8 -0
- data/lib/central/cli/services/containers_command.rb +32 -0
- data/lib/central/cli/services/create_command.rb +90 -0
- data/lib/central/cli/services/delete_command.rb +19 -0
- data/lib/central/cli/services/deploy_command.rb +21 -0
- data/lib/central/cli/services/env_command.rb +11 -0
- data/lib/central/cli/services/envs/add_command.rb +19 -0
- data/lib/central/cli/services/envs/list_command.rb +20 -0
- data/lib/central/cli/services/envs/remove_command.rb +18 -0
- data/lib/central/cli/services/envs_command.rb +20 -0
- data/lib/central/cli/services/link_command.rb +26 -0
- data/lib/central/cli/services/list_command.rb +42 -0
- data/lib/central/cli/services/logs_command.rb +57 -0
- data/lib/central/cli/services/monitor_command.rb +58 -0
- data/lib/central/cli/services/remove_command.rb +17 -0
- data/lib/central/cli/services/remove_env_command.rb +18 -0
- data/lib/central/cli/services/remove_secret_command.rb +28 -0
- data/lib/central/cli/services/restart_command.rb +17 -0
- data/lib/central/cli/services/scale_command.rb +17 -0
- data/lib/central/cli/services/secret_command.rb +9 -0
- data/lib/central/cli/services/secrets/link_command.rb +24 -0
- data/lib/central/cli/services/secrets/unlink_command.rb +28 -0
- data/lib/central/cli/services/services_helper.rb +360 -0
- data/lib/central/cli/services/show_command.rb +18 -0
- data/lib/central/cli/services/start_command.rb +17 -0
- data/lib/central/cli/services/stats_command.rb +74 -0
- data/lib/central/cli/services/stop_command.rb +17 -0
- data/lib/central/cli/services/unlink_command.rb +25 -0
- data/lib/central/cli/services/update_command.rb +78 -0
- data/lib/central/cli/stack_command.rb +32 -0
- data/lib/central/cli/stack_options.rb +11 -0
- data/lib/central/cli/stacks/add_user_command.rb +18 -0
- data/lib/central/cli/stacks/audit_log_command.rb +21 -0
- data/lib/central/cli/stacks/cloud_config_command.rb +41 -0
- data/lib/central/cli/stacks/common.rb +95 -0
- data/lib/central/cli/stacks/create_command.rb +26 -0
- data/lib/central/cli/stacks/current_command.rb +25 -0
- data/lib/central/cli/stacks/env_command.rb +32 -0
- data/lib/central/cli/stacks/list_command.rb +35 -0
- data/lib/central/cli/stacks/list_users_command.rb +26 -0
- data/lib/central/cli/stacks/logs_command.rb +81 -0
- data/lib/central/cli/stacks/remove_command.rb +26 -0
- data/lib/central/cli/stacks/remove_user_command.rb +17 -0
- data/lib/central/cli/stacks/show_command.rb +19 -0
- data/lib/central/cli/stacks/trusted_subnets/add_command.rb +16 -0
- data/lib/central/cli/stacks/trusted_subnets/list_command.rb +17 -0
- data/lib/central/cli/stacks/trusted_subnets/remove_command.rb +20 -0
- data/lib/central/cli/stacks/update_command.rb +27 -0
- data/lib/central/cli/stacks/use_command.rb +21 -0
- data/lib/central/cli/stacks/user_command.rb +11 -0
- data/lib/central/cli/stacks/users/add_command.rb +18 -0
- data/lib/central/cli/stacks/users/list_command.rb +18 -0
- data/lib/central/cli/stacks/users/remove_command.rb +17 -0
- data/lib/central/cli/user/forgot_password_command.rb +16 -0
- data/lib/central/cli/user/reset_password_command.rb +21 -0
- data/lib/central/cli/user/verify_command.rb +22 -0
- data/lib/central/cli/user_command.rb +12 -0
- data/lib/central/cli/vault/list_command.rb +25 -0
- data/lib/central/cli/vault/read_command.rb +17 -0
- data/lib/central/cli/vault/remove_command.rb +14 -0
- data/lib/central/cli/vault/update_command.rb +18 -0
- data/lib/central/cli/vault/write_command.rb +22 -0
- data/lib/central/cli/vault_command.rb +16 -0
- data/lib/central/cli/version.rb +5 -0
- data/lib/central/cli/version_command.rb +22 -0
- data/lib/central/cli/vpn/config_command.rb +25 -0
- data/lib/central/cli/vpn/create_command.rb +71 -0
- data/lib/central/cli/vpn/delete_command.rb +21 -0
- data/lib/central/cli/vpn/remove_command.rb +19 -0
- data/lib/central/cli/vpn_command.rb +13 -0
- data/lib/central/cli/whoami_command.rb +20 -0
- data/lib/central/client.rb +208 -0
- data/lib/central/errors.rb +10 -0
- data/lib/central/machine/aws.rb +14 -0
- data/lib/central/machine/aws/auth_provisioner.rb +161 -0
- data/lib/central/machine/aws/cloudinit.yml +71 -0
- data/lib/central/machine/aws/cloudinit_master.yml +118 -0
- data/lib/central/machine/aws/cloudinit_oauth.yml +76 -0
- data/lib/central/machine/aws/common.rb +31 -0
- data/lib/central/machine/aws/master_provisioner.rb +171 -0
- data/lib/central/machine/aws/node_destroyer.rb +46 -0
- data/lib/central/machine/aws/node_provisioner.rb +214 -0
- data/lib/central/machine/azure.rb +13 -0
- data/lib/central/machine/azure/cloudinit.yml +64 -0
- data/lib/central/machine/azure/cloudinit_master.yml +106 -0
- data/lib/central/machine/azure/logger.rb +26 -0
- data/lib/central/machine/azure/master_provisioner.rb +125 -0
- data/lib/central/machine/azure/node_destroyer.rb +52 -0
- data/lib/central/machine/azure/node_provisioner.rb +126 -0
- data/lib/central/machine/cert_helper.rb +39 -0
- data/lib/central/machine/cloud_config/cloudinit.yml +70 -0
- data/lib/central/machine/cloud_config/node_generator.rb +27 -0
- data/lib/central/machine/common.rb +16 -0
- data/lib/central/machine/digital_ocean.rb +13 -0
- data/lib/central/machine/digital_ocean/cloudinit.yml +64 -0
- data/lib/central/machine/digital_ocean/cloudinit_master.yml +118 -0
- data/lib/central/machine/digital_ocean/master_provisioner.rb +99 -0
- data/lib/central/machine/digital_ocean/node_destroyer.rb +40 -0
- data/lib/central/machine/digital_ocean/node_provisioner.rb +81 -0
- data/lib/central/machine/random_name.rb +39 -0
- data/lib/central/machine/vagrant.rb +12 -0
- data/lib/central/machine/vagrant/Vagrantfile.master.rb.erb +116 -0
- data/lib/central/machine/vagrant/Vagrantfile.node.rb.erb +32 -0
- data/lib/central/machine/vagrant/cloudinit.yml +73 -0
- data/lib/central/machine/vagrant/master_destroyer.rb +34 -0
- data/lib/central/machine/vagrant/master_provisioner.rb +79 -0
- data/lib/central/machine/vagrant/node_destroyer.rb +38 -0
- data/lib/central/machine/vagrant/node_provisioner.rb +68 -0
- data/lib/central/scripts/completer +157 -0
- data/lib/central/scripts/init +11 -0
- data/spec/central/cli/app/common_spec.rb +150 -0
- data/spec/central/cli/app/deploy_command_spec.rb +598 -0
- data/spec/central/cli/app/docker_helper_spec.rb +102 -0
- data/spec/central/cli/app/scale_spec.rb +49 -0
- data/spec/central/cli/common_spec.rb +117 -0
- data/spec/central/cli/login_command_spec.rb +31 -0
- data/spec/central/cli/master/current_command_spec.rb +55 -0
- data/spec/central/cli/master/use_command_spec.rb +37 -0
- data/spec/central/cli/master/users/invite_command_spec.rb +34 -0
- data/spec/central/cli/master/users/remove_command_spec.rb +26 -0
- data/spec/central/cli/master/users/roles/add_command_spec.rb +34 -0
- data/spec/central/cli/master/users/roles/remove_command_spec.rb +34 -0
- data/spec/central/cli/register_command_spec.rb +56 -0
- data/spec/central/cli/services/containers_command_spec.rb +40 -0
- data/spec/central/cli/services/link_command_spec.rb +38 -0
- data/spec/central/cli/services/restart_command_spec.rb +27 -0
- data/spec/central/cli/services/secrets/link_command_spec.rb +59 -0
- data/spec/central/cli/services/secrets/unlink_command_spec.rb +48 -0
- data/spec/central/cli/services/services_helper_spec.rb +170 -0
- data/spec/central/cli/services/unlink_command_spec.rb +38 -0
- data/spec/central/cli/stacks/trusted_subnets/add_command_spec.rb +37 -0
- data/spec/central/cli/stacks/trusted_subnets/list_command_spec.rb +30 -0
- data/spec/central/cli/stacks/trusted_subnets/remove_command_spec.rb +37 -0
- data/spec/central/cli/version_command_spec.rb +16 -0
- data/spec/fixtures/central.yml +17 -0
- data/spec/fixtures/docker-compose.yml +8 -0
- data/spec/fixtures/mysql.yml +3 -0
- data/spec/fixtures/wordpress-scaled.yml +3 -0
- data/spec/fixtures/wordpress.yml +2 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/client_helpers.rb +30 -0
- data/spec/support/fixtures_helpers.rb +7 -0
- data/tasks/rspec.rake +5 -0
- metadata +463 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../../../../spec_helper'
|
2
|
+
require 'central/cli/master/users_command'
|
3
|
+
require 'central/cli/master/users/roles/add_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Master::Users::Roles::AddCommand do
|
6
|
+
let(:subject) do
|
7
|
+
described_class.new(File.basename($PROGRAM_NAME))
|
8
|
+
end
|
9
|
+
|
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
|
+
describe '#add-role' do
|
22
|
+
before(:each) do
|
23
|
+
allow(subject).to receive(:client).and_return(client)
|
24
|
+
allow(subject).to receive(:settings).and_return(valid_settings)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'makes add role request for all given users' do
|
28
|
+
expect(client).to receive(:post).with('users/john@example.org/roles', role: 'role').once
|
29
|
+
expect(client).to receive(:post).with('users/jane@example.org/roles', role: 'role').once
|
30
|
+
|
31
|
+
subject.run(['role', 'john@example.org', 'jane@example.org'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../../../../spec_helper'
|
2
|
+
require 'central/cli/master/users_command'
|
3
|
+
require 'central/cli/master/users/roles/remove_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Master::Users::Roles::RemoveCommand do
|
6
|
+
let(:subject) do
|
7
|
+
described_class.new(File.basename($PROGRAM_NAME))
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:valid_settings) do
|
11
|
+
{ 'current_server' => 'alias',
|
12
|
+
'servers' => [
|
13
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
14
|
+
{ 'name' => 'alias', 'url' => 'someurl', 'token' => '123456' }
|
15
|
+
]
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:client) { spy(:client) }
|
20
|
+
|
21
|
+
describe '#remove-role' do
|
22
|
+
before(:each) do
|
23
|
+
allow(subject).to receive(:client).and_return(client)
|
24
|
+
allow(subject).to receive(:settings).and_return(valid_settings)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'makes remove role request for all given users' do
|
28
|
+
expect(client).to receive(:delete).with('users/john@example.org/roles/role').once
|
29
|
+
expect(client).to receive(:delete).with('users/jane@example.org/roles/role').once
|
30
|
+
|
31
|
+
subject.run(['role', 'john@example.org', 'jane@example.org'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'central/cli/register_command'
|
3
|
+
|
4
|
+
describe Central::Cli::RegisterCommand do
|
5
|
+
describe '#register' do
|
6
|
+
let(:auth_client) do
|
7
|
+
double(Central::Client)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:subject) { described_class.new(File.basename($PROGRAM_NAME)) }
|
11
|
+
|
12
|
+
it 'asks password twice' do
|
13
|
+
allow(subject).to receive(:ask).with('Email: ').once.and_return('john.doe@acme.io')
|
14
|
+
expect(subject).to receive(:ask).with('Password: ').once.and_return('secret')
|
15
|
+
expect(subject).to receive(:ask).with('Password again: ').once.and_return('secret')
|
16
|
+
allow(Central::Client).to receive(:new).and_return(auth_client)
|
17
|
+
allow(auth_client).to receive(:post)
|
18
|
+
subject.run([])
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'validates given passwords' do
|
22
|
+
allow(subject).to receive(:ask).with('Email: ').once.and_return('john.doe@acme.io')
|
23
|
+
expect(subject).to receive(:ask).with('Password: ').once.and_return('secret')
|
24
|
+
expect(subject).to receive(:ask).with('Password again: ').once.and_return('secret2')
|
25
|
+
expect { subject.run([]) }.to raise_error(SystemExit)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'uses https://auth.bluebeluga.io as default auth provider' do
|
29
|
+
allow(subject).to receive(:ask).and_return('john.doe@acme.io')
|
30
|
+
allow(subject).to receive(:ask).with('Email: ').once.and_return('john.doe@acme.io')
|
31
|
+
expect(subject).to receive(:ask).with('Password: ').once.and_return('secret')
|
32
|
+
expect(subject).to receive(:ask).with('Password again: ').once.and_return('secret')
|
33
|
+
expect(Central::Client).to receive(:new).with('https://auth.bluebeluga.io').and_return(auth_client)
|
34
|
+
allow(auth_client).to receive(:post)
|
35
|
+
subject.run([])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'uses given auth provider' do
|
39
|
+
allow(subject).to receive(:ask).with('Email: ').once.and_return('john.doe@acme.io')
|
40
|
+
expect(subject).to receive(:ask).with('Password: ').once.and_return('secret')
|
41
|
+
expect(subject).to receive(:ask).with('Password again: ').once.and_return('secret')
|
42
|
+
expect(Central::Client).to receive(:new).with('http://custom.auth-provider.io').and_return(auth_client)
|
43
|
+
allow(auth_client).to receive(:post)
|
44
|
+
subject.run(['--auth-provider-url', 'http://custom.auth-provider.io'])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sends register request to auth provider' do
|
48
|
+
allow(subject).to receive(:ask).with('Email: ').once.and_return('john.doe@acme.io')
|
49
|
+
expect(subject).to receive(:ask).with('Password: ').once.and_return('secret')
|
50
|
+
expect(subject).to receive(:ask).with('Password again: ').once.and_return('secret')
|
51
|
+
allow(Central::Client).to receive(:new).with('https://auth.bluebeluga.io').and_return(auth_client)
|
52
|
+
expect(auth_client).to receive(:post).with('users', email: 'john.doe@acme.io', password: 'secret')
|
53
|
+
subject.run([])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/services/containers_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Services::ContainersCommand do
|
5
|
+
include ClientHelpers
|
6
|
+
|
7
|
+
describe '#execute' do
|
8
|
+
before(:each) do
|
9
|
+
allow(client).to receive(:get).and_return('containers' => [])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'requires api url' do
|
13
|
+
expect(subject).to receive(:require_api_url).once
|
14
|
+
subject.run(['service-a'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'requires token' do
|
18
|
+
expect(subject).to receive(:require_token).and_return(token)
|
19
|
+
subject.run(['service-a'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'to not throw on missing "overlay_cidr" property' do
|
23
|
+
allow(client).to receive(:get).and_return('containers' => [
|
24
|
+
{ 'id' => 'service-a-id', 'node' => { 'public_ip' => '' } }
|
25
|
+
])
|
26
|
+
expect do
|
27
|
+
subject.run(['service-a'])
|
28
|
+
end.to_not raise_error(NoMethodError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'to not throw on nil "overlay_cidr" property' do
|
32
|
+
allow(client).to receive(:get).and_return('containers' => [
|
33
|
+
{ 'id' => 'service-a-id', 'node' => { 'public_ip' => '' }, 'overlay_cidr' => nil }
|
34
|
+
])
|
35
|
+
expect do
|
36
|
+
subject.run(['service-a'])
|
37
|
+
end.to_not raise_error(NoMethodError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/services/link_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Services::LinkCommand do
|
5
|
+
include ClientHelpers
|
6
|
+
|
7
|
+
describe '#execute' do
|
8
|
+
before(:each) do
|
9
|
+
allow(client).to receive(:get).and_return('links' => [])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'requires api url' do
|
13
|
+
expect(subject).to receive(:require_api_url).once
|
14
|
+
subject.run(['service-a', 'service-b'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'requires token' do
|
18
|
+
expect(subject).to receive(:require_token).and_return(token)
|
19
|
+
subject.run(['service-a', 'service-b'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'aborts if service is already linked' do
|
23
|
+
allow(client).to receive(:get).and_return('links' => [
|
24
|
+
{ 'alias' => 'service-b', 'stack_service_id' => 'stack/service-b' }
|
25
|
+
])
|
26
|
+
expect do
|
27
|
+
subject.run(['service-a', 'service-b'])
|
28
|
+
end.to raise_error(SystemExit)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sends link to master' do
|
32
|
+
expect(client).to receive(:put).with(
|
33
|
+
'services/test-stack/service-a', links: [{ name: 'service-b', alias: 'service-b' }]
|
34
|
+
)
|
35
|
+
subject.run(['service-a', 'service-b'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/services/restart_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Services::RestartCommand do
|
5
|
+
include ClientHelpers
|
6
|
+
|
7
|
+
describe '#execute' do
|
8
|
+
before(:each) do
|
9
|
+
allow(subject).to receive(:restart_service).and_return({})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'requires api url' do
|
13
|
+
expect(subject).to receive(:require_api_url).once
|
14
|
+
subject.run(['service'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'requires token' do
|
18
|
+
expect(subject).to receive(:require_token).once
|
19
|
+
subject.run(['service'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'triggers restart command' do
|
23
|
+
expect(subject).to receive(:restart_service).with(token, 'service')
|
24
|
+
subject.run(['service'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../../../../spec_helper'
|
2
|
+
require 'central/cli/stack_options'
|
3
|
+
require 'central/cli/services/secrets/link_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Services::Secrets::LinkCommand do
|
6
|
+
include ClientHelpers
|
7
|
+
|
8
|
+
describe '#execute' do
|
9
|
+
it 'requires api url' do
|
10
|
+
expect(subject).to receive(:require_api_url).once
|
11
|
+
subject.run(['service', 'secret:name:env'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'requires token' do
|
15
|
+
expect(subject).to receive(:require_token).and_return(token)
|
16
|
+
subject.run(['service', 'secret:name:env'])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'requires service as param' do
|
20
|
+
expect do
|
21
|
+
subject.run([])
|
22
|
+
end.to raise_error(Clamp::UsageError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'requires secret as param' do
|
26
|
+
expect do
|
27
|
+
subject.run(['service'])
|
28
|
+
end.to raise_error(Clamp::UsageError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sends secrets to master' do
|
32
|
+
data = {
|
33
|
+
secrets: [
|
34
|
+
{ secret: 'MY_PASSWORD', name: 'PASSWORD', type: 'env' }
|
35
|
+
]
|
36
|
+
}
|
37
|
+
allow(client).to receive(:get).with('services/test-stack/foo').and_return('secrets' => [])
|
38
|
+
expect(client).to receive(:put).with('services/test-stack/foo', data)
|
39
|
+
subject.run(['foo', 'MY_PASSWORD:PASSWORD:env'])
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'appends secret to existing list' do
|
43
|
+
original = {
|
44
|
+
'secrets' => [
|
45
|
+
{ 'secret' => 'FOO', 'name' => 'BAR', 'type' => 'env' }
|
46
|
+
]
|
47
|
+
}
|
48
|
+
data = {
|
49
|
+
secrets: [
|
50
|
+
{ 'secret' => 'FOO', 'name' => 'BAR', 'type' => 'env' },
|
51
|
+
{ secret: 'MY_PASSWORD', name: 'PASSWORD', type: 'env' }
|
52
|
+
]
|
53
|
+
}
|
54
|
+
allow(client).to receive(:get).with('services/test-stack/foo').and_return(original)
|
55
|
+
expect(client).to receive(:put).with('services/test-stack/foo', data)
|
56
|
+
subject.run(['foo', 'MY_PASSWORD:PASSWORD:env'])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../../../../spec_helper'
|
2
|
+
require 'central/cli/stack_options'
|
3
|
+
require 'central/cli/services/secrets/unlink_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Services::Secrets::UnlinkCommand do
|
6
|
+
include ClientHelpers
|
7
|
+
|
8
|
+
describe '#execute' do
|
9
|
+
it 'requires api url' do
|
10
|
+
expect(subject).to receive(:require_api_url).once
|
11
|
+
subject.run(['service', 'secret:name:env'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'requires token' do
|
15
|
+
expect(subject).to receive(:require_token).and_return(token)
|
16
|
+
subject.run(['service', 'secret:name:env'])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'requires service as param' do
|
20
|
+
expect do
|
21
|
+
subject.run([])
|
22
|
+
end.to raise_error(Clamp::UsageError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'requires secret as param' do
|
26
|
+
expect do
|
27
|
+
subject.run(['service'])
|
28
|
+
end.to raise_error(Clamp::UsageError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'removes secret to existing list' do
|
32
|
+
original = {
|
33
|
+
'secrets' => [
|
34
|
+
{ 'secret' => 'FOO', 'name' => 'BAR', 'type' => 'env' },
|
35
|
+
{ 'secret' => 'BAR', 'name' => 'BAZ', 'type' => 'env' }
|
36
|
+
]
|
37
|
+
}
|
38
|
+
data = {
|
39
|
+
secrets: [
|
40
|
+
{ 'secret' => 'BAR', 'name' => 'BAZ', 'type' => 'env' }
|
41
|
+
]
|
42
|
+
}
|
43
|
+
allow(client).to receive(:get).with('services/test-stack/mymy').and_return(original)
|
44
|
+
expect(client).to receive(:put).with('services/test-stack/mymy', data)
|
45
|
+
subject.run(['mymy', 'FOO:BAR:env'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/services/services_helper'
|
3
|
+
|
4
|
+
module Central::Cli::Services
|
5
|
+
describe ServicesHelper do
|
6
|
+
subject { klass.new }
|
7
|
+
|
8
|
+
let(:klass) { Class.new { include ServicesHelper } }
|
9
|
+
|
10
|
+
let(:client) do
|
11
|
+
double
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:token) do
|
15
|
+
'token'
|
16
|
+
end
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
allow(subject).to receive(:client).with(token).and_return(client)
|
20
|
+
allow(subject).to receive(:current_stack).and_return('test-stack')
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#create_service' do
|
24
|
+
it 'creates POST stacks/:stack/:name/services request to Central Server' do
|
25
|
+
expect(client).to receive(:post).with('stacks/test-stack/services', 'name' => 'test-service')
|
26
|
+
subject.create_service(token, 'test-stack', 'name' => 'test-service')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#update_service' do
|
31
|
+
it 'creates PUT services/:id request to Central Server' do
|
32
|
+
expect(client).to receive(:put).with('services/test-stack/1', 'name' => 'test-service')
|
33
|
+
subject.update_service(token, '1', 'name' => 'test-service')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#get_service' do
|
38
|
+
it 'creates GET services/:id request to Central Server' do
|
39
|
+
expect(client).to receive(:get).with('services/test-stack/test-service')
|
40
|
+
subject.get_service(token, 'test-service')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#stop_service' do
|
45
|
+
it 'creates POST services/:id/stop request to Central Server' do
|
46
|
+
expect(client).to receive(:post).with('services/test-stack/test-service/stop', {})
|
47
|
+
subject.stop_service(token, 'test-service')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#start_service' do
|
52
|
+
it 'creates POST services/:id/start request to Central Server' do
|
53
|
+
expect(client).to receive(:post).with('services/test-stack/test-service/start', {})
|
54
|
+
subject.start_service(token, 'test-service')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#restart_service' do
|
59
|
+
it 'creates POST services/:id/restart request to Central Server' do
|
60
|
+
expect(client).to receive(:post).with('services/test-stack/test-service/restart', {})
|
61
|
+
subject.restart_service(token, 'test-service')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#deploy_service' do
|
66
|
+
it 'creates POST services/:id/deploy request to Central Server' do
|
67
|
+
allow(client).to receive(:get).with('services/test-stack/1').and_return('state' => 'running')
|
68
|
+
expect(client).to receive(:post).with('services/test-stack/1/deploy', 'strategy' => 'ha')
|
69
|
+
subject.deploy_service(token, '1', 'strategy' => 'ha')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#parse_ports' do
|
74
|
+
it 'raises error if node_port is missing' do
|
75
|
+
expect do
|
76
|
+
subject.parse_ports(['80'])
|
77
|
+
end.to raise_error(ArgumentError)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'raises error if container_port is missing' do
|
81
|
+
expect do
|
82
|
+
subject.parse_ports(['80:'])
|
83
|
+
end.to raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns hash of port options' do
|
87
|
+
valid_result = [{
|
88
|
+
container_port: '80',
|
89
|
+
node_port: '80',
|
90
|
+
protocol: 'tcp'
|
91
|
+
}]
|
92
|
+
port_options = subject.parse_ports(['80:80'])
|
93
|
+
expect(port_options).to eq(valid_result)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#parse_links' do
|
98
|
+
it 'raises error if service name is missing' do
|
99
|
+
expect do
|
100
|
+
subject.parse_links([''])
|
101
|
+
end.to raise_error(ArgumentError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns hash of link options' do
|
105
|
+
valid_result = [{
|
106
|
+
name: 'db',
|
107
|
+
alias: 'mysql'
|
108
|
+
}]
|
109
|
+
link_options = subject.parse_links(['db:mysql'])
|
110
|
+
expect(link_options).to eq(valid_result)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#parse_service_id' do
|
115
|
+
it 'adds current_stack if service_id is missing prefix' do
|
116
|
+
expect(subject.parse_service_id('mysql')).to eq('test-stack/mysql')
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'does not add current_stack if service id includes prefix' do
|
120
|
+
expect(subject.parse_service_id('second-stack/mysql')).to eq('second-stack/mysql')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#parse_image' do
|
125
|
+
it 'adds :default tag if no tag exist' do
|
126
|
+
expect(subject.parse_image('nginx')).to eq('nginx:latest')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'does not touch image name if tag is set' do
|
130
|
+
expect(subject.parse_image('redis:3.0')).to eq('redis:3.0')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#parse_memory' do
|
135
|
+
it 'parses kilobytes' do
|
136
|
+
expect(subject.parse_memory('1024k')).to eq(1 * 1024 * 1024)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'parses megabytes' do
|
140
|
+
expect(subject.parse_memory('32m')).to eq(32 * 1024 * 1024)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'parses gigabytes' do
|
144
|
+
expect(subject.parse_memory('2g')).to eq(2 * 1024 * 1024 * 1024)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'parses plain bytes' do
|
148
|
+
expect(subject.parse_memory((12 * 1024 * 1024).to_s)).to eq(12 * 1024 * 1024)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#parse_relative_time' do
|
153
|
+
it 'parses minutes' do
|
154
|
+
expect(subject.parse_relative_time('60min')).to eq(60 * 60)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'parses hours' do
|
158
|
+
expect(subject.parse_relative_time('8h')).to eq(8 * 60 * 60)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'parses days' do
|
162
|
+
expect(subject.parse_relative_time('7d')).to eq(7 * 24 * 60 * 60)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'parses seconds by default' do
|
166
|
+
expect(subject.parse_relative_time('600')).to eq(600)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|