debox 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/debox +15 -0
- data/debox.gemspec +23 -0
- data/lib/debox.rb +9 -0
- data/lib/debox/api.rb +261 -0
- data/lib/debox/cli.rb +111 -0
- data/lib/debox/command.rb +48 -0
- data/lib/debox/command/apps.rb +14 -0
- data/lib/debox/command/auth.rb +29 -0
- data/lib/debox/command/base.rb +57 -0
- data/lib/debox/command/cap.rb +16 -0
- data/lib/debox/command/deploy.rb +18 -0
- data/lib/debox/command/key.rb +20 -0
- data/lib/debox/command/live.rb +14 -0
- data/lib/debox/command/log.rb +17 -0
- data/lib/debox/command/login.rb +18 -0
- data/lib/debox/command/logs.rb +27 -0
- data/lib/debox/command/recipes.rb +65 -0
- data/lib/debox/config.rb +59 -0
- data/lib/debox/utils.rb +77 -0
- data/lib/debox/version.rb +3 -0
- data/spec/integration/api/api_key_spec.rb +20 -0
- data/spec/integration/api/apps_spec.rb +9 -0
- data/spec/integration/api/cap/cap_spec.rb +58 -0
- data/spec/integration/api/live/log_spec.rb +12 -0
- data/spec/integration/api/logs/index_spec.rb +54 -0
- data/spec/integration/api/logs/show_spec.rb +27 -0
- data/spec/integration/api/public_key_spec.rb +15 -0
- data/spec/integration/api/recipes/create_spec.rb +10 -0
- data/spec/integration/api/recipes/destroy_spec.rb +14 -0
- data/spec/integration/api/recipes/index_spec.rb +17 -0
- data/spec/integration/api/recipes/new_spec.rb +10 -0
- data/spec/integration/api/recipes/show_spec.rb +10 -0
- data/spec/integration/api/recipes/update_spec.rb +11 -0
- data/spec/integration/api/users/create_spec.rb +8 -0
- data/spec/integration/api/users/delete_spec.rb +11 -0
- data/spec/integration/api/users/index_spec.rb +10 -0
- data/spec/integration/commands/apps_spec.rb +8 -0
- data/spec/integration/commands/cap_spec.rb +17 -0
- data/spec/integration/commands/key_spec.rb +24 -0
- data/spec/integration/commands/login_spec.rb +11 -0
- data/spec/integration/commands/logs/index_spec.rb +14 -0
- data/spec/integration/commands/logs/show_spec.rb +14 -0
- data/spec/integration/commands/recipes/delete_spec.rb +8 -0
- data/spec/integration/commands/recipes/edit_spec.rb +23 -0
- data/spec/integration/commands/recipes/index_spec.rb +8 -0
- data/spec/integration/commands/recipes/show_spec.rb +8 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/herlpers.rb +43 -0
- metadata +209 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Return api key for a given user
|
4
|
+
describe 'api_keys' do
|
5
|
+
|
6
|
+
it 'should return api key with invalid credentials' do
|
7
|
+
configure
|
8
|
+
expect {
|
9
|
+
Debox::API.api_key user: 'invalid@indeos.es', password: 'invalid'
|
10
|
+
}.to raise_error Debox::DeboxServerException, 'Access denied. Please login first.'
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return the user api key with valid credentials' do
|
15
|
+
user = create_admin
|
16
|
+
configure
|
17
|
+
response = Debox::API.api_key user: user.email, password: 'secret'
|
18
|
+
response.body.should eq user.api_key
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe 'cap' do
|
3
|
+
|
4
|
+
it 'should deal with invalid app' do
|
5
|
+
configure_admin
|
6
|
+
DeboxServer::Deployer.should_not_receive(:add_job_to_queue)
|
7
|
+
expect {
|
8
|
+
Debox::API.cap(app: 'test')
|
9
|
+
}.to raise_error Debox::DeboxServerException, '400: App not found'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should deal with invalid env' do
|
13
|
+
configure_admin
|
14
|
+
server.create_recipe('test', :production, 'invalid content')
|
15
|
+
DeboxServer::Deployer.should_not_receive(:add_job_to_queue)
|
16
|
+
expect {
|
17
|
+
Debox::API.cap(app: 'test', env: 'invalid')
|
18
|
+
}.to raise_error Debox::DeboxServerException, '400: Environment not found.'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should run a cap task gith a given app' do
|
22
|
+
configure_admin
|
23
|
+
server.create_recipe('test', :production, 'invalid content')
|
24
|
+
DeboxServer::Deployer.should_receive(:add_job_to_queue)
|
25
|
+
|
26
|
+
job = Debox::API.cap app: 'test'
|
27
|
+
job[:app].should eq 'test'
|
28
|
+
job[:env].should eq 'production'
|
29
|
+
job[:task].should eq 'deploy'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should run a cap task gith a given app and env' do
|
33
|
+
configure_admin
|
34
|
+
server.create_recipe('test', :production, 'invalid content')
|
35
|
+
server.create_recipe('test', :staging, 'invalid content')
|
36
|
+
DeboxServer::Deployer.should_receive(:add_job_to_queue)
|
37
|
+
|
38
|
+
job = Debox::API.cap app: 'test', env: 'staging'
|
39
|
+
job[:app].should eq 'test'
|
40
|
+
job[:env].should eq 'staging'
|
41
|
+
job[:task].should eq 'deploy'
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it 'should run a cap task gith a given app and env' do
|
46
|
+
configure_admin
|
47
|
+
server.create_recipe('test', :production, 'invalid content')
|
48
|
+
server.create_recipe('test', :staging, 'invalid content')
|
49
|
+
DeboxServer::Deployer.should_receive(:add_job_to_queue)
|
50
|
+
|
51
|
+
job = Debox::API.cap app: 'test', env: 'staging', task: 'node:setup'
|
52
|
+
job[:app].should eq 'test'
|
53
|
+
job[:env].should eq 'staging'
|
54
|
+
job[:task].should eq 'node:setup'
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'logs' do
|
4
|
+
# it 'should show live log' do
|
5
|
+
# server.create_recipe('test', 'production', 'content')
|
6
|
+
# configure_admin
|
7
|
+
# Debox::API.cap app: 'test'
|
8
|
+
# Debox::API.live(app: 'test') do |msg|
|
9
|
+
# puts msg
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'logs' do
|
4
|
+
it 'should return all the logs' do
|
5
|
+
time = DateTime.now
|
6
|
+
out = OpenStruct.new time: time, success: true, buffer: 'Some log content', error: 'Log result'
|
7
|
+
server.create_recipe('test', 'production', 'content')
|
8
|
+
job = stubbed_job 'test', 'production', 'deploy', out
|
9
|
+
job.save_log
|
10
|
+
|
11
|
+
configure_admin
|
12
|
+
|
13
|
+
logs = Debox::API.logs app: 'test', env: 'production'
|
14
|
+
logs.count.should eq 1
|
15
|
+
saved = logs.first
|
16
|
+
DateTime.parse(saved[:time]).to_s.should eq time.to_s
|
17
|
+
saved[:error].should eq 'Log result'
|
18
|
+
saved[:status].should eq 'success'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should set default env if not set and only one available' do
|
22
|
+
time = DateTime.now
|
23
|
+
out = OpenStruct.new time: time, success: true, buffer: 'Some log content', error: 'Log result'
|
24
|
+
server.create_recipe('test', 'production', 'content')
|
25
|
+
job = stubbed_job 'test', 'production', 'deploy', out
|
26
|
+
job.save_log
|
27
|
+
|
28
|
+
configure_admin
|
29
|
+
|
30
|
+
logs = Debox::API.logs app: 'test', env: 'production'
|
31
|
+
logs.count.should eq 1
|
32
|
+
saved = logs.first
|
33
|
+
|
34
|
+
DateTime.parse(saved[:time]).to_s.should eq time.to_s
|
35
|
+
saved[:error].should eq 'Log result'
|
36
|
+
saved[:status].should eq 'success'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should empty array withut logs' do
|
40
|
+
server.create_recipe('test', 'production', 'content')
|
41
|
+
configure_admin
|
42
|
+
logs = Debox::API.logs app: 'test', env: 'production'
|
43
|
+
logs.should be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should return invalid if app does not exists' do
|
47
|
+
configure_admin
|
48
|
+
expect {
|
49
|
+
Debox::API.logs app: 'test', env: 'production'
|
50
|
+
}.to raise_error Debox::DeboxServerException, '400: App not found'
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe 'log' do
|
3
|
+
it 'should return the log' do
|
4
|
+
out = OpenStruct.new time: DateTime.now, success: true, buffer: 'Some log content', error: 'Log result'
|
5
|
+
server.create_recipe('test', 'production', 'content')
|
6
|
+
job = stubbed_job 'test', 'production', 'deploy', out
|
7
|
+
job.save_log
|
8
|
+
|
9
|
+
configure_admin
|
10
|
+
|
11
|
+
log = Debox::API.log app: 'test', env: 'production'
|
12
|
+
log.should eq 'Some log content'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return the log without env' do
|
16
|
+
out = OpenStruct.new time: DateTime.now, success: true, buffer: 'Some log content', error: 'Log result'
|
17
|
+
server.create_recipe('test', 'production', 'content')
|
18
|
+
job = stubbed_job 'test', 'production', 'deploy', out
|
19
|
+
job.save_log
|
20
|
+
|
21
|
+
configure_admin
|
22
|
+
|
23
|
+
log = Debox::API.log app: 'test'
|
24
|
+
log.should eq 'Some log content'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'public_key' do
|
4
|
+
|
5
|
+
it 'should return the public key if generated' do
|
6
|
+
configure_admin
|
7
|
+
|
8
|
+
# Stub the rsa file
|
9
|
+
public_key_file = double 'file'
|
10
|
+
public_key_file.stub(:read).and_return 'id_rsa.pub content'
|
11
|
+
File.should_receive(:open).with(DeboxServer::SshKeys::PUBLIC_KEY).and_return public_key_file
|
12
|
+
|
13
|
+
Debox::API.public_key.should eq 'id_rsa.pub content'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes_create' do
|
4
|
+
it 'should create a config file with given content' do
|
5
|
+
configure_admin
|
6
|
+
response = Debox::API.recipes_create app: 'test', env: 'production', content: 'some content'
|
7
|
+
response.code.should eq '201'
|
8
|
+
server.recipe_content('test', 'production').should eq 'some content'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes_delete' do
|
4
|
+
|
5
|
+
|
6
|
+
it 'should destroy the recipe if exists' do
|
7
|
+
configure_admin
|
8
|
+
server.create_recipe('test', :staging, 'sample content')
|
9
|
+
server.create_recipe('test', :production, 'sample content')
|
10
|
+
response = Debox::API.recipes_destroy app: 'test', env: 'staging'
|
11
|
+
response.code.should eq '200'
|
12
|
+
server.recipes_list('test').should eq ['production']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes index' do
|
4
|
+
it 'should return an empty array without recipes' do
|
5
|
+
configure_admin
|
6
|
+
Debox::API.recipes(app: 'test').should eq []
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
it 'should return current recipes if any' do
|
11
|
+
app = 'test'
|
12
|
+
server.create_recipe(app, :staging, 'sample content')
|
13
|
+
server.create_recipe(app, :production, 'sample content')
|
14
|
+
configure_admin
|
15
|
+
Debox::API.recipes(app: 'test').should eq ['staging', 'production']
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes new' do
|
4
|
+
it 'should create a new config file with the content of the template' do
|
5
|
+
configure_admin
|
6
|
+
response = Debox::API.recipes_new app: 'test_app', env: 'production'
|
7
|
+
response.should match 'test_app'
|
8
|
+
response.should match 'PRODUCTION'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '/v1/recipes/:app/:env/show' do
|
4
|
+
it 'should return the file content' do
|
5
|
+
configure_admin
|
6
|
+
server.create_recipe('test_app', :production, 'this is the first content')
|
7
|
+
recipe = Debox::API.recipes_show app: 'test_app', env: 'production'
|
8
|
+
recipe.should eq 'this is the first content'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes update' do
|
4
|
+
it 'should return the file content' do
|
5
|
+
configure_admin
|
6
|
+
server.create_recipe('test_app', :production, 'this is the first content')
|
7
|
+
response = Debox::API.recipes_update app: 'test_app', env: 'production', content: 'updated content'
|
8
|
+
response.code.should eq '200'
|
9
|
+
server.recipe_content('test_app', 'production').should eq 'updated content'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'users_delete' do
|
4
|
+
it 'should delete a user' do
|
5
|
+
user = configure_admin
|
6
|
+
create_admin 'other@indeos.es'
|
7
|
+
response = Debox::API.users_delete user: 'other@indeos.es'
|
8
|
+
response.code.should eq '200'
|
9
|
+
server.users_list.should eq [user.email]
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'cap command' do
|
4
|
+
it 'should call API::cap and API::live' do
|
5
|
+
Debox::API.should_receive(:cap).with(app: 'test', env: 'prod', task: 'deploy').and_return '1'
|
6
|
+
Debox::API.should_receive(:live).with(app: 'test', env: 'prod', task: 'deploy')
|
7
|
+
run_command 'cap deploy test prod'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'env is optional' do
|
11
|
+
Debox::API.should_receive(:cap).with(app: 'test', task: 'deploy').and_return '1'
|
12
|
+
Debox::API.should_receive(:live).with(app: 'test', task: 'deploy')
|
13
|
+
run_command 'cap deploy test'
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'key:show' do
|
4
|
+
it 'should call API:public_key' do
|
5
|
+
Debox::API.should_receive(:public_key).and_return 'sample_public_key'
|
6
|
+
run_command 'key:show'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe 'key:copy' do
|
12
|
+
it 'should fail without host' do
|
13
|
+
Debox::API.should_not_receive(:public_key)
|
14
|
+
Object.any_instance.should_not_receive(:system)
|
15
|
+
run_command 'key:copy'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should call copy the public key' do
|
19
|
+
Debox::API.should_receive(:public_key).and_return 'sample_public_key'
|
20
|
+
Object.any_instance.should_receive(:system).
|
21
|
+
with "echo \"sample_public_key\" | ssh sample.host \"umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys\" || exit 1 "
|
22
|
+
run_command 'key:copy sample.host'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'login' do
|
4
|
+
|
5
|
+
xit 'should call API::api_key' do
|
6
|
+
Debox::API.should_receive(:api_key).and_return 'secret_key'
|
7
|
+
Debox::Config.should_receive(:save_config)
|
8
|
+
run_command 'login', host: 'sample.host'
|
9
|
+
Debox::config[:host].should eq 'sample.host'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'logs list' do
|
4
|
+
it 'should call API::logs_lists with app' do
|
5
|
+
Debox::API.should_receive(:logs).with(app: 'test') { [] }
|
6
|
+
run_command 'logs test'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should call API::logs_lists with app and env if given' do
|
10
|
+
Debox::API.should_receive(:logs).with(app: 'test', env: 'prod') { [] }
|
11
|
+
run_command 'logs test prod'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'logs' do
|
4
|
+
it 'should call API::logs' do
|
5
|
+
Debox::API.should_receive(:log).with(app: 'test', env: 'prod')
|
6
|
+
run_command 'log test prod'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should call API::logs_show' do
|
10
|
+
Debox::API.should_receive(:log).with(app: 'test', env: 'prod')
|
11
|
+
run_command 'log test prod'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'recipes edit' do
|
4
|
+
before :each do
|
5
|
+
@content = 'recipe content'
|
6
|
+
@edited_content = 'edited content'
|
7
|
+
@args = { app: 'test', env: 'prod'}
|
8
|
+
end
|
9
|
+
it 'should ignore update if the recipe does not change' do
|
10
|
+
Debox::API.should_receive(:recipes_show).with(@args).and_return @content
|
11
|
+
Debox::Command::Recipes.any_instance.should_receive(:edit_file).with(@content).and_return(@content)
|
12
|
+
Debox::API.should_not_receive :recipes_update
|
13
|
+
run_command 'recipes:edit test prod'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should update the recipe if the content change' do
|
17
|
+
Debox::API.should_receive(:recipes_show).with(@args).and_return @content
|
18
|
+
Debox::Command::Recipes.any_instance.should_receive(:edit_file).with(@content).and_return(@edited_content)
|
19
|
+
Debox::API.should_receive(:recipes_update).with(@args.merge content: @edited_content)
|
20
|
+
run_command 'recipes:edit test prod'
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|