shelly 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shelly/app.rb CHANGED
@@ -62,6 +62,14 @@ module Shelly
62
62
  shelly.application_logs(self.code_name)
63
63
  end
64
64
 
65
+ def database_backups
66
+ shelly.database_backups(code_name)
67
+ end
68
+
69
+ def logs
70
+ shelly.cloud_logs(self.code_name)
71
+ end
72
+
65
73
  def start
66
74
  shelly.start_cloud(code_name)
67
75
  end
@@ -0,0 +1,35 @@
1
+ require "shelly/cli/command"
2
+
3
+ module Shelly
4
+ module CLI
5
+ class Backup < Command
6
+ namespace :backup
7
+ include Helpers
8
+
9
+ desc "list", "List database backup clouds defined in Cloudfile"
10
+ def list(cloud = nil)
11
+ logged_in?
12
+ say_error "Must be run inside your project git repository" unless App.inside_git_repository?
13
+ say_error "No Cloudfile found" unless Cloudfile.present?
14
+ multiple_clouds(cloud, "backup list", "Select cloud to view database backups using:")
15
+ backups = @app.database_backups
16
+ unless backups.empty?
17
+ backups.unshift({"filename" => "Filename", "size" => "Size"})
18
+ say "Available backups:", :green
19
+ say_new_line
20
+ print_table(backups.map do |backup|
21
+ [backup['filename'], "| #{backup['size']}"]
22
+ end, :ident => 2)
23
+ else
24
+ say "No database backups available"
25
+ end
26
+ rescue Client::APIError => e
27
+ if e.unauthorized?
28
+ say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
29
+ else
30
+ say_error e.message
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,6 @@
1
1
  require "shelly/cli/command"
2
2
  require "shelly/cli/user"
3
+ require "shelly/cli/backup"
3
4
  require "shelly/cli/deploys"
4
5
  require "shelly/cli/config"
5
6
 
@@ -9,6 +10,7 @@ module Shelly
9
10
  include Thor::Actions
10
11
  include Helpers
11
12
  register(User, "user", "user <command>", "Manages users using this cloud")
13
+ register(Backup, "backup", "backup <command>", "Manages database backups from this cloud")
12
14
  register(Deploys, "deploys", "deploys <command>", "View cloud deploy logs")
13
15
  register(Config, "config", "config <command>", "Manages cloud configuration files")
14
16
  check_unknown_options!
data/lib/shelly/client.rb CHANGED
@@ -102,6 +102,10 @@ module Shelly
102
102
  get("/apps/#{cloud}/logs")
103
103
  end
104
104
 
105
+ def database_backups(code_name)
106
+ get("/apps/#{code_name}/database_backups")
107
+ end
108
+
105
109
  def ssh_key_available?(ssh_key)
106
110
  get("/users/new", :ssh_key => ssh_key)
107
111
  end
@@ -1,3 +1,3 @@
1
1
  module Shelly
2
- VERSION = "0.0.31"
2
+ VERSION = "0.0.32"
3
3
  end
@@ -0,0 +1,60 @@
1
+ require "spec_helper"
2
+ require "shelly/cli/backup"
3
+
4
+ describe Shelly::CLI::Backup do
5
+ before do
6
+ @backup = Shelly::CLI::Backup.new
7
+ @client = mock
8
+ Shelly::Client.stub(:new).and_return(@client)
9
+ end
10
+
11
+ describe "#list" do
12
+ before do
13
+ FileUtils.mkdir_p("/projects/foo")
14
+ Dir.chdir("/projects/foo")
15
+ File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\n") }
16
+ @client.stub(:token).and_return("abc")
17
+ end
18
+
19
+ it "should exit with message if there is no Cloudfile" do
20
+ File.delete("Cloudfile")
21
+ $stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
22
+ lambda {
23
+ @backup.list
24
+ }.should raise_error(SystemExit)
25
+ end
26
+
27
+ it "should exit if user doesn't have access to cloud in Cloudfile" do
28
+ response = {"message" => "Cloud foo-staging not found"}
29
+ exception = Shelly::Client::APIError.new(response.to_json)
30
+ @client.stub(:database_backups).and_raise(exception)
31
+ $stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
32
+ lambda { @backup.list }.should raise_error(SystemExit)
33
+ end
34
+
35
+ context "multiple clouds" do
36
+ before do
37
+ File.open("Cloudfile", 'w') {|f| f.write("foo-staging:\nfoo-production:\n") }
38
+ end
39
+
40
+ it "should show information to select specific cloud and exit" do
41
+ $stdout.should_receive(:puts).with("You have multiple clouds in Cloudfile. Select cloud to view database backups using:")
42
+ $stdout.should_receive(:puts).with(" shelly backup list foo-production")
43
+ $stdout.should_receive(:puts).with("Available clouds:")
44
+ $stdout.should_receive(:puts).with(" * foo-production")
45
+ $stdout.should_receive(:puts).with(" * foo-staging")
46
+ lambda { @backup.list }.should raise_error(SystemExit)
47
+ end
48
+
49
+ it "should take cloud from command line for which to show backups" do
50
+ @client.should_receive(:database_backups).with("foo-staging").and_return([{"filename" => "backup.postgre.tar.gz", "size" => "10kb"},{"filename" => "backup.mongo.tar.gz", "size" => "22kb"}])
51
+ $stdout.should_receive(:puts).with(green "Available backups:")
52
+ $stdout.should_receive(:puts).with("\n")
53
+ $stdout.should_receive(:puts).with(" Filename | Size")
54
+ $stdout.should_receive(:puts).with(" backup.postgre.tar.gz | 10kb")
55
+ $stdout.should_receive(:puts).with(" backup.mongo.tar.gz | 22kb")
56
+ @backup.list("foo-staging")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -24,6 +24,7 @@ describe Shelly::CLI::Main do
24
24
  expected = <<-OUT
25
25
  Tasks:
26
26
  shelly add # Adds new cloud to Shelly Cloud
27
+ shelly backup <command> # Manages database backups from this cloud
27
28
  shelly config <command> # Manages cloud configuration files
28
29
  shelly delete CODE-NAME # Delete cloud from Shelly Cloud
29
30
  shelly deploys <command> # View cloud deploy logs
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shelly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 95
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 31
10
- version: 0.0.31
9
+ - 32
10
+ version: 0.0.32
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shelly Cloud team
@@ -208,6 +208,7 @@ files:
208
208
  - lib/core_ext/object.rb
209
209
  - lib/shelly.rb
210
210
  - lib/shelly/app.rb
211
+ - lib/shelly/cli/backup.rb
211
212
  - lib/shelly/cli/command.rb
212
213
  - lib/shelly/cli/config.rb
213
214
  - lib/shelly/cli/deploys.rb
@@ -228,6 +229,7 @@ files:
228
229
  - spec/helpers.rb
229
230
  - spec/input_faker.rb
230
231
  - spec/shelly/app_spec.rb
232
+ - spec/shelly/cli/backup_spec.rb
231
233
  - spec/shelly/cli/config_spec.rb
232
234
  - spec/shelly/cli/deploys_spec.rb
233
235
  - spec/shelly/cli/main_spec.rb
@@ -276,6 +278,7 @@ test_files:
276
278
  - spec/helpers.rb
277
279
  - spec/input_faker.rb
278
280
  - spec/shelly/app_spec.rb
281
+ - spec/shelly/cli/backup_spec.rb
279
282
  - spec/shelly/cli/config_spec.rb
280
283
  - spec/shelly/cli/deploys_spec.rb
281
284
  - spec/shelly/cli/main_spec.rb