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,102 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/apps/docker_helper'
|
3
|
+
|
4
|
+
describe Central::Cli::Apps::DockerHelper do
|
5
|
+
let(:subject) do
|
6
|
+
Class.new { include Central::Cli::Apps::DockerHelper }.new
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:services_with_valid_hooks) do
|
10
|
+
{
|
11
|
+
'test_service' => {
|
12
|
+
'build' => '.',
|
13
|
+
'image' => 'test_service',
|
14
|
+
'hooks' => {
|
15
|
+
'pre_build' => [
|
16
|
+
{ 'cmd' => 'echo PREBUILD1', 'name' => 'hook1' },
|
17
|
+
{ 'cmd' => 'echo PREBUILD2', 'name' => 'hook2' }
|
18
|
+
]
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:services_with_invalid_hook) do
|
25
|
+
{
|
26
|
+
'test_service' => {
|
27
|
+
'build' => '.',
|
28
|
+
'image' => 'test_service',
|
29
|
+
'hooks' => {
|
30
|
+
'pre_build' => [
|
31
|
+
{ 'cmd' => 'echo PREBUILD1', 'name' => 'hook1' },
|
32
|
+
{ 'cmd' => 'some_non_existing_command', 'name' => 'failing hook' }
|
33
|
+
]
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:services_with_no_hook) do
|
40
|
+
{
|
41
|
+
'test_service' => {
|
42
|
+
'build' => '.',
|
43
|
+
'image' => 'test_service'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#validate_image_name' do
|
49
|
+
context 'when image name is valid' do
|
50
|
+
it 'returns true' do
|
51
|
+
expect(subject.validate_image_name('registry.central.local/image-name:latest')).to be_truthy
|
52
|
+
expect(subject.validate_image_name('my-registry.com/organization/image_name:latest')).to be_truthy
|
53
|
+
expect(subject.validate_image_name('my-registry.com:5000/organization/image_name:latest')).to be_truthy
|
54
|
+
expect(subject.validate_image_name('mysql:5.1')).to be_truthy
|
55
|
+
expect(subject.validate_image_name('wordpress')).to be_truthy
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#validate_image_name' do
|
61
|
+
context 'when image name is invalid' do
|
62
|
+
it 'returns false' do
|
63
|
+
expect(subject.validate_image_name('registry.central.local/image-name:')).to be_falsey
|
64
|
+
expect(subject.validate_image_name('mysql 5.1')).to be_falsey
|
65
|
+
expect(subject.validate_image_name('*.mydomain.com/mysql')).to be_falsey
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#run_pre_build_hook' do
|
71
|
+
context 'when hook defined' do
|
72
|
+
it 'runs the hook' do
|
73
|
+
allow(subject).to receive(:build_docker_image)
|
74
|
+
allow(subject).to receive(:push_docker_image)
|
75
|
+
expect(subject).to receive(:system).with('echo PREBUILD1'). and_return(true)
|
76
|
+
expect(subject).to receive(:system).with('echo PREBUILD2'). and_return(true)
|
77
|
+
|
78
|
+
subject.process_docker_images(services_with_valid_hooks)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'fails to run the hook' do
|
82
|
+
allow(subject).to receive(:build_docker_image)
|
83
|
+
allow(subject).to receive(:push_docker_image)
|
84
|
+
expect(subject).to receive(:system).with('echo PREBUILD1'). and_return(true)
|
85
|
+
expect(subject).to receive(:system).with('some_non_existing_command'). and_return(false)
|
86
|
+
|
87
|
+
expect do
|
88
|
+
subject.process_docker_images(services_with_invalid_hook)
|
89
|
+
end.to raise_error(SystemExit)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
context 'when no hook defined' do
|
93
|
+
it 'runs no hooks' do
|
94
|
+
allow(subject).to receive(:build_docker_image)
|
95
|
+
allow(subject).to receive(:push_docker_image)
|
96
|
+
expect(subject).not_to receive(:run_pre_build_hook)
|
97
|
+
|
98
|
+
subject.process_docker_images(services_with_no_hook)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/apps/scale_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Apps::ScaleCommand do
|
5
|
+
include FixturesHelpers
|
6
|
+
include ClientHelpers
|
7
|
+
|
8
|
+
let(:subject) do
|
9
|
+
described_class.new(File.basename($PROGRAM_NAME))
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:central_yml) do
|
13
|
+
fixture('wordpress-scaled.yml')
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:central_yml_no_instances) do
|
17
|
+
fixture('wordpress.yml')
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#execute' do
|
21
|
+
before(:each) do
|
22
|
+
allow(subject).to receive(:current_dir).and_return('central-test')
|
23
|
+
allow(File).to receive(:exists?).and_return(true)
|
24
|
+
allow(File).to receive(:read).with("#{Dir.getwd}/central.yml").and_return(central_yml)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when service already contains instances property' do
|
28
|
+
it 'aborts execution' do
|
29
|
+
expect do
|
30
|
+
subject.run(['wordpress', 3])
|
31
|
+
end.to raise_error(SystemExit)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when service not found in YML' do
|
36
|
+
it 'aborts execution' do
|
37
|
+
expect do
|
38
|
+
subject.run(['mysql', 3])
|
39
|
+
end.to raise_error(SystemExit)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'scales given service' do
|
44
|
+
allow(File).to receive(:read).with("#{Dir.getwd}/central.yml").and_return(central_yml_no_instances)
|
45
|
+
expect(subject).to receive(:scale_service).with('1234567', 'central-test-wordpress', 3)
|
46
|
+
subject.run(['wordpress', 3])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'central/cli/common'
|
3
|
+
|
4
|
+
describe Central::Cli::Common do
|
5
|
+
let(:masters) do
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:subject) do
|
9
|
+
Class.new do
|
10
|
+
include Central::Cli::Common
|
11
|
+
end.new
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
allow(subject).to receive(:settings).and_return('current_server' => 'default',
|
16
|
+
'servers' => [{}])
|
17
|
+
allow(subject).to receive(:save_settings)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#current_stack' do
|
21
|
+
it 'returns nil by default' do
|
22
|
+
allow(subject).to receive(:settings).and_return('current_server' => 'alias',
|
23
|
+
'servers' => [
|
24
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
25
|
+
{ 'name' => 'alias', 'url' => 'someurl' }
|
26
|
+
])
|
27
|
+
expect(subject.current_stack).to eq(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns stack from env' do
|
31
|
+
expect(ENV).to receive(:[]).with('CENTRAL_STACK').and_return('foo')
|
32
|
+
expect(subject.current_stack).to eq('foo')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns stack from json' do
|
36
|
+
allow(subject).to receive(:settings).and_return('current_server' => 'alias',
|
37
|
+
'servers' => [
|
38
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
39
|
+
{ 'name' => 'alias', 'url' => 'someurl', 'stack' => 'foo_stack' }
|
40
|
+
])
|
41
|
+
expect(subject.current_stack).to eq('foo_stack')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns nil if settings are not present' do
|
45
|
+
allow(subject).to receive(:current_master).and_raise(ArgumentError)
|
46
|
+
expect(subject.current_stack).to be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#api_url' do
|
51
|
+
it 'raises error by default' do
|
52
|
+
expect do
|
53
|
+
subject.api_url
|
54
|
+
end.to raise_error(ArgumentError)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'return url from env' do
|
58
|
+
expect(ENV).to receive(:[]).with('CENTRAL_URL').and_return('https://domain.com')
|
59
|
+
expect(subject.api_url).to eq('https://domain.com')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#require_token' do
|
64
|
+
it 'raises error by default' do
|
65
|
+
expect do
|
66
|
+
subject.require_token
|
67
|
+
end.to raise_error(ArgumentError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'return token from env' do
|
71
|
+
expect(ENV).to receive(:[]).with('CENTRAL_TOKEN').and_return('secret_token')
|
72
|
+
expect(subject.require_token).to eq('secret_token')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#current_master' do
|
77
|
+
it 'return correct master info' do
|
78
|
+
allow(subject).to receive(:settings).and_return('current_server' => 'alias',
|
79
|
+
'servers' => [
|
80
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
81
|
+
{ 'name' => 'alias', 'url' => 'someurl' }
|
82
|
+
])
|
83
|
+
|
84
|
+
expect(subject.current_master['url']).to eq('someurl')
|
85
|
+
expect(subject.current_master['name']).to eq('alias')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#settings' do
|
90
|
+
it 'migrates old settings' do
|
91
|
+
RSpec::Mocks.space.proxy_for(subject).reset
|
92
|
+
|
93
|
+
allow(File).to receive(:exists?).and_return(true)
|
94
|
+
allow(File).to receive(:read).and_return('{
|
95
|
+
"server": {
|
96
|
+
"url": "https://master.domain.com:8443",
|
97
|
+
"stack": "my-stack",
|
98
|
+
"token": "central-token"
|
99
|
+
}
|
100
|
+
}')
|
101
|
+
expected_settings = {
|
102
|
+
'current_server' => 'default',
|
103
|
+
'servers' => [
|
104
|
+
{
|
105
|
+
'url' => 'https://master.domain.com:8443',
|
106
|
+
'stack' => 'my-stack',
|
107
|
+
'token' => 'central-token',
|
108
|
+
'name' => 'default'
|
109
|
+
}
|
110
|
+
]
|
111
|
+
}
|
112
|
+
expect(File).to receive(:write).with(subject.settings_filename, JSON.pretty_generate(expected_settings))
|
113
|
+
|
114
|
+
subject.settings
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
require 'central/cli/login_command'
|
3
|
+
|
4
|
+
describe Central::Cli::LoginCommand do
|
5
|
+
describe '#register' do
|
6
|
+
let(:settings) do
|
7
|
+
{ 'current_server' => 'alias',
|
8
|
+
'servers' => [
|
9
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
10
|
+
{ 'name' => 'alias', 'url' => 'someurl', 'token' => '123456' }
|
11
|
+
]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:auth_client) do
|
16
|
+
double(Central::Client)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:subject) { described_class.new(File.basename($PROGRAM_NAME)) }
|
20
|
+
|
21
|
+
it 'asks email and password' do
|
22
|
+
allow(subject).to receive(:settings).and_return(settings)
|
23
|
+
expect(subject).to receive(:ask).once.with('Email: ').and_return('john.doe@acme.io')
|
24
|
+
allow(subject).to receive(:ask).once.with('Password: ').and_return('secret')
|
25
|
+
allow(Central::Client).to receive(:new).and_return(auth_client)
|
26
|
+
allow(auth_client).to receive(:post)
|
27
|
+
allow(subject).to receive(:request_server_info).and_return(true)
|
28
|
+
subject.run(['http://localhost:8443'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/master/current_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Master::CurrentCommand do
|
5
|
+
let(:settings) do
|
6
|
+
{ 'current_server' => 'alias',
|
7
|
+
'servers' => [
|
8
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
9
|
+
{ 'name' => 'alias', 'url' => 'someurl', 'token' => '123456' }
|
10
|
+
]
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:subject) { described_class.new(File.basename($PROGRAM_NAME)) }
|
15
|
+
|
16
|
+
describe '#execute' do
|
17
|
+
it 'puts master name and URL' do
|
18
|
+
allow(subject).to receive(:settings).and_return(settings)
|
19
|
+
|
20
|
+
expect do
|
21
|
+
subject.run([])
|
22
|
+
end.to output(/alias.*someurl/).to_stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'only outputs name if name-flag is set' do
|
26
|
+
allow(subject).to receive(:settings).and_return(settings)
|
27
|
+
|
28
|
+
expect do
|
29
|
+
subject.run(['--name'])
|
30
|
+
end.to output("alias\n").to_stdout
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not raise error when logged in' do
|
34
|
+
allow(subject).to receive(:settings).and_return(settings)
|
35
|
+
|
36
|
+
expect do
|
37
|
+
subject.run([])
|
38
|
+
end.to_not raise_error
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'raises error when not logged in' do
|
42
|
+
allow(subject).to receive(:settings).and_return(
|
43
|
+
'current_server' => nil,
|
44
|
+
'servers' => [
|
45
|
+
{ 'name' => 'some_master', 'url' => 'some_master' },
|
46
|
+
{ 'name' => 'alias', 'url' => 'someurl', 'token' => '123456' }
|
47
|
+
]
|
48
|
+
)
|
49
|
+
|
50
|
+
expect do
|
51
|
+
subject.run([])
|
52
|
+
end.to raise_error(ArgumentError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'central/cli/master/use_command'
|
3
|
+
|
4
|
+
describe Central::Cli::Master::UseCommand do
|
5
|
+
let(:subject) do
|
6
|
+
described_class.new(File.basename($PROGRAM_NAME))
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:client) { spy(:client) }
|
10
|
+
|
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
|
+
describe '#use' do
|
21
|
+
it 'should update current master' do
|
22
|
+
allow(subject).to receive(:client).and_return(client)
|
23
|
+
allow(subject).to receive(:settings).and_return(valid_settings)
|
24
|
+
expect(subject).to receive(:current_master=).with('some_master')
|
25
|
+
subject.run(['some_master'])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should fetch stack list from master' do
|
29
|
+
allow(subject).to receive(:require_token).and_return('token')
|
30
|
+
allow(subject).to receive(:client).and_return(client)
|
31
|
+
allow(subject).to receive(:settings).and_return(valid_settings)
|
32
|
+
expect(subject).to receive(:current_master=).with('some_master')
|
33
|
+
expect(client).to receive(:get).with('stacks')
|
34
|
+
subject.run(['some_master'])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../../../../spec_helper'
|
2
|
+
require 'central/cli/master/users_command'
|
3
|
+
require 'central/cli/master/users/invite_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Master::Users::InviteCommand 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 '#invite' 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 invitation request for all given users' do
|
28
|
+
expect(client).to receive(:post).with('users', email: 'john@example.org').once
|
29
|
+
expect(client).to receive(:post).with('users', email: 'jane@example.org').once
|
30
|
+
|
31
|
+
subject.run(['john@example.org', 'jane@example.org'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../../../../spec_helper'
|
2
|
+
require 'central/cli/master/users_command'
|
3
|
+
require 'central/cli/master/users/remove_command'
|
4
|
+
|
5
|
+
describe Central::Cli::Master::Users::RemoveCommand 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(['john@domain.com'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'requires token' do
|
15
|
+
expect(subject).to receive(:require_token).and_return(token)
|
16
|
+
subject.run(['john@domain.com'])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sends email to master' do
|
20
|
+
expect(client).to receive(:delete).with(
|
21
|
+
'users/john@domain.com'
|
22
|
+
)
|
23
|
+
subject.run(['john@domain.com'])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|