aptible-cli 0.24.2 → 0.24.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile.lock +1 -1
- data/lib/aptible/cli/agent.rb +9 -1
- data/lib/aptible/cli/helpers/app.rb +16 -1
- data/lib/aptible/cli/helpers/database.rb +20 -5
- data/lib/aptible/cli/helpers/environment.rb +28 -3
- data/lib/aptible/cli/helpers/telemetry.rb +58 -0
- data/lib/aptible/cli/helpers/token.rb +6 -0
- data/lib/aptible/cli/renderer.rb +5 -1
- data/lib/aptible/cli/resource_formatter.rb +7 -0
- data/lib/aptible/cli/subcommands/apps.rb +31 -2
- data/lib/aptible/cli/subcommands/backup.rb +9 -0
- data/lib/aptible/cli/subcommands/backup_retention_policy.rb +5 -0
- data/lib/aptible/cli/subcommands/config.rb +11 -0
- data/lib/aptible/cli/subcommands/db.rb +68 -3
- data/lib/aptible/cli/subcommands/deploy.rb +3 -0
- data/lib/aptible/cli/subcommands/endpoints.rb +26 -0
- data/lib/aptible/cli/subcommands/environment.rb +11 -0
- data/lib/aptible/cli/subcommands/log_drain.rb +26 -5
- data/lib/aptible/cli/subcommands/logs.rb +5 -0
- data/lib/aptible/cli/subcommands/maintenance.rb +5 -0
- data/lib/aptible/cli/subcommands/metric_drain.rb +25 -5
- data/lib/aptible/cli/subcommands/operation.rb +7 -0
- data/lib/aptible/cli/subcommands/rebuild.rb +3 -0
- data/lib/aptible/cli/subcommands/restart.rb +3 -0
- data/lib/aptible/cli/subcommands/services.rb +12 -3
- data/lib/aptible/cli/subcommands/ssh.rb +3 -0
- data/lib/aptible/cli/version.rb +1 -1
- data/spec/aptible/cli/subcommands/apps_spec.rb +13 -1
- data/spec/aptible/cli/subcommands/config_spec.rb +4 -2
- data/spec/aptible/cli/subcommands/db_spec.rb +7 -1
- data/spec/aptible/cli/subcommands/endpoints_spec.rb +9 -3
- data/spec/aptible/cli/subcommands/environment_spec.rb +3 -1
- data/spec/aptible/cli/subcommands/log_drain_spec.rb +15 -2
- data/spec/aptible/cli/subcommands/maintenance_spec.rb +3 -2
- data/spec/aptible/cli/subcommands/metric_drain_spec.rb +15 -2
- data/spec/aptible/cli/subcommands/services_spec.rb +3 -1
- data/spec/fabricators/account_fabricator.rb +8 -0
- data/spec/fabricators/app_fabricator.rb +9 -0
- data/spec/fabricators/database_fabricator.rb +8 -0
- data/spec/fabricators/log_drain_fabricator.rb +8 -0
- data/spec/fabricators/metric_drain_fabricator.rb +8 -0
- data/spec/spec_helper.rb +9 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23bd0dde480e09b51d6876d15ff0628739d632197ae600bc2bc567bd54d7ee9
|
4
|
+
data.tar.gz: 7c2952e17c06a6c9593a5cbcbb3898e333d2c5e2a6d32bff053cd42798e87287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b41752dc657d784ed2cc6da0ed4bc2c54f730adc59b02de4120d30aed2c6626b93a25b6049551051a17f1f6c841c9cac200f70eb480c1330c37543440e3d431e
|
7
|
+
data.tar.gz: 0f3a5c06f634a87ff7768914f8d383a86bbee84a4c6dc511797f752bdc777f29bd4882d46e8b93e53124d35fba16e1a0589cae9355e16c17392c9026322e3b69
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/aptible/cli/agent.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'uri'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
require 'aptible/auth'
|
5
6
|
require 'thor'
|
@@ -8,6 +9,7 @@ require 'chronic_duration'
|
|
8
9
|
|
9
10
|
require_relative 'helpers/ssh'
|
10
11
|
require_relative 'helpers/token'
|
12
|
+
require_relative 'helpers/telemetry'
|
11
13
|
require_relative 'helpers/operation'
|
12
14
|
require_relative 'helpers/environment'
|
13
15
|
require_relative 'helpers/app'
|
@@ -80,7 +82,13 @@ module Aptible
|
|
80
82
|
|
81
83
|
def initialize(*)
|
82
84
|
nag_toolbelt unless toolbelt?
|
83
|
-
Aptible::Resource.configure
|
85
|
+
Aptible::Resource.configure do |conf|
|
86
|
+
conf.user_agent = version_string
|
87
|
+
level = Logger::WARN
|
88
|
+
debug_level = ENV['APTIBLE_DEBUG']
|
89
|
+
level = debug_level if debug_level
|
90
|
+
conf.logger.tap { |l| l.level = level }
|
91
|
+
end
|
84
92
|
warn_sso_enforcement
|
85
93
|
super
|
86
94
|
end
|
@@ -151,12 +151,27 @@ module Aptible
|
|
151
151
|
service
|
152
152
|
end
|
153
153
|
|
154
|
+
def apps_href
|
155
|
+
href = '/apps'
|
156
|
+
if Renderer.format != 'json'
|
157
|
+
href = '/apps?per_page=5000&no_embed=true'
|
158
|
+
end
|
159
|
+
href
|
160
|
+
end
|
161
|
+
|
162
|
+
def apps_all
|
163
|
+
Aptible::Api::App.all(
|
164
|
+
token: fetch_token,
|
165
|
+
href: apps_href
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
154
169
|
def apps_from_handle(handle, environment)
|
155
170
|
# TODO: This should probably use each_app for more efficiency.
|
156
171
|
if environment
|
157
172
|
environment.apps
|
158
173
|
else
|
159
|
-
|
174
|
+
apps_all
|
160
175
|
end.select { |a| a.handle == handle }
|
161
176
|
end
|
162
177
|
|
@@ -31,12 +31,27 @@ module Aptible
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
databases = Aptible::Api::Database.all(token: fetch_token)
|
34
|
+
def databases_href
|
35
|
+
href = '/databases'
|
36
|
+
if Renderer.format != 'json'
|
37
|
+
href = '/databases?per_page=5000&no_embed=true'
|
39
38
|
end
|
39
|
+
href
|
40
|
+
end
|
41
|
+
|
42
|
+
def databases_all
|
43
|
+
Aptible::Api::Database.all(
|
44
|
+
token: fetch_token,
|
45
|
+
href: databases_href
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def databases_from_handle(handle, environment)
|
50
|
+
databases = if environment
|
51
|
+
environment.databases
|
52
|
+
else
|
53
|
+
databases_all
|
54
|
+
end
|
40
55
|
databases.select { |a| a.handle == handle }
|
41
56
|
end
|
42
57
|
|
@@ -6,6 +6,14 @@ module Aptible
|
|
6
6
|
module Environment
|
7
7
|
include Helpers::Token
|
8
8
|
|
9
|
+
def environment_href
|
10
|
+
href = '/accounts'
|
11
|
+
if Renderer.format != 'json'
|
12
|
+
href = '/accounts?per_page=5000&no_embed=true'
|
13
|
+
end
|
14
|
+
href
|
15
|
+
end
|
16
|
+
|
9
17
|
def scoped_environments(options)
|
10
18
|
if options[:environment]
|
11
19
|
if (environment = environment_from_handle(options[:environment]))
|
@@ -14,7 +22,11 @@ module Aptible
|
|
14
22
|
raise Thor::Error, 'Specified account does not exist'
|
15
23
|
end
|
16
24
|
else
|
17
|
-
|
25
|
+
href = environment_href
|
26
|
+
Aptible::Api::Account.all(
|
27
|
+
token: fetch_token,
|
28
|
+
href: href
|
29
|
+
)
|
18
30
|
end
|
19
31
|
end
|
20
32
|
|
@@ -30,13 +42,26 @@ module Aptible
|
|
30
42
|
|
31
43
|
def environment_from_handle(handle)
|
32
44
|
return nil unless handle
|
33
|
-
|
45
|
+
href = environment_href
|
46
|
+
Aptible::Api::Account.all(token: fetch_token, href: href).find do |a|
|
34
47
|
a.handle == handle
|
35
48
|
end
|
36
49
|
end
|
37
50
|
|
51
|
+
def environment_map(accounts)
|
52
|
+
acc_map = {}
|
53
|
+
accounts.each do |account|
|
54
|
+
acc_map[account.links.self.href] = account
|
55
|
+
end
|
56
|
+
acc_map
|
57
|
+
end
|
58
|
+
|
38
59
|
def ensure_default_environment
|
39
|
-
|
60
|
+
href = environment_href
|
61
|
+
environments = Aptible::Api::Account.all(
|
62
|
+
token: fetch_token,
|
63
|
+
href: href
|
64
|
+
)
|
40
65
|
case environments.count
|
41
66
|
when 0
|
42
67
|
e = 'No environments. Go to https://app.aptible.com/ to proceed'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Aptible
|
6
|
+
module CLI
|
7
|
+
module Helpers
|
8
|
+
module Telemetry
|
9
|
+
def telemetry(cmd, options = {})
|
10
|
+
token_hash = decode_token
|
11
|
+
format = Renderer.format
|
12
|
+
format = 'text' if format.nil?
|
13
|
+
sub = token_hash[0]['sub']
|
14
|
+
parsed_url = URI.parse(sub)
|
15
|
+
path_components = parsed_url.path.split('/')
|
16
|
+
user_or_org_id = path_components.last
|
17
|
+
# https://github.com/aptible/aptible-resource/blob/7c3a79e6eee9c88aa7dbf332e550508f22a5b08d/lib/hyper_resource/modules/http.rb#L21
|
18
|
+
client = HTTPClient.new.tap do |c|
|
19
|
+
c.cookie_manager = nil
|
20
|
+
c.connect_timeout = 30
|
21
|
+
c.send_timeout = 45
|
22
|
+
c.keep_alive_timeout = 15
|
23
|
+
c.ssl_config.set_default_paths
|
24
|
+
end
|
25
|
+
|
26
|
+
value = {
|
27
|
+
'email' => token_hash[0]['email'],
|
28
|
+
'format' => format,
|
29
|
+
'cmd' => cmd,
|
30
|
+
'options' => options,
|
31
|
+
'version' => version_string,
|
32
|
+
# https://stackoverflow.com/a/73973555
|
33
|
+
'github' => ENV['GITHUB_ACTIONS'],
|
34
|
+
'gitlab' => ENV['GITLAB_CI'],
|
35
|
+
'travis' => ENV['TRAVIS'],
|
36
|
+
'circleci' => ENV['CIRCLECI'],
|
37
|
+
'ci' => ENV['CI']
|
38
|
+
}
|
39
|
+
|
40
|
+
begin
|
41
|
+
uri = URI('https://tuna.aptible.com/www/e')
|
42
|
+
client.get(
|
43
|
+
uri,
|
44
|
+
'id' => SecureRandom.uuid,
|
45
|
+
'user_id' => user_or_org_id,
|
46
|
+
'type' => 'cli_telemetry',
|
47
|
+
'url' => sub,
|
48
|
+
'value' => value
|
49
|
+
)
|
50
|
+
rescue
|
51
|
+
# since this is just for telemetry we don't want to notify
|
52
|
+
# user of an error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'aptible/auth'
|
2
|
+
require 'jwt'
|
2
3
|
|
3
4
|
require_relative 'config_path'
|
4
5
|
|
@@ -46,6 +47,11 @@ module Aptible
|
|
46
47
|
def token_file
|
47
48
|
File.join(aptible_config_path, 'tokens.json').freeze
|
48
49
|
end
|
50
|
+
|
51
|
+
def decode_token
|
52
|
+
tok = fetch_token
|
53
|
+
JWT.decode(tok, nil, false)
|
54
|
+
end
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
data/lib/aptible/cli/renderer.rb
CHANGED
@@ -108,6 +108,13 @@ module Aptible
|
|
108
108
|
attach_account(node, account)
|
109
109
|
end
|
110
110
|
|
111
|
+
def inject_database_minimal(node, database, account)
|
112
|
+
node.value('id', database.id)
|
113
|
+
node.value('handle', database.handle)
|
114
|
+
node.value('created_at', database.created_at)
|
115
|
+
attach_account(node, account)
|
116
|
+
end
|
117
|
+
|
111
118
|
def inject_database(node, database, account)
|
112
119
|
node.value('id', database.id)
|
113
120
|
node.value('handle', database.handle)
|
@@ -7,17 +7,34 @@ module Aptible
|
|
7
7
|
include Helpers::App
|
8
8
|
include Helpers::Environment
|
9
9
|
include Helpers::Token
|
10
|
+
include Helpers::Telemetry
|
10
11
|
|
11
12
|
desc 'apps', 'List all applications'
|
12
13
|
option :environment, aliases: '--env'
|
13
14
|
def apps
|
15
|
+
telemetry(__method__, options)
|
16
|
+
|
14
17
|
Formatter.render(Renderer.current) do |root|
|
15
18
|
root.grouped_keyed_list(
|
16
19
|
{ 'environment' => 'handle' },
|
17
20
|
'handle'
|
18
21
|
) do |node|
|
19
|
-
scoped_environments(options)
|
20
|
-
|
22
|
+
accounts = scoped_environments(options)
|
23
|
+
acc_map = environment_map(accounts)
|
24
|
+
|
25
|
+
if Renderer.format == 'json'
|
26
|
+
accounts.each do |account|
|
27
|
+
account.each_app do |app|
|
28
|
+
node.object do |n|
|
29
|
+
ResourceFormatter.inject_app(n, app, account)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
apps_all.each do |app|
|
35
|
+
account = acc_map[app.links.account.href]
|
36
|
+
next if account.nil?
|
37
|
+
|
21
38
|
node.object do |n|
|
22
39
|
ResourceFormatter.inject_app(n, app, account)
|
23
40
|
end
|
@@ -30,6 +47,8 @@ module Aptible
|
|
30
47
|
desc 'apps:create HANDLE', 'Create a new application'
|
31
48
|
option :environment, aliases: '--env'
|
32
49
|
define_method 'apps:create' do |handle|
|
50
|
+
telemetry(__method__, options.merge(handle: handle))
|
51
|
+
|
33
52
|
environment = ensure_environment(options)
|
34
53
|
app = environment.create_app(handle: handle)
|
35
54
|
|
@@ -56,6 +75,8 @@ module Aptible
|
|
56
75
|
option :container_profile, type: :string,
|
57
76
|
desc: 'Examples: m c r'
|
58
77
|
define_method 'apps:scale' do |type|
|
78
|
+
telemetry(__method__, options.merge(type: type))
|
79
|
+
|
59
80
|
service = ensure_service(options, type)
|
60
81
|
|
61
82
|
container_count = options[:container_count]
|
@@ -89,6 +110,8 @@ module Aptible
|
|
89
110
|
desc 'apps:deprovision', 'Deprovision an app'
|
90
111
|
app_options
|
91
112
|
define_method 'apps:deprovision' do
|
113
|
+
telemetry(__method__, options)
|
114
|
+
|
92
115
|
app = ensure_app(options)
|
93
116
|
CLI.logger.info "Deprovisioning #{app.handle}..."
|
94
117
|
op = app.create_operation!(type: 'deprovision')
|
@@ -108,6 +131,12 @@ module Aptible
|
|
108
131
|
' drain destinations, you must restart the app.'
|
109
132
|
option :environment, aliases: '--env'
|
110
133
|
define_method 'apps:rename' do |old_handle, new_handle|
|
134
|
+
opts = options.merge(
|
135
|
+
old_handle: old_handle,
|
136
|
+
new_handle: new_handle
|
137
|
+
)
|
138
|
+
telemetry(__method__, opts)
|
139
|
+
|
111
140
|
env = ensure_environment(options)
|
112
141
|
app = ensure_app(options.merge(app: old_handle))
|
113
142
|
app.update!(handle: new_handle)
|
@@ -6,6 +6,7 @@ module Aptible
|
|
6
6
|
thor.class_eval do
|
7
7
|
include Helpers::Token
|
8
8
|
include Helpers::Database
|
9
|
+
include Helpers::Telemetry
|
9
10
|
|
10
11
|
desc 'backup:restore BACKUP_ID ' \
|
11
12
|
'[--environment ENVIRONMENT_HANDLE] [--handle HANDLE] ' \
|
@@ -24,6 +25,8 @@ module Aptible
|
|
24
25
|
desc: 'Examples: m c r'
|
25
26
|
option :iops, type: :numeric
|
26
27
|
define_method 'backup:restore' do |backup_id|
|
28
|
+
telemetry(__method__, options.merge(backup_id: backup_id))
|
29
|
+
|
27
30
|
backup = Aptible::Api::Backup.find(backup_id, token: fetch_token)
|
28
31
|
raise Thor::Error, "Backup ##{backup_id} not found" if backup.nil?
|
29
32
|
|
@@ -74,6 +77,8 @@ module Aptible
|
|
74
77
|
default: '99y',
|
75
78
|
desc: 'Limit backups returned (example usage: 1w, 1y, etc.)'
|
76
79
|
define_method 'backup:list' do |handle|
|
80
|
+
telemetry(__method__, options.merge(handle: handle))
|
81
|
+
|
77
82
|
age = ChronicDuration.parse(options[:max_age])
|
78
83
|
raise Thor::Error, "Invalid age: #{options[:max_age]}" if age.nil?
|
79
84
|
min_created_at = Time.now - age
|
@@ -101,6 +106,8 @@ module Aptible
|
|
101
106
|
desc: 'Limit backups returned '\
|
102
107
|
'(example usage: 1w, 1y, etc.)'
|
103
108
|
define_method 'backup:orphaned' do
|
109
|
+
telemetry(__method__, options)
|
110
|
+
|
104
111
|
age = ChronicDuration.parse(options[:max_age])
|
105
112
|
raise Thor::Error, "Invalid age: #{options[:max_age]}" if age.nil?
|
106
113
|
min_created_at = Time.now - age
|
@@ -126,6 +133,8 @@ module Aptible
|
|
126
133
|
desc 'backup:purge BACKUP_ID',
|
127
134
|
'Permanently delete a backup and any copies of it'
|
128
135
|
define_method 'backup:purge' do |backup_id|
|
136
|
+
telemetry(__method__, options.merge(backup_id: backup_id))
|
137
|
+
|
129
138
|
backup = Aptible::Api::Backup.find(backup_id, token: fetch_token)
|
130
139
|
raise Thor::Error, "Backup ##{backup_id} not found" if backup.nil?
|
131
140
|
|
@@ -10,10 +10,13 @@ module Aptible
|
|
10
10
|
thor.class_eval do
|
11
11
|
include Helpers::Environment
|
12
12
|
include Term::ANSIColor
|
13
|
+
include Helpers::Telemetry
|
13
14
|
|
14
15
|
desc 'backup_retention_policy [ENVIRONMENT_HANDLE]',
|
15
16
|
'Show the current backup retention policy for the environment'
|
16
17
|
define_method 'backup_retention_policy' do |env|
|
18
|
+
telemetry(__method__, options.merge(env: env))
|
19
|
+
|
17
20
|
account = ensure_environment(environment: env)
|
18
21
|
policy = account.backup_retention_policies.first
|
19
22
|
unless policy
|
@@ -52,6 +55,8 @@ module Aptible
|
|
52
55
|
desc: 'Do not prompt for confirmation if the new policy ' \
|
53
56
|
'retains fewer backups than the current policy'
|
54
57
|
define_method 'backup_retention_policy:set' do |env|
|
58
|
+
telemetry(__method__, options.merge(env: env))
|
59
|
+
|
55
60
|
if options.empty?
|
56
61
|
raise Thor::Error,
|
57
62
|
'Please specify at least one attribute to change'
|
@@ -7,10 +7,13 @@ module Aptible
|
|
7
7
|
thor.class_eval do
|
8
8
|
include Helpers::Operation
|
9
9
|
include Helpers::App
|
10
|
+
include Helpers::Telemetry
|
10
11
|
|
11
12
|
desc 'config', "Print an app's current configuration"
|
12
13
|
app_options
|
13
14
|
def config
|
15
|
+
telemetry(__method__, options)
|
16
|
+
|
14
17
|
app = ensure_app(options)
|
15
18
|
config = app.current_configuration
|
16
19
|
env = config ? config.env : {}
|
@@ -32,6 +35,8 @@ module Aptible
|
|
32
35
|
"Print a specific key within an app's current configuration"
|
33
36
|
app_options
|
34
37
|
define_method 'config:get' do |*args|
|
38
|
+
telemetry(__method__, options)
|
39
|
+
|
35
40
|
app = ensure_app(options)
|
36
41
|
config = app.current_configuration
|
37
42
|
env = config ? config.env : {}
|
@@ -49,6 +54,8 @@ module Aptible
|
|
49
54
|
'Add an ENV variable to an app'
|
50
55
|
app_options
|
51
56
|
define_method 'config:add' do |*args|
|
57
|
+
telemetry(__method__, options)
|
58
|
+
|
52
59
|
# FIXME: define_method - ?! Seriously, WTF Thor.
|
53
60
|
app = ensure_app(options)
|
54
61
|
env = extract_env(args)
|
@@ -61,6 +68,7 @@ module Aptible
|
|
61
68
|
'Add an ENV variable to an app'
|
62
69
|
app_options
|
63
70
|
define_method 'config:set' do |*args|
|
71
|
+
telemetry(__method__, options)
|
64
72
|
send('config:add', *args)
|
65
73
|
end
|
66
74
|
|
@@ -68,6 +76,8 @@ module Aptible
|
|
68
76
|
'Remove an ENV variable from an app'
|
69
77
|
app_options
|
70
78
|
define_method 'config:rm' do |*args|
|
79
|
+
telemetry(__method__, options)
|
80
|
+
|
71
81
|
# FIXME: define_method - ?! Seriously, WTF Thor.
|
72
82
|
app = ensure_app(options)
|
73
83
|
env = Hash[args.map do |arg|
|
@@ -84,6 +94,7 @@ module Aptible
|
|
84
94
|
'Remove an ENV variable from an app'
|
85
95
|
app_options
|
86
96
|
define_method 'config:unset' do |*args|
|
97
|
+
telemetry(__method__, options)
|
87
98
|
send('config:rm', *args)
|
88
99
|
end
|
89
100
|
end
|
@@ -12,19 +12,40 @@ module Aptible
|
|
12
12
|
include Helpers::Database
|
13
13
|
include Helpers::Token
|
14
14
|
include Term::ANSIColor
|
15
|
+
include Helpers::Telemetry
|
15
16
|
|
16
17
|
desc 'db:list', 'List all databases'
|
17
18
|
option :environment, aliases: '--env'
|
18
19
|
define_method 'db:list' do
|
20
|
+
telemetry(__method__, options)
|
21
|
+
|
19
22
|
Formatter.render(Renderer.current) do |root|
|
20
23
|
root.grouped_keyed_list(
|
21
24
|
{ 'environment' => 'handle' },
|
22
25
|
'handle'
|
23
26
|
) do |node|
|
24
|
-
scoped_environments(options)
|
25
|
-
|
27
|
+
accounts = scoped_environments(options)
|
28
|
+
acc_map = environment_map(accounts)
|
29
|
+
|
30
|
+
if Renderer.format == 'json'
|
31
|
+
accounts.each do |account|
|
32
|
+
account.each_database do |db|
|
33
|
+
node.object do |n|
|
34
|
+
ResourceFormatter.inject_database(n, db, account)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
databases_all.each do |db|
|
40
|
+
account = acc_map[db.links.account.href]
|
41
|
+
next if account.nil?
|
42
|
+
|
26
43
|
node.object do |n|
|
27
|
-
ResourceFormatter.
|
44
|
+
ResourceFormatter.inject_database_minimal(
|
45
|
+
n,
|
46
|
+
db,
|
47
|
+
account
|
48
|
+
)
|
28
49
|
end
|
29
50
|
end
|
30
51
|
end
|
@@ -34,6 +55,8 @@ module Aptible
|
|
34
55
|
|
35
56
|
desc 'db:versions', 'List available database versions'
|
36
57
|
define_method 'db:versions' do
|
58
|
+
telemetry(__method__, options)
|
59
|
+
|
37
60
|
Formatter.render(Renderer.current) do |root|
|
38
61
|
root.grouped_keyed_list('type', 'version') do |node|
|
39
62
|
Aptible::Api::DatabaseImage.all(
|
@@ -68,6 +91,8 @@ module Aptible
|
|
68
91
|
desc: 'Examples: m c r'
|
69
92
|
option :iops, type: :numeric
|
70
93
|
define_method 'db:create' do |handle|
|
94
|
+
telemetry(__method__, options.merge(handle: handle))
|
95
|
+
|
71
96
|
account = ensure_environment(options)
|
72
97
|
|
73
98
|
db_opts = {
|
@@ -128,6 +153,12 @@ module Aptible
|
|
128
153
|
desc 'db:clone SOURCE DEST', 'Clone a database to create a new one'
|
129
154
|
option :environment, aliases: '--env'
|
130
155
|
define_method 'db:clone' do |source_handle, dest_handle|
|
156
|
+
opts = options.merge(
|
157
|
+
source_handle: source_handle,
|
158
|
+
dest_handle: dest_handle
|
159
|
+
)
|
160
|
+
telemetry(__method__, opts)
|
161
|
+
|
131
162
|
# TODO: Deprecate + recommend backup
|
132
163
|
source = ensure_database(options.merge(db: source_handle))
|
133
164
|
database = clone_database(source, dest_handle)
|
@@ -150,6 +181,12 @@ module Aptible
|
|
150
181
|
desc: 'Examples: m c r'
|
151
182
|
option :iops, type: :numeric
|
152
183
|
define_method 'db:replicate' do |source_handle, dest_handle|
|
184
|
+
opts = options.merge(
|
185
|
+
source_handle: source_handle,
|
186
|
+
dest_handle: dest_handle
|
187
|
+
)
|
188
|
+
telemetry(__method__, opts)
|
189
|
+
|
153
190
|
source = ensure_database(options.merge(db: source_handle))
|
154
191
|
|
155
192
|
if options[:logical]
|
@@ -193,6 +230,8 @@ module Aptible
|
|
193
230
|
'Dump a remote database to file'
|
194
231
|
option :environment, aliases: '--env'
|
195
232
|
define_method 'db:dump' do |handle, *dump_options|
|
233
|
+
telemetry(__method__, options.merge(handle: handle))
|
234
|
+
|
196
235
|
database = ensure_database(options.merge(db: handle))
|
197
236
|
with_postgres_tunnel(database) do |url|
|
198
237
|
filename = "#{handle}.dump"
|
@@ -207,6 +246,12 @@ module Aptible
|
|
207
246
|
option :environment, aliases: '--env'
|
208
247
|
option :on_error_stop, type: :boolean
|
209
248
|
define_method 'db:execute' do |handle, sql_path|
|
249
|
+
opts = options.merge(
|
250
|
+
handle: handle,
|
251
|
+
sql_path: sql_path
|
252
|
+
)
|
253
|
+
telemetry(__method__, opts)
|
254
|
+
|
210
255
|
database = ensure_database(options.merge(db: handle))
|
211
256
|
with_postgres_tunnel(database) do |url|
|
212
257
|
CLI.logger.info "Executing #{sql_path} against #{handle}"
|
@@ -221,6 +266,8 @@ module Aptible
|
|
221
266
|
option :port, type: :numeric
|
222
267
|
option :type, type: :string
|
223
268
|
define_method 'db:tunnel' do |handle|
|
269
|
+
telemetry(__method__, options.merge(handle: handle))
|
270
|
+
|
224
271
|
desired_port = Integer(options[:port] || 0)
|
225
272
|
database = ensure_database(options.merge(db: handle))
|
226
273
|
|
@@ -264,6 +311,8 @@ module Aptible
|
|
264
311
|
desc 'db:deprovision HANDLE', 'Deprovision a database'
|
265
312
|
option :environment, aliases: '--env'
|
266
313
|
define_method 'db:deprovision' do |handle|
|
314
|
+
telemetry(__method__, options.merge(handle: handle))
|
315
|
+
|
267
316
|
database = ensure_database(options.merge(db: handle))
|
268
317
|
CLI.logger.info "Deprovisioning #{database.handle}..."
|
269
318
|
op = database.create_operation!(type: 'deprovision')
|
@@ -280,6 +329,8 @@ module Aptible
|
|
280
329
|
desc 'db:backup HANDLE', 'Backup a database'
|
281
330
|
option :environment, aliases: '--env'
|
282
331
|
define_method 'db:backup' do |handle|
|
332
|
+
telemetry(__method__, options.merge(handle: handle))
|
333
|
+
|
283
334
|
database = ensure_database(options.merge(db: handle))
|
284
335
|
CLI.logger.info "Backing up #{database.handle}..."
|
285
336
|
op = database.create_operation!(type: 'backup')
|
@@ -289,6 +340,8 @@ module Aptible
|
|
289
340
|
desc 'db:reload HANDLE', 'Reload a database'
|
290
341
|
option :environment, aliases: '--env'
|
291
342
|
define_method 'db:reload' do |handle|
|
343
|
+
telemetry(__method__, options.merge(handle: handle))
|
344
|
+
|
292
345
|
database = ensure_database(options.merge(db: handle))
|
293
346
|
CLI.logger.info "Reloading #{database.handle}..."
|
294
347
|
op = database.create_operation!(type: 'reload')
|
@@ -309,6 +362,8 @@ module Aptible
|
|
309
362
|
option :iops, type: :numeric
|
310
363
|
option :volume_type
|
311
364
|
define_method 'db:restart' do |handle|
|
365
|
+
telemetry(__method__, options.merge(handle: handle))
|
366
|
+
|
312
367
|
database = ensure_database(options.merge(db: handle))
|
313
368
|
|
314
369
|
opts = {
|
@@ -339,6 +394,8 @@ module Aptible
|
|
339
394
|
option :iops, type: :numeric
|
340
395
|
option :volume_type
|
341
396
|
define_method 'db:modify' do |handle|
|
397
|
+
telemetry(__method__, options.merge(handle: handle))
|
398
|
+
|
342
399
|
database = ensure_database(options.merge(db: handle))
|
343
400
|
|
344
401
|
opts = {
|
@@ -357,6 +414,8 @@ module Aptible
|
|
357
414
|
option :environment, aliases: '--env'
|
358
415
|
option :type, type: :string
|
359
416
|
define_method 'db:url' do |handle|
|
417
|
+
telemetry(__method__, options.merge(handle: handle))
|
418
|
+
|
360
419
|
database = ensure_database(options.merge(db: handle))
|
361
420
|
credential = find_credential(database, options[:type])
|
362
421
|
|
@@ -373,6 +432,12 @@ module Aptible
|
|
373
432
|
' metric drain destinations, you must reload the database.'
|
374
433
|
option :environment, aliases: '--env'
|
375
434
|
define_method 'db:rename' do |old_handle, new_handle|
|
435
|
+
opts = options.merge(
|
436
|
+
old_handle: old_handle,
|
437
|
+
new_handle: new_handle
|
438
|
+
)
|
439
|
+
telemetry(__method__, opts)
|
440
|
+
|
376
441
|
env = ensure_environment(options)
|
377
442
|
db = ensure_database(options.merge(db: old_handle))
|
378
443
|
db.update!(handle: new_handle)
|