acquia_toolbelt 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +62 -130
- data/.gitignore +0 -4
- data/.ruby-version +0 -1
- data/.travis.yml +0 -7
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -35
- data/LICENSE +0 -19
- data/README.md +0 -147
- data/Rakefile +0 -1
- data/acquia_toolbelt.gemspec +0 -32
- data/bin/acquia +0 -9
- data/lib/acquia_toolbelt.rb +0 -4
- data/lib/acquia_toolbelt/cli.rb +0 -103
- data/lib/acquia_toolbelt/cli/api.rb +0 -106
- data/lib/acquia_toolbelt/cli/auth.rb +0 -31
- data/lib/acquia_toolbelt/cli/database.rb +0 -208
- data/lib/acquia_toolbelt/cli/deploy.rb +0 -30
- data/lib/acquia_toolbelt/cli/domain.rb +0 -166
- data/lib/acquia_toolbelt/cli/environment.rb +0 -38
- data/lib/acquia_toolbelt/cli/file.rb +0 -23
- data/lib/acquia_toolbelt/cli/server.rb +0 -61
- data/lib/acquia_toolbelt/cli/site.rb +0 -28
- data/lib/acquia_toolbelt/cli/ssh.rb +0 -69
- data/lib/acquia_toolbelt/cli/svn.rb +0 -65
- data/lib/acquia_toolbelt/cli/task.rb +0 -71
- data/lib/acquia_toolbelt/cli/ui.rb +0 -29
- data/lib/acquia_toolbelt/error.rb +0 -4
- data/lib/acquia_toolbelt/thor.rb +0 -95
- data/lib/acquia_toolbelt/version.rb +0 -3
- data/lib/vendor/thor/CHANGELOG.md +0 -139
- data/lib/vendor/thor/Gemfile +0 -20
- data/lib/vendor/thor/LICENSE.md +0 -20
- data/lib/vendor/thor/README.md +0 -35
- data/lib/vendor/thor/lib/thor.rb +0 -474
- data/lib/vendor/thor/lib/thor/actions.rb +0 -318
- data/lib/vendor/thor/lib/thor/actions/create_file.rb +0 -105
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +0 -60
- data/lib/vendor/thor/lib/thor/actions/directory.rb +0 -119
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +0 -137
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +0 -317
- data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +0 -109
- data/lib/vendor/thor/lib/thor/base.rb +0 -654
- data/lib/vendor/thor/lib/thor/command.rb +0 -136
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -80
- data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +0 -12
- data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/vendor/thor/lib/thor/error.rb +0 -32
- data/lib/vendor/thor/lib/thor/group.rb +0 -282
- data/lib/vendor/thor/lib/thor/invocation.rb +0 -172
- data/lib/vendor/thor/lib/thor/parser.rb +0 -4
- data/lib/vendor/thor/lib/thor/parser/argument.rb +0 -74
- data/lib/vendor/thor/lib/thor/parser/arguments.rb +0 -171
- data/lib/vendor/thor/lib/thor/parser/option.rb +0 -121
- data/lib/vendor/thor/lib/thor/parser/options.rb +0 -218
- data/lib/vendor/thor/lib/thor/rake_compat.rb +0 -72
- data/lib/vendor/thor/lib/thor/runner.rb +0 -322
- data/lib/vendor/thor/lib/thor/shell.rb +0 -88
- data/lib/vendor/thor/lib/thor/shell/basic.rb +0 -422
- data/lib/vendor/thor/lib/thor/shell/color.rb +0 -148
- data/lib/vendor/thor/lib/thor/shell/html.rb +0 -127
- data/lib/vendor/thor/lib/thor/util.rb +0 -270
- data/lib/vendor/thor/lib/thor/version.rb +0 -3
- data/lib/vendor/thor/spec/actions/create_file_spec.rb +0 -170
- data/lib/vendor/thor/spec/actions/create_link_spec.rb +0 -95
- data/lib/vendor/thor/spec/actions/directory_spec.rb +0 -169
- data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +0 -129
- data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +0 -382
- data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +0 -135
- data/lib/vendor/thor/spec/actions_spec.rb +0 -331
- data/lib/vendor/thor/spec/base_spec.rb +0 -291
- data/lib/vendor/thor/spec/command_spec.rb +0 -80
- data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
- data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/lib/vendor/thor/spec/exit_condition_spec.rb +0 -19
- data/lib/vendor/thor/spec/fixtures/application.rb +0 -2
- data/lib/vendor/thor/spec/fixtures/app{1}/README +0 -3
- data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +0 -6
- data/lib/vendor/thor/spec/fixtures/bundle/main.thor +0 -1
- data/lib/vendor/thor/spec/fixtures/command.thor +0 -10
- data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +0 -11
- data/lib/vendor/thor/spec/fixtures/doc/README +0 -3
- data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +0 -3
- data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
- data/lib/vendor/thor/spec/fixtures/doc/config.rb +0 -1
- data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +0 -1
- data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
- data/lib/vendor/thor/spec/fixtures/enum.thor +0 -10
- data/lib/vendor/thor/spec/fixtures/group.thor +0 -128
- data/lib/vendor/thor/spec/fixtures/invoke.thor +0 -118
- 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 +0 -3
- data/lib/vendor/thor/spec/fixtures/script.thor +0 -220
- data/lib/vendor/thor/spec/fixtures/subcommand.thor +0 -17
- data/lib/vendor/thor/spec/group_spec.rb +0 -222
- data/lib/vendor/thor/spec/helper.rb +0 -67
- data/lib/vendor/thor/spec/invocation_spec.rb +0 -108
- data/lib/vendor/thor/spec/parser/argument_spec.rb +0 -53
- data/lib/vendor/thor/spec/parser/arguments_spec.rb +0 -66
- data/lib/vendor/thor/spec/parser/option_spec.rb +0 -202
- data/lib/vendor/thor/spec/parser/options_spec.rb +0 -400
- data/lib/vendor/thor/spec/rake_compat_spec.rb +0 -72
- data/lib/vendor/thor/spec/register_spec.rb +0 -197
- data/lib/vendor/thor/spec/runner_spec.rb +0 -241
- data/lib/vendor/thor/spec/shell/basic_spec.rb +0 -330
- data/lib/vendor/thor/spec/shell/color_spec.rb +0 -95
- data/lib/vendor/thor/spec/shell/html_spec.rb +0 -31
- data/lib/vendor/thor/spec/shell_spec.rb +0 -47
- data/lib/vendor/thor/spec/subcommand_spec.rb +0 -30
- data/lib/vendor/thor/spec/thor_spec.rb +0 -499
- data/lib/vendor/thor/spec/util_spec.rb +0 -196
- data/lib/vendor/thor/thor.gemspec +0 -24
- data/script/setup_build +0 -6
- data/spec/auth_spec.rb +0 -8
- data/spec_helper.rb +0 -6
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/acquia_toolbelt.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'acquia_toolbelt/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "acquia_toolbelt"
|
8
|
-
spec.version = AcquiaToolbelt::VERSION
|
9
|
-
spec.authors = ["Jacob Bednarz"]
|
10
|
-
spec.email = ["jacob.bednarz@gmail.com"]
|
11
|
-
spec.description = %q{A CLI tool for interacting with Acquia's hosting services.}
|
12
|
-
spec.summary = ""
|
13
|
-
spec.homepage = "https://github.com/jacobbednarz/acquia-toolbelt"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_runtime_dependency "thor", "0.18.1"
|
22
|
-
spec.add_runtime_dependency "netrc", "0.7.7"
|
23
|
-
spec.add_runtime_dependency "highline", "1.6.19"
|
24
|
-
spec.add_runtime_dependency "faraday", "0.8.8"
|
25
|
-
spec.add_runtime_dependency "json", "1.8.0"
|
26
|
-
spec.add_runtime_dependency "rainbow", "1.1.4"
|
27
|
-
spec.add_runtime_dependency "sshkey", "1.6.0"
|
28
|
-
|
29
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
30
|
-
spec.add_development_dependency "rake"
|
31
|
-
spec.add_development_dependency "minitest"
|
32
|
-
end
|
data/bin/acquia
DELETED
data/lib/acquia_toolbelt.rb
DELETED
data/lib/acquia_toolbelt/cli.rb
DELETED
@@ -1,103 +0,0 @@
|
|
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
|
-
commands = given_args.shift.split(":")
|
31
|
-
given_args = given_args.unshift(commands).flatten
|
32
|
-
end
|
33
|
-
|
34
|
-
super(given_args, {:shell => ui}.merge(config))
|
35
|
-
rescue AcquiaToolbelt::Error
|
36
|
-
ui.print_exception(e)
|
37
|
-
raise
|
38
|
-
rescue Interrupt => e
|
39
|
-
puts
|
40
|
-
ui.print_exception(e)
|
41
|
-
ui.say("Quitting...")
|
42
|
-
raise
|
43
|
-
rescue SystemExit, Errno::EPIPE
|
44
|
-
# Don't print a message for safe exits.
|
45
|
-
raise
|
46
|
-
rescue Exception => e
|
47
|
-
ui.print_exception(e)
|
48
|
-
raise
|
49
|
-
end
|
50
|
-
|
51
|
-
# Define some options that are available to all commands.
|
52
|
-
class_option :subscription, :type => :string, :aliases => %w(-s),
|
53
|
-
:desc => "Name of a subscription you would like to target."
|
54
|
-
class_option :environment, :type => :string, :aliases => %w(-e),
|
55
|
-
:desc => "Environment to target for commands."
|
56
|
-
class_option :verbose, :type => :boolean, :aliases => %w(-v),
|
57
|
-
:desc => "Increase the verbose output from the commands."
|
58
|
-
|
59
|
-
# Authentication.
|
60
|
-
desc "auth", ""
|
61
|
-
subcommand "auth", AcquiaToolbelt::CLI::Auth
|
62
|
-
|
63
|
-
# Databases.
|
64
|
-
desc "databases", ""
|
65
|
-
subcommand "databases", AcquiaToolbelt::CLI::Databases
|
66
|
-
|
67
|
-
# Servers.
|
68
|
-
desc "servers", ""
|
69
|
-
subcommand "servers", AcquiaToolbelt::CLI::Servers
|
70
|
-
|
71
|
-
# SSH.
|
72
|
-
desc "ssh", ""
|
73
|
-
subcommand "ssh", AcquiaToolbelt::CLI::SSH
|
74
|
-
|
75
|
-
# SVN.
|
76
|
-
desc "svn", ""
|
77
|
-
subcommand "svn", AcquiaToolbelt::CLI::SVN
|
78
|
-
|
79
|
-
# Tasks.
|
80
|
-
desc "tasks", ""
|
81
|
-
subcommand "tasks", AcquiaToolbelt::CLI::Tasks
|
82
|
-
|
83
|
-
# Sites.
|
84
|
-
desc "sites", ""
|
85
|
-
subcommand "sites", AcquiaToolbelt::CLI::Sites
|
86
|
-
|
87
|
-
# Domains.
|
88
|
-
desc "domains", ""
|
89
|
-
subcommand "domains", AcquiaToolbelt::CLI::Domains
|
90
|
-
|
91
|
-
# Deployments.
|
92
|
-
desc "deploy", ""
|
93
|
-
subcommand "deploy", AcquiaToolbelt::CLI::Deploy
|
94
|
-
|
95
|
-
# Files.
|
96
|
-
desc "files", ""
|
97
|
-
subcommand "files", AcquiaToolbelt::CLI::Files
|
98
|
-
|
99
|
-
# Environments.
|
100
|
-
desc "environments", ""
|
101
|
-
subcommand "environments", AcquiaToolbelt::CLI::Environments
|
102
|
-
end
|
103
|
-
end
|
@@ -1,106 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,208 +0,0 @@
|
|
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
|