acquia_toolbelt 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.ruby-version +1 -0
- data/Gemfile.lock +35 -0
- data/README.md +55 -27
- data/acquia_toolbelt.gemspec +2 -0
- data/bin/acquia +6 -565
- data/lib/acquia_toolbelt/cli.rb +102 -0
- data/lib/acquia_toolbelt/cli/api.rb +106 -0
- data/lib/acquia_toolbelt/cli/auth.rb +31 -0
- data/lib/acquia_toolbelt/cli/database.rb +208 -0
- data/lib/acquia_toolbelt/cli/deploy.rb +30 -0
- data/lib/acquia_toolbelt/cli/domain.rb +166 -0
- data/lib/acquia_toolbelt/cli/environment.rb +38 -0
- data/lib/acquia_toolbelt/cli/file.rb +23 -0
- data/lib/acquia_toolbelt/cli/server.rb +61 -0
- data/lib/acquia_toolbelt/cli/site.rb +28 -0
- data/lib/acquia_toolbelt/cli/ssh.rb +69 -0
- data/lib/acquia_toolbelt/cli/svn.rb +65 -0
- data/lib/acquia_toolbelt/cli/task.rb +71 -0
- data/lib/acquia_toolbelt/cli/ui.rb +29 -0
- data/lib/acquia_toolbelt/error.rb +4 -0
- data/lib/acquia_toolbelt/thor.rb +95 -0
- data/lib/acquia_toolbelt/version.rb +1 -1
- data/lib/vendor/thor/CHANGELOG.md +139 -0
- data/lib/vendor/thor/Gemfile +20 -0
- data/lib/vendor/thor/LICENSE.md +20 -0
- data/lib/vendor/thor/README.md +35 -0
- data/lib/vendor/thor/lib/thor.rb +474 -0
- data/lib/vendor/thor/lib/thor/actions.rb +318 -0
- data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
- data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
- data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
- data/lib/vendor/thor/lib/thor/base.rb +654 -0
- data/lib/vendor/thor/lib/thor/command.rb +136 -0
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
- data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/vendor/thor/lib/thor/error.rb +32 -0
- data/lib/vendor/thor/lib/thor/group.rb +282 -0
- data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
- data/lib/vendor/thor/lib/thor/parser.rb +4 -0
- data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
- data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
- data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
- data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
- data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
- data/lib/vendor/thor/lib/thor/runner.rb +322 -0
- data/lib/vendor/thor/lib/thor/shell.rb +88 -0
- data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
- data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
- data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
- data/lib/vendor/thor/lib/thor/util.rb +270 -0
- data/lib/vendor/thor/lib/thor/version.rb +3 -0
- data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
- data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
- data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
- data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
- data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
- data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
- data/lib/vendor/thor/spec/actions_spec.rb +331 -0
- data/lib/vendor/thor/spec/base_spec.rb +291 -0
- data/lib/vendor/thor/spec/command_spec.rb +80 -0
- data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
- data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
- data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
- data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
- data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
- data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
- data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
- data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
- data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
- data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
- data/lib/vendor/thor/spec/fixtures/path with spaces b/data/lib/vendor/thor/spec/fixtures/path with → spaces +0 -0
- data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
- data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
- data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
- data/lib/vendor/thor/spec/group_spec.rb +222 -0
- data/lib/vendor/thor/spec/helper.rb +67 -0
- data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
- data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
- data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
- data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
- data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
- data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
- data/lib/vendor/thor/spec/register_spec.rb +197 -0
- data/lib/vendor/thor/spec/runner_spec.rb +241 -0
- data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
- data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
- data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
- data/lib/vendor/thor/spec/shell_spec.rb +47 -0
- data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
- data/lib/vendor/thor/spec/thor_spec.rb +499 -0
- data/lib/vendor/thor/spec/util_spec.rb +196 -0
- data/lib/vendor/thor/thor.gemspec +24 -0
- data/spec/auth_spec.rb +8 -0
- data/spec_helper.rb +6 -0
- metadata +135 -4
- data/tests/example_test.rb +0 -5
@@ -0,0 +1,102 @@
|
|
1
|
+
require "acquia_toolbelt"
|
2
|
+
require "acquia_toolbelt/error"
|
3
|
+
require "acquia_toolbelt/thor"
|
4
|
+
|
5
|
+
module AcquiaToolbelt
|
6
|
+
class CLI < AcquiaToolbelt::Thor
|
7
|
+
require "acquia_toolbelt/cli/ui"
|
8
|
+
require "acquia_toolbelt/cli/api"
|
9
|
+
require "acquia_toolbelt/cli/auth"
|
10
|
+
require "acquia_toolbelt/cli/database"
|
11
|
+
require "acquia_toolbelt/cli/server"
|
12
|
+
require "acquia_toolbelt/cli/ssh"
|
13
|
+
require "acquia_toolbelt/cli/svn"
|
14
|
+
require "acquia_toolbelt/cli/task"
|
15
|
+
require "acquia_toolbelt/cli/site"
|
16
|
+
require "acquia_toolbelt/cli/domain"
|
17
|
+
require "acquia_toolbelt/cli/deploy"
|
18
|
+
require "acquia_toolbelt/cli/file"
|
19
|
+
require "acquia_toolbelt/cli/environment"
|
20
|
+
|
21
|
+
include Thor::Actions
|
22
|
+
|
23
|
+
def self.start(given_args = ARGV, config = {})
|
24
|
+
Thor::Base.shell = AcquiaToolbelt::CLI::UI
|
25
|
+
ui = AcquiaToolbelt::CLI::UI.new
|
26
|
+
|
27
|
+
# Use a custom symbol to separate the commands. Useful for rake styled
|
28
|
+
# commands.
|
29
|
+
if given_args[0].include? ":"
|
30
|
+
given_args = given_args.flat_map {|e| e.split(':')}
|
31
|
+
end
|
32
|
+
|
33
|
+
super(given_args, {:shell => ui}.merge(config))
|
34
|
+
rescue AcquiaToolbelt::Error
|
35
|
+
ui.print_exception(e)
|
36
|
+
raise
|
37
|
+
rescue Interrupt => e
|
38
|
+
puts
|
39
|
+
ui.print_exception(e)
|
40
|
+
ui.say("Quitting...")
|
41
|
+
raise
|
42
|
+
rescue SystemExit, Errno::EPIPE
|
43
|
+
# Don't print a message for safe exits.
|
44
|
+
raise
|
45
|
+
rescue Exception => e
|
46
|
+
ui.print_exception(e)
|
47
|
+
raise
|
48
|
+
end
|
49
|
+
|
50
|
+
# Define some options that are available to all commands.
|
51
|
+
class_option :subscription, :type => :string, :aliases => %w(-s),
|
52
|
+
:desc => "Name of a subscription you would like to target."
|
53
|
+
class_option :environment, :type => :string, :aliases => %w(-e),
|
54
|
+
:desc => "Environment to target for commands."
|
55
|
+
class_option :verbose, :type => :boolean, :aliases => %w(-v),
|
56
|
+
:desc => "Increase the verbose output from the commands."
|
57
|
+
|
58
|
+
# Authentication.
|
59
|
+
desc "auth", ""
|
60
|
+
subcommand "auth", AcquiaToolbelt::CLI::Auth
|
61
|
+
|
62
|
+
# Databases.
|
63
|
+
desc "databases", ""
|
64
|
+
subcommand "databases", AcquiaToolbelt::CLI::Databases
|
65
|
+
|
66
|
+
# Servers.
|
67
|
+
desc "servers", ""
|
68
|
+
subcommand "servers", AcquiaToolbelt::CLI::Servers
|
69
|
+
|
70
|
+
# SSH.
|
71
|
+
desc "ssh", ""
|
72
|
+
subcommand "ssh", AcquiaToolbelt::CLI::SSH
|
73
|
+
|
74
|
+
# SVN.
|
75
|
+
desc "svn", ""
|
76
|
+
subcommand "svn", AcquiaToolbelt::CLI::SVN
|
77
|
+
|
78
|
+
# Tasks.
|
79
|
+
desc "tasks", ""
|
80
|
+
subcommand "tasks", AcquiaToolbelt::CLI::Tasks
|
81
|
+
|
82
|
+
# Sites.
|
83
|
+
desc "sites", ""
|
84
|
+
subcommand "sites", AcquiaToolbelt::CLI::Sites
|
85
|
+
|
86
|
+
# Domains.
|
87
|
+
desc "domains", ""
|
88
|
+
subcommand "domains", AcquiaToolbelt::CLI::Domains
|
89
|
+
|
90
|
+
# Deployments.
|
91
|
+
desc "deploy", ""
|
92
|
+
subcommand "deploy", AcquiaToolbelt::CLI::Deploy
|
93
|
+
|
94
|
+
# Files.
|
95
|
+
desc "files", ""
|
96
|
+
subcommand "files", AcquiaToolbelt::CLI::Files
|
97
|
+
|
98
|
+
# Environments.
|
99
|
+
desc "environments", ""
|
100
|
+
subcommand "environments", AcquiaToolbelt::CLI::Environments
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "netrc"
|
2
|
+
require "faraday"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module AcquiaToolbelt
|
6
|
+
class CLI
|
7
|
+
class API
|
8
|
+
USER_AGENT = "AcquiaToolbelt/#{AcquiaToolbelt::VERSION}"
|
9
|
+
ENDPOINT = "https://cloudapi.acquia.com"
|
10
|
+
ENDPOINT_VERSION = "v1"
|
11
|
+
|
12
|
+
# Internal: Send a request to the Acquia API.
|
13
|
+
#
|
14
|
+
# Build a HTTP request to connect to the Acquia API and handle the JSON
|
15
|
+
# response accordingly.
|
16
|
+
#
|
17
|
+
# Retuns JSON object from the response body.
|
18
|
+
def self.request(resource, method = "GET", data = {})
|
19
|
+
n = Netrc.read
|
20
|
+
|
21
|
+
# Make sure there is an entry for the Acquia API before generating the
|
22
|
+
# requests.
|
23
|
+
if n["cloudapi.acquia.com"].nil?
|
24
|
+
puts "No entry for cloudapi.acquia.com within your netrc file."
|
25
|
+
puts "You can login/reset your user credentials by running 'acquia auth:login'"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
@acquia_user, @acquia_password = n["cloudapi.acquia.com"]
|
30
|
+
|
31
|
+
# Check if the user is behind a proxy and add the proxy settings if
|
32
|
+
# they are.
|
33
|
+
conn = (using_proxy?) ? Faraday.new(:proxy => ENV["HTTPS_PROXY"]) : Faraday.new
|
34
|
+
conn.basic_auth(@acquia_user, @acquia_password)
|
35
|
+
|
36
|
+
# Be nice and send a user agent - help tracking and issue detection on
|
37
|
+
# Acquia's end as well as the client.
|
38
|
+
conn.headers["User-Agent"] = "#{AcquiaToolbelt::CLI::API::USER_AGENT}"
|
39
|
+
|
40
|
+
case method
|
41
|
+
when "GET"
|
42
|
+
response = conn.get "#{endpoint_uri}/#{resource}.json"
|
43
|
+
JSON.parse response.body
|
44
|
+
when "POST"
|
45
|
+
response = conn.post "#{endpoint_uri}/#{resource}.json", data.to_json
|
46
|
+
JSON.parse response.body
|
47
|
+
when "QUERY-STRING-POST"
|
48
|
+
response = conn.post "#{endpoint_uri}/#{resource}.json?#{data[:key]}=#{data[:value]}", data.to_json
|
49
|
+
JSON.parse response.body
|
50
|
+
when "DELETE"
|
51
|
+
response = conn.delete "#{endpoint_uri}/#{resource}.json"
|
52
|
+
JSON.parse response.body
|
53
|
+
else
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Internal: Get defined subscription environments.
|
58
|
+
#
|
59
|
+
# This is a helper method that fetches all the available environments for
|
60
|
+
# a subscription and returns them for use in other methods.
|
61
|
+
#
|
62
|
+
# Returns an array of environments.
|
63
|
+
def self.get_environments
|
64
|
+
subscription = default_subscription
|
65
|
+
env_data = request "sites/#{subscription}/envs"
|
66
|
+
|
67
|
+
envs = []
|
68
|
+
env_data.each do |env|
|
69
|
+
envs << env["name"]
|
70
|
+
end
|
71
|
+
|
72
|
+
envs
|
73
|
+
end
|
74
|
+
|
75
|
+
# Internal: Use the default environment the user has access to.
|
76
|
+
#
|
77
|
+
# If the -s (subscription) flag is not set, just use the first
|
78
|
+
# subscription the user has access to. This is handy for users that
|
79
|
+
# primarily only deal with a specific subscription.
|
80
|
+
#
|
81
|
+
# Returns the first subscription name.
|
82
|
+
def self.default_subscription
|
83
|
+
sites = request "sites"
|
84
|
+
sites.first
|
85
|
+
end
|
86
|
+
|
87
|
+
# Internal: Build the endpoint URI.
|
88
|
+
#
|
89
|
+
# By building the URI here, we ensure that it is consistent throughout the
|
90
|
+
# application and also allows a single point to update should it be
|
91
|
+
# needed.
|
92
|
+
#
|
93
|
+
# Returns a URI string.
|
94
|
+
def self.endpoint_uri
|
95
|
+
"#{AcquiaToolbelt::CLI::API::ENDPOINT}/#{AcquiaToolbelt::CLI::API::ENDPOINT_VERSION}"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Internal: Check whether a proxy is in use.
|
99
|
+
#
|
100
|
+
# Return boolean based on whether HTTPS_PROXY is set.
|
101
|
+
def self.using_proxy?
|
102
|
+
ENV["HTTPS_PROXY"] ? true : false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "highline/import"
|
2
|
+
require "netrc"
|
3
|
+
require "acquia_toolbelt/cli"
|
4
|
+
|
5
|
+
module AcquiaToolbelt
|
6
|
+
class CLI
|
7
|
+
class Auth < AcquiaToolbelt::Thor
|
8
|
+
desc "login", "Login to your Acquia account."
|
9
|
+
# Public: Login to an Acquia account.
|
10
|
+
#
|
11
|
+
# Save the login details in a netrc file for use for all authenticated
|
12
|
+
# requests.
|
13
|
+
#
|
14
|
+
# Returns a status message.
|
15
|
+
def login
|
16
|
+
cli = HighLine.new
|
17
|
+
user = cli.ask("Enter your username: ")
|
18
|
+
password = cli.ask("Enter your password: ") { |q| q.echo = false }
|
19
|
+
|
20
|
+
# Update (or create if needed) the netrc file that will contain the user
|
21
|
+
# authentication details.
|
22
|
+
n = Netrc.read
|
23
|
+
n.new_item_prefix = "# This entry was added for connecting to the Acquia Cloud API\n"
|
24
|
+
n["cloudapi.acquia.com"] = user, password
|
25
|
+
n.save
|
26
|
+
|
27
|
+
ui.success "Your user credentials have been successfully set."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
module AcquiaToolbelt
|
2
|
+
class CLI
|
3
|
+
class Databases < AcquiaToolbelt::Thor
|
4
|
+
no_tasks do
|
5
|
+
# Internal: Build the database output.
|
6
|
+
#
|
7
|
+
# Output the database information exposing all the available fields and
|
8
|
+
# data to the end user.
|
9
|
+
#
|
10
|
+
# Returns multiple lines.
|
11
|
+
def output_database_instance(database)
|
12
|
+
ui.say "> Username: #{database["username"]}"
|
13
|
+
ui.say "> Password: #{database["password"]}"
|
14
|
+
ui.say "> Host: #{database["host"]}"
|
15
|
+
ui.say "> DB cluster: #{database["db_cluster"]}"
|
16
|
+
ui.say "> Instance name: #{database["instance_name"]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Add a database to the subscription.
|
21
|
+
#
|
22
|
+
# Returns a status message.
|
23
|
+
desc "add", "Add a database."
|
24
|
+
method_option :database, :type => :string, :aliases => %w(-d), :required => true,
|
25
|
+
:desc => "Name of the database to create."
|
26
|
+
def add
|
27
|
+
if options[:subscription]
|
28
|
+
subscription = options[:subscription]
|
29
|
+
else
|
30
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
31
|
+
end
|
32
|
+
|
33
|
+
database = options[:database]
|
34
|
+
add_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs", "POST", :db => "#{database}"
|
35
|
+
ui.success "Database '#{database}' has been successfully created." if add_database["id"]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Public: Copy a database from one environment to another.
|
39
|
+
#
|
40
|
+
# Returns a status message.
|
41
|
+
desc "copy", "Copy a database from one environment to another."
|
42
|
+
method_option :database, :type => :string, :aliases => %w(-d), :required => true,
|
43
|
+
:desc => "Name of the database to copy."
|
44
|
+
method_option :origin, :type => :string, :aliases => %w(-o), :required => true,
|
45
|
+
:desc => "Origin of the database to copy."
|
46
|
+
method_option :target, :type => :string, :aliases => %w(-t), :required => true,
|
47
|
+
:desc => "Target of where to copy the database."
|
48
|
+
def copy
|
49
|
+
if options[:subscription]
|
50
|
+
subscription = options[:subscription]
|
51
|
+
else
|
52
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
53
|
+
end
|
54
|
+
|
55
|
+
database = options[:database]
|
56
|
+
origin = options[:origin]
|
57
|
+
target = options[:target]
|
58
|
+
copy_database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}/db-copy/#{origin}/#{target}", "POST"
|
59
|
+
ui.success "Database '#{database}' has been copied from #{origin} to #{target}." if copy_database["id"]
|
60
|
+
end
|
61
|
+
|
62
|
+
# Public: Delete a database from a subscription.
|
63
|
+
#
|
64
|
+
# NB: This will delete all instances of the database across all
|
65
|
+
# environments.
|
66
|
+
#
|
67
|
+
# Returns a status message.
|
68
|
+
desc "delete", "Delete a database."
|
69
|
+
method_option :database, :type => :string, :aliases => %w(-d), :required => true,
|
70
|
+
:desc => "Name of the database to delete."
|
71
|
+
def delete
|
72
|
+
if options[:subscription]
|
73
|
+
subscription = options[:subscription]
|
74
|
+
else
|
75
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
76
|
+
end
|
77
|
+
|
78
|
+
database = options[:database]
|
79
|
+
delete_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs/#{database}", "DELETE"
|
80
|
+
ui.success "Database '#{database}' has been successfully deleted." if delete_db["id"]
|
81
|
+
end
|
82
|
+
|
83
|
+
# Public: List all databases available within a subscription.
|
84
|
+
#
|
85
|
+
# Returns a database listing.
|
86
|
+
desc "list", "List all databases."
|
87
|
+
method_option :database, :type => :string, :aliases => %w(-d),
|
88
|
+
:desc => "Name of the database to view."
|
89
|
+
def list
|
90
|
+
if options[:subscription]
|
91
|
+
subscription = options[:subscription]
|
92
|
+
else
|
93
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
94
|
+
end
|
95
|
+
|
96
|
+
database = options[:database]
|
97
|
+
environment = options[:environment]
|
98
|
+
|
99
|
+
# Output a single database where the name and environment are specified.
|
100
|
+
if database && environment
|
101
|
+
database = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}"
|
102
|
+
ui.say
|
103
|
+
output_database_instance(database)
|
104
|
+
|
105
|
+
# Only an environment was set so get all expanded data for the requested
|
106
|
+
# environment.
|
107
|
+
elsif environment
|
108
|
+
databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs"
|
109
|
+
databases.each do |db|
|
110
|
+
ui.say
|
111
|
+
ui.say "#{db["name"]}"
|
112
|
+
output_database_instance(db)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Just a general listing of the databases, no in depth details.
|
116
|
+
else
|
117
|
+
databases = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/dbs"
|
118
|
+
ui.say
|
119
|
+
databases.each do |db|
|
120
|
+
say "> #{db["name"]}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Public: Create a database instance backup.
|
126
|
+
#
|
127
|
+
# Returns a status message.
|
128
|
+
desc "backup", "Create a new backup for a database."
|
129
|
+
method_option :database, :type => :string, :aliases => %w(-d), :required => true,
|
130
|
+
:desc => "Name of the database to backup."
|
131
|
+
def backup
|
132
|
+
if options[:subscription]
|
133
|
+
subscription = options[:subscription]
|
134
|
+
else
|
135
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
136
|
+
end
|
137
|
+
|
138
|
+
database = options[:database]
|
139
|
+
environment = options[:environment]
|
140
|
+
create_backup = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups", "POST"
|
141
|
+
ui.success "The backup for '#{database}' in #{environment} has been started." if create_backup["id"]
|
142
|
+
end
|
143
|
+
|
144
|
+
# Public: List available database backups.
|
145
|
+
#
|
146
|
+
# Returns all database backups.
|
147
|
+
desc "list-backups", "List all database backups."
|
148
|
+
method_option :database, :type => :string, :aliases => %w(-d), :required => true,
|
149
|
+
:desc => "Name of the database to get the backup for."
|
150
|
+
def list_backups
|
151
|
+
# Ensure we have an environment defined.
|
152
|
+
if options[:environment].nil?
|
153
|
+
ui.say "No value provided for required options '--environment'"
|
154
|
+
return
|
155
|
+
end
|
156
|
+
|
157
|
+
if options[:subscription]
|
158
|
+
subscription = options[:subscription]
|
159
|
+
else
|
160
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
161
|
+
end
|
162
|
+
|
163
|
+
database = options[:database]
|
164
|
+
environment = options[:environment]
|
165
|
+
backups = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups"
|
166
|
+
backups.each do |backup|
|
167
|
+
ui.say
|
168
|
+
ui.say "> ID: #{backup["id"]}"
|
169
|
+
ui.say "> MD5: #{backup["checksum"]}"
|
170
|
+
ui.say "> Type: #{backup["type"]}"
|
171
|
+
ui.say "> Path: #{backup["path"]}"
|
172
|
+
ui.say "> Link: #{backup["link"]}"
|
173
|
+
ui.say "> Started: #{Time.at(backup["started"].to_i)}"
|
174
|
+
ui.say "> Completed: #{Time.at(backup["completed"].to_i)}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Public: Restore a database backup.
|
179
|
+
#
|
180
|
+
# Returns a status message.
|
181
|
+
desc "restore", "Restore a database from a backup."
|
182
|
+
method_option :id, :type => :string, :aliases => %w(-i),
|
183
|
+
:desc => "Backup ID to restore."
|
184
|
+
method_option :database, :type => :string, :aliases => %w(-d),
|
185
|
+
:desc => "Name of the database to restore."
|
186
|
+
def restore
|
187
|
+
# Ensure we have an environment defined.
|
188
|
+
if options[:environment].nil?
|
189
|
+
ui.say "No value provided for required options '--environment'"
|
190
|
+
return
|
191
|
+
end
|
192
|
+
|
193
|
+
if options[:subscription]
|
194
|
+
subscription = options[:subscription]
|
195
|
+
else
|
196
|
+
subscription = AcquiaToolbelt::CLI::API.default_subscription
|
197
|
+
end
|
198
|
+
|
199
|
+
database = options[:database]
|
200
|
+
environment = options[:environment]
|
201
|
+
database = options[:database]
|
202
|
+
backup_id = options[:id]
|
203
|
+
restore_db = AcquiaToolbelt::CLI::API.request "sites/#{subscription}/envs/#{environment}/dbs/#{database}/backups/#{backup_id}/restore", "POST"
|
204
|
+
ui.success "Database backup #{backup_id} has been restored to #{database} in #{environment}." if restore_db["id"]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|