shelly 0.0.43 → 0.0.44.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/shelly/app.rb +4 -0
- data/lib/shelly/cli/backup.rb +42 -43
- data/lib/shelly/cli/config.rb +34 -47
- data/lib/shelly/cli/deploys.rb +14 -22
- data/lib/shelly/cli/main.rb +95 -88
- data/lib/shelly/cli/runner.rb +6 -2
- data/lib/shelly/cli/user.rb +10 -16
- data/lib/shelly/client.rb +36 -32
- data/lib/shelly/download_progress_bar.rb +1 -1
- data/lib/shelly/helpers.rb +5 -10
- data/lib/shelly/user.rb +10 -2
- data/lib/shelly/version.rb +1 -1
- data/lib/thor/thor.rb +4 -0
- data/shelly.gemspec +2 -1
- data/spec/helpers.rb +7 -0
- data/spec/shelly/app_spec.rb +11 -5
- data/spec/shelly/cli/backup_spec.rb +36 -31
- data/spec/shelly/cli/config_spec.rb +70 -35
- data/spec/shelly/cli/deploys_spec.rb +19 -19
- data/spec/shelly/cli/main_spec.rb +213 -105
- data/spec/shelly/cli/runner_spec.rb +29 -1
- data/spec/shelly/cli/user_spec.rb +20 -53
- data/spec/shelly/client_spec.rb +90 -81
- data/spec/shelly/download_progress_bar_spec.rb +4 -4
- data/spec/shelly/user_spec.rb +23 -0
- data/spec/spec_helper.rb +5 -1
- metadata +43 -32
data/.gitignore
CHANGED
data/lib/shelly/app.rb
CHANGED
data/lib/shelly/cli/backup.rb
CHANGED
@@ -8,14 +8,14 @@ module Shelly
|
|
8
8
|
namespace :backup
|
9
9
|
include Helpers
|
10
10
|
|
11
|
-
before_hook :logged_in?, :only => [:list, :get, :create]
|
11
|
+
before_hook :logged_in?, :only => [:list, :get, :create, :restore]
|
12
12
|
before_hook :cloudfile_present?, :only => [:list]
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
15
|
+
|
16
|
+
desc "list", "List available database backups"
|
17
17
|
def list
|
18
|
-
multiple_clouds(options[:cloud], "backup list"
|
18
|
+
multiple_clouds(options[:cloud], "backup list")
|
19
19
|
backups = @app.database_backups
|
20
20
|
if backups.present?
|
21
21
|
to_display = [["Filename", "| Size"]]
|
@@ -29,18 +29,18 @@ module Shelly
|
|
29
29
|
else
|
30
30
|
say "No database backups available"
|
31
31
|
end
|
32
|
-
rescue Client::
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
raise e
|
37
|
-
end
|
32
|
+
rescue Client::NotFoundException => e
|
33
|
+
raise unless e.resource == :cloud
|
34
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
|
37
|
+
desc "get [FILENAME]", "Download database backup"
|
38
|
+
long_desc %{
|
39
|
+
Download given database backup to current directory.
|
40
|
+
If filename is not specyfied, latest database backup will be downloaded.
|
41
|
+
}
|
42
42
|
def get(handler = "last")
|
43
|
-
multiple_clouds(options[:cloud], "backup get
|
43
|
+
multiple_clouds(options[:cloud], "backup get #{handler}")
|
44
44
|
|
45
45
|
backup = @app.database_backup(handler)
|
46
46
|
bar = Shelly::DownloadProgressBar.new(backup.size)
|
@@ -48,53 +48,52 @@ module Shelly
|
|
48
48
|
|
49
49
|
say_new_line
|
50
50
|
say "Backup file saved to #{backup.filename}", :green
|
51
|
-
rescue Client::
|
52
|
-
case e.
|
51
|
+
rescue Client::NotFoundException => e
|
52
|
+
case e.resource
|
53
53
|
when :cloud
|
54
|
-
say_error "You have no access to '#{@app
|
55
|
-
when :
|
54
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
55
|
+
when :database_backup
|
56
56
|
say_error "Backup not found", :with_exit => false
|
57
|
-
say "You can list available backups with
|
58
|
-
else; raise
|
57
|
+
say "You can list available backups with `shelly backup list` command"
|
58
|
+
else; raise
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
desc "create [
|
63
|
-
|
64
|
-
|
62
|
+
desc "create [DB_KIND]", "Create backup of given database"
|
63
|
+
long_desc %{
|
64
|
+
Create backup of given database.
|
65
|
+
If database kind is not specified, backup of all configured databases will be performed.
|
66
|
+
}
|
65
67
|
def create(kind = nil)
|
66
|
-
multiple_clouds(options[:cloud], "backup create
|
68
|
+
multiple_clouds(options[:cloud], "backup create [DB_KIND]")
|
67
69
|
@app.request_backup(kind)
|
68
70
|
say "Backup requested. It can take up to several minutes for " +
|
69
71
|
"the backup process to finish and the backup to show up in backups list.", :green
|
70
|
-
rescue Client::
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
72
|
+
rescue Client::ValidationException => e
|
73
|
+
say_error e[:message]
|
74
|
+
rescue Client::NotFoundException => e
|
75
|
+
raise unless e.resource == :cloud
|
76
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
76
77
|
end
|
77
78
|
|
78
|
-
desc "restore
|
79
|
-
|
80
|
-
:
|
81
|
-
def restore(filename = nil)
|
82
|
-
logged_in?
|
83
|
-
multiple_clouds(options[:cloud], "backup restore <filename>", "Select cloud for which you want restore backup")
|
84
|
-
say_error "Filename is required" unless filename
|
79
|
+
desc "restore FILENAME", "Restore database to state from given backup"
|
80
|
+
def restore(filename)
|
81
|
+
multiple_clouds(options[:cloud], "backup restore FILENAME")
|
85
82
|
backup = @app.database_backup(filename)
|
86
83
|
say "You are about restore database #{backup.kind} for cloud #{backup.code_name} to state from #{backup.filename}"
|
87
84
|
say_new_line
|
88
85
|
ask_to_restore_database
|
89
86
|
@app.restore_backup(filename)
|
90
87
|
say_new_line
|
91
|
-
say "Restore has been scheduled. Wait few minutes till database is restored."
|
92
|
-
rescue Client::
|
93
|
-
|
88
|
+
say "Restore has been scheduled. Wait a few minutes till database is restored."
|
89
|
+
rescue Client::NotFoundException => e
|
90
|
+
case e.resource
|
91
|
+
when :cloud
|
92
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
93
|
+
when :database_backup
|
94
94
|
say_error "Backup not found", :with_exit => false
|
95
|
-
say "You can list available backups with
|
96
|
-
else
|
97
|
-
raise e
|
95
|
+
say "You can list available backups with `shelly backup list` command"
|
96
|
+
else; raise
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
data/lib/shelly/cli/config.rb
CHANGED
@@ -33,88 +33,78 @@ module Shelly
|
|
33
33
|
else
|
34
34
|
say "Cloud #{cloud} has no configuration files"
|
35
35
|
end
|
36
|
-
rescue Client::
|
37
|
-
|
38
|
-
|
39
|
-
else
|
40
|
-
raise e
|
41
|
-
end
|
36
|
+
rescue Client::NotFoundException => e
|
37
|
+
raise unless e.resource == :cloud
|
38
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
42
39
|
end
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
47
|
-
:desc => "Specify which cloud to show configuration file for"
|
43
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
48
44
|
desc "show PATH", "View configuration file"
|
49
45
|
def show(path = nil)
|
50
46
|
say_error "No configuration file specified" unless path
|
51
|
-
multiple_clouds(options[:cloud], "show #{path}"
|
47
|
+
multiple_clouds(options[:cloud], "show #{path}")
|
52
48
|
config = @app.config(path)
|
53
49
|
say "Content of #{config["path"]}:", :green
|
54
50
|
say config["content"]
|
55
|
-
rescue Client::
|
56
|
-
case e.
|
51
|
+
rescue Client::NotFoundException => e
|
52
|
+
case e.resource
|
57
53
|
when :cloud
|
58
54
|
say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
|
59
55
|
when :config
|
60
56
|
say_error "Config '#{path}' not found", :with_exit => false
|
61
57
|
say_error "You can list available config files with `shelly config list --cloud #{@app}`"
|
62
|
-
else
|
58
|
+
else raise
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
62
|
map "new" => :create
|
67
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
68
|
-
:desc => "Specify which cloud to create configuration file for"
|
63
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
69
64
|
desc "create PATH", "Create configuration file"
|
70
65
|
def create(path = nil)
|
71
66
|
say_error "No path specified" unless path
|
72
67
|
output = open_editor(path)
|
73
|
-
multiple_clouds(options[:cloud], "create #{path}"
|
68
|
+
multiple_clouds(options[:cloud], "create #{path}")
|
74
69
|
@app.create_config(path, output)
|
75
70
|
say "File '#{path}' created, it will be used after next code deploy", :green
|
76
|
-
rescue Client::
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
else
|
83
|
-
say_error e.message
|
84
|
-
end
|
71
|
+
rescue Client::NotFoundException => e
|
72
|
+
raise unless e.resource == :cloud
|
73
|
+
say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
|
74
|
+
rescue Client::ValidationException => e
|
75
|
+
e.each_error { |error| say_error error, :with_exit => false }
|
76
|
+
exit 1
|
85
77
|
end
|
86
78
|
|
87
79
|
map "update" => :edit
|
88
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
89
|
-
:desc => "Specify which cloud to edit configuration file for"
|
80
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
90
81
|
desc "edit PATH", "Edit configuration file"
|
91
82
|
def edit(path = nil)
|
92
83
|
say_error "No configuration file specified" unless path
|
93
|
-
multiple_clouds(options[:cloud], "edit #{path}"
|
84
|
+
multiple_clouds(options[:cloud], "edit #{path}")
|
94
85
|
config = @app.config(path)
|
95
86
|
content = open_editor(config["path"], config["content"])
|
96
87
|
@app.update_config(path, content)
|
97
88
|
say "File '#{config["path"]}' updated, it will be used after next code deploy", :green
|
98
|
-
rescue Client::
|
99
|
-
|
89
|
+
rescue Client::NotFoundException => e
|
90
|
+
case e.resource
|
91
|
+
when :cloud
|
100
92
|
say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
|
101
|
-
|
93
|
+
when :config
|
102
94
|
say_error "Config '#{path}' not found", :with_exit => false
|
103
95
|
say_error "You can list available config files with `shelly config list --cloud #{@app}`"
|
104
|
-
|
105
|
-
e.each_error { |error| say_error error, :with_exit => false }
|
106
|
-
exit 1
|
107
|
-
else
|
108
|
-
say_error e.message
|
96
|
+
else raise
|
109
97
|
end
|
98
|
+
rescue Client::ValidationException => e
|
99
|
+
e.each_error { |error| say_error error, :with_exit => false }
|
100
|
+
exit 1
|
110
101
|
end
|
111
102
|
|
112
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
113
|
-
:desc => "Specify for which cloud to delete configuration file for"
|
103
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
114
104
|
desc "delete PATH", "Delete configuration file"
|
115
105
|
def delete(path = nil)
|
116
106
|
say_error "No configuration file specified" unless path
|
117
|
-
multiple_clouds(options[:cloud], "delete #{path}"
|
107
|
+
multiple_clouds(options[:cloud], "delete #{path}")
|
118
108
|
answer = yes?("Are you sure you want to delete 'path' (yes/no): ")
|
119
109
|
if answer
|
120
110
|
@app.delete_config(path)
|
@@ -122,17 +112,14 @@ module Shelly
|
|
122
112
|
else
|
123
113
|
say "File not deleted"
|
124
114
|
end
|
125
|
-
rescue Client::
|
126
|
-
|
115
|
+
rescue Client::NotFoundException => e
|
116
|
+
case e.resource
|
117
|
+
when :cloud
|
127
118
|
say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
|
128
|
-
|
119
|
+
when :config
|
129
120
|
say_error "Config '#{path}' not found", :with_exit => false
|
130
121
|
say_error "You can list available config files with `shelly config list --cloud #{@app}`"
|
131
|
-
|
132
|
-
e.each_error { |error| say_error error, :with_exit => false }
|
133
|
-
exit 1
|
134
|
-
else
|
135
|
-
say_error e.message
|
122
|
+
else raise
|
136
123
|
end
|
137
124
|
end
|
138
125
|
|
@@ -166,4 +153,4 @@ module Shelly
|
|
166
153
|
|
167
154
|
end
|
168
155
|
end
|
169
|
-
end
|
156
|
+
end
|
data/lib/shelly/cli/deploys.rb
CHANGED
@@ -11,10 +11,9 @@ module Shelly
|
|
11
11
|
before_hook :cloudfile_present?, :only => [:list, :show]
|
12
12
|
|
13
13
|
desc "list", "Lists deploy logs"
|
14
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
15
|
-
:desc => "Specify which cloud to show deploy logs for"
|
14
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
16
15
|
def list
|
17
|
-
multiple_clouds(options[:cloud], "deploys list"
|
16
|
+
multiple_clouds(options[:cloud], "deploys list")
|
18
17
|
logs = @app.deploy_logs
|
19
18
|
unless logs.empty?
|
20
19
|
say "Available deploy logs", :green
|
@@ -24,20 +23,16 @@ module Shelly
|
|
24
23
|
else
|
25
24
|
say "No deploy logs available"
|
26
25
|
end
|
27
|
-
rescue Client::
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
raise e
|
32
|
-
end
|
26
|
+
rescue Client::NotFoundException => e
|
27
|
+
raise unless e.resource == :cloud
|
28
|
+
say_error "You have no access to '#{@app}' cloud defined in Cloudfile"
|
33
29
|
end
|
34
30
|
|
35
31
|
desc "show LOG", "Show specific deploy log"
|
36
|
-
method_option :cloud, :type => :string, :aliases => "-c",
|
37
|
-
:desc => "Specify which cloud to show deploy logs for"
|
32
|
+
method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud"
|
38
33
|
def show(log = nil)
|
39
34
|
specify_log(log)
|
40
|
-
multiple_clouds(options[:cloud], "deploys show #{log}"
|
35
|
+
multiple_clouds(options[:cloud], "deploys show #{log}")
|
41
36
|
content = @app.deploy_log(log)
|
42
37
|
say "Log for deploy done on #{content["created_at"]}", :green
|
43
38
|
if content["bundle_install"]
|
@@ -55,16 +50,13 @@ module Shelly
|
|
55
50
|
if content["thin_restart"]
|
56
51
|
say("Starting thin", :green); say(content["thin_restart"])
|
57
52
|
end
|
58
|
-
rescue Client::
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
else
|
67
|
-
raise e
|
53
|
+
rescue Client::NotFoundException => e
|
54
|
+
case e.resource
|
55
|
+
when :cloud
|
56
|
+
say_error "You have no access to '#{@app.code_name}' cloud defined in Cloudfile"
|
57
|
+
when :log
|
58
|
+
say_error "Log not found, list all deploy logs using `shelly deploys list --cloud=#{@app.code_name}`"
|
59
|
+
else raise
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|