aptible-cli 0.18.2 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf958faed8401636f811f03296e187e9af011fef3d6ce6aa3bc7f2aee315d5c8
4
- data.tar.gz: 36214902974167a2748685d63fa9d1d659c64d4f752e3b813aeb7adb907f601b
3
+ metadata.gz: bdd31b147b7a6e31ec8a563120edfeeb65675e6fc3207a3f7a67dfd36b34c852
4
+ data.tar.gz: d984d2e4aa162a24c44acf7a3ea7854a2dd14b7896afbfa7851b1c2d87b2310d
5
5
  SHA512:
6
- metadata.gz: a1a85e655dd7e0d3267035baca9c8c5898193f524a3ac842961ec62aa0e3b4f951c89a0a1dd5a1adcf80b840b729dafb90238214d6224eff1fd524a54fb90b21
7
- data.tar.gz: d85e946cb9adee2314f31078029033bd62ea44a0ef23d673c434e422817c17cf7094bff714ce5b6862c52135f30b030ae7d52a4f72e8052f2fc99b372b3016ca
6
+ metadata.gz: 70854f3f9dbdd1af2c90c739e05baa72b127c4cadfea8e1d889f2b00a81fcbc56a2bf779d51e621371e38e3312110a2a1324d3edc4b2514bd944f940f9f1e74c
7
+ data.tar.gz: 42a946fb3e79f01f951f480aa788d356560f97887ac1613dd5d3c210311873daaabfa9b30d6ebb542185ad264b5521f7f72a267073958c2adc9bffb2445e8f11
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'pry', github: 'fancyremarker/pry', branch: 'aptible'
3
+ gem 'pry',
4
+ git: 'https://github.com/fancyremarker/pry.git',
5
+ branch: 'aptible'
6
+
4
7
  gem 'activesupport', '~> 4.0'
5
8
  gem 'rack', '~> 1.0'
6
9
 
data/README.md CHANGED
@@ -28,56 +28,70 @@ From `aptible help`:
28
28
  <!-- BEGIN USAGE -->
29
29
  ```
30
30
  Commands:
31
- aptible apps # List all applications
32
- aptible apps:create HANDLE # Create a new application
33
- aptible apps:deprovision # Deprovision an app
34
- aptible apps:scale SERVICE [--container-count COUNT] [--container-size SIZE_MB] # Scale a service
35
- aptible backup:list DB_HANDLE # List backups for a database
36
- aptible backup:orphaned # List backups associated with deprovisioned databases
37
- aptible backup:purge BACKUP_ID # Permanently delete a backup and any copies of it
38
- aptible backup:restore BACKUP_ID [--environment ENVIRONMENT_HANDLE] [--handle HANDLE] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Restore a backup
39
- aptible config # Print an app's current configuration
40
- aptible config:add [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
41
- aptible config:rm [VAR1] [VAR2] [...] # Remove an ENV variable from an app
42
- aptible config:set [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
43
- aptible config:unset [VAR1] [VAR2] [...] # Remove an ENV variable from an app
44
- aptible db:backup HANDLE # Backup a database
45
- aptible db:clone SOURCE DEST # Clone a database to create a new one
46
- aptible db:create HANDLE [--type TYPE] [--version VERSION] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Create a new database
47
- aptible db:deprovision HANDLE # Deprovision a database
48
- aptible db:dump HANDLE [pg_dump options] # Dump a remote database to file
49
- aptible db:execute HANDLE SQL_FILE [--on-error-stop] # Executes sql against a database
50
- aptible db:list # List all databases
51
- aptible db:modify HANDLE [--iops IOPS] [--volume-type [gp2, gp3]] # Modify a database disk
52
- aptible db:reload HANDLE # Reload a database
53
- aptible db:replicate HANDLE REPLICA_HANDLE [--container-size SIZE_MB] [--disk-size SIZE_GB] [--logical --version VERSION] [--key-arn KEY_ARN] # Create a replica/follower of a database
54
- aptible db:restart HANDLE [--container-size SIZE_MB] [--disk-size SIZE_GB][--iops IOPS] [--volume-type [gp2, gp3]] # Restart a database
55
- aptible db:tunnel HANDLE # Create a local tunnel to a database
56
- aptible db:url HANDLE # Display a database URL
57
- aptible db:versions # List available database versions
58
- aptible deploy [OPTIONS] [VAR1=VAL1] [VAR2=VAL2] [...] # Deploy an app
59
- aptible domains # Print an app's current virtual domains - DEPRECATED
60
- aptible endpoints:database:create DATABASE # Create a Database Endpoint
61
- aptible endpoints:deprovision [--app APP | --database DATABASE] ENDPOINT_HOSTNAME # Deprovision an App or Database Endpoint
62
- aptible endpoints:https:create [--app APP] SERVICE # Create an App HTTPS Endpoint
63
- aptible endpoints:https:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App HTTPS Endpoint
64
- aptible endpoints:list [--app APP | --database DATABASE] # List Endpoints for an App or Database
65
- aptible endpoints:renew [--app APP] ENDPOINT_HOSTNAME # Renew an App Managed TLS Endpoint
66
- aptible endpoints:tcp:create [--app APP] SERVICE # Create an App TCP Endpoint
67
- aptible endpoints:tcp:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TCP Endpoint
68
- aptible endpoints:tls:create [--app APP] SERVICE # Create an App TLS Endpoint
69
- aptible endpoints:tls:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TLS Endpoint
70
- aptible environment:ca_cert # Retrieve the CA certificate associated with the environment
71
- aptible environment:list # List all environments
72
- aptible help [COMMAND] # Describe available commands or one specific command
73
- aptible login # Log in to Aptible
74
- aptible logs [--app APP | --database DATABASE] # Follows logs from a running app or database
75
- aptible operation:cancel OPERATION_ID # Cancel a running operation
76
- aptible rebuild # Rebuild an app, and restart its services
77
- aptible restart # Restart all services associated with an app
78
- aptible services # List Services for an App
79
- aptible ssh [COMMAND] # Run a command against an app
80
- aptible version # Print Aptible CLI version
31
+ aptible apps # List all applications
32
+ aptible apps:create HANDLE # Create a new application
33
+ aptible apps:deprovision # Deprovision an app
34
+ aptible apps:scale SERVICE [--container-count COUNT] [--container-size SIZE_MB] # Scale a service
35
+ aptible backup:list DB_HANDLE # List backups for a database
36
+ aptible backup:orphaned # List backups associated with deprovisioned databases
37
+ aptible backup:purge BACKUP_ID # Permanently delete a backup and any copies of it
38
+ aptible backup:restore BACKUP_ID [--environment ENVIRONMENT_HANDLE] [--handle HANDLE] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Restore a backup
39
+ aptible config # Print an app's current configuration
40
+ aptible config:add [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
41
+ aptible config:rm [VAR1] [VAR2] [...] # Remove an ENV variable from an app
42
+ aptible config:set [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
43
+ aptible config:unset [VAR1] [VAR2] [...] # Remove an ENV variable from an app
44
+ aptible db:backup HANDLE # Backup a database
45
+ aptible db:clone SOURCE DEST # Clone a database to create a new one
46
+ aptible db:create HANDLE [--type TYPE] [--version VERSION] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Create a new database
47
+ aptible db:deprovision HANDLE # Deprovision a database
48
+ aptible db:dump HANDLE [pg_dump options] # Dump a remote database to file
49
+ aptible db:execute HANDLE SQL_FILE [--on-error-stop] # Executes sql against a database
50
+ aptible db:list # List all databases
51
+ aptible db:modify HANDLE [--iops IOPS] [--volume-type [gp2, gp3]] # Modify a database disk
52
+ aptible db:reload HANDLE # Reload a database
53
+ aptible db:replicate HANDLE REPLICA_HANDLE [--container-size SIZE_MB] [--disk-size SIZE_GB] [--logical --version VERSION] [--key-arn KEY_ARN] # Create a replica/follower of a database
54
+ aptible db:restart HANDLE [--container-size SIZE_MB] [--disk-size SIZE_GB] [--iops IOPS] [--volume-type [gp2, gp3]] # Restart a database
55
+ aptible db:tunnel HANDLE # Create a local tunnel to a database
56
+ aptible db:url HANDLE # Display a database URL
57
+ aptible db:versions # List available database versions
58
+ aptible deploy [OPTIONS] [VAR1=VAL1] [VAR2=VAL2] [...] # Deploy an app
59
+ aptible endpoints:database:create DATABASE # Create a Database Endpoint
60
+ aptible endpoints:database:modify --database DATABASE ENDPOINT_HOSTNAME # Modify a Database Endpoint
61
+ aptible endpoints:deprovision [--app APP | --database DATABASE] ENDPOINT_HOSTNAME # Deprovision an App or Database Endpoint
62
+ aptible endpoints:https:create [--app APP] SERVICE # Create an App HTTPS Endpoint
63
+ aptible endpoints:https:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App HTTPS Endpoint
64
+ aptible endpoints:list [--app APP | --database DATABASE] # List Endpoints for an App or Database
65
+ aptible endpoints:renew [--app APP] ENDPOINT_HOSTNAME # Renew an App Managed TLS Endpoint
66
+ aptible endpoints:tcp:create [--app APP] SERVICE # Create an App TCP Endpoint
67
+ aptible endpoints:tcp:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TCP Endpoint
68
+ aptible endpoints:tls:create [--app APP] SERVICE # Create an App TLS Endpoint
69
+ aptible endpoints:tls:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TLS Endpoint
70
+ aptible environment:ca_cert # Retrieve the CA certificate associated with the environment
71
+ aptible environment:list # List all environments
72
+ aptible help [COMMAND] # Describe available commands or one specific command
73
+ aptible log_drain:create:datadog HANDLE --url DATADOG_URL --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a Datadog Log Drain
74
+ aptible log_drain:create:elasticsearch HANDLE --db DATABASE_HANDLE --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create an Elasticsearch Log Drain
75
+ aptible log_drain:create:https HANDLE --url URL --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a HTTPS Drain
76
+ aptible log_drain:create:logdna HANDLE --url LOGDNA_URL --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a LogDNA Log Drain
77
+ aptible log_drain:create:papertrail HANDLE --host PAPERTRAIL_HOST --port PAPERTRAIL_PORT --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a Papertrail Log Drain
78
+ aptible log_drain:create:sumologic HANDLE --url SUMOLOGIC_URL --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a Sumologic Drain
79
+ aptible log_drain:create:syslog HANDLE --host SYSLOG_HOST --port SYSLOG_PORT [--token TOKEN] --environment ENVIRONMENT [--drain-apps true/false] [--drain_databases true/false] [--drain_ephemeral_sessions true/false] [--drain_proxies true/false] # Create a Papertrail Log Drain
80
+ aptible log_drain:deprovision HANDLE --environment ENVIRONMENT # Deprovisions a log drain
81
+ aptible log_drain:list # List all Log Drains
82
+ aptible login # Log in to Aptible
83
+ aptible logs [--app APP | --database DATABASE] # Follows logs from a running app or database
84
+ aptible metric_drain:create:datadog HANDLE --api_key DATADOG_API_KEY --site DATADOG_SITE --environment ENVIRONMENT # Create a Datadog Metric Drain
85
+ aptible metric_drain:create:influxdb HANDLE --db DATABASE_HANDLE --environment ENVIRONMENT # Create an InfluxDB Metric Drain
86
+ aptible metric_drain:create:influxdb:custom HANDLE --username USERNAME --password PASSWORD --url URL_INCLUDING_PORT --db INFLUX_DATABASE_NAME --environment ENVIRONMENT # Create an InfluxDB Metric Drain
87
+ aptible metric_drain:deprovision HANDLE --environment ENVIRONMENT # Deprovisions a Metric Drain
88
+ aptible metric_drain:list # List all Metric Drains
89
+ aptible operation:cancel OPERATION_ID # Cancel a running operation
90
+ aptible rebuild # Rebuild an app, and restart its services
91
+ aptible restart # Restart all services associated with an app
92
+ aptible services # List Services for an App
93
+ aptible ssh [COMMAND] # Run a command against an app
94
+ aptible version # Print Aptible CLI version
81
95
  ```
82
96
  <!-- END USAGE -->
83
97
 
data/aptible-cli.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'aptible-resource', '~> 1.1'
24
24
  spec.add_dependency 'aptible-api', '~> 1.2'
25
- spec.add_dependency 'aptible-auth', '~> 1.2.3'
25
+ spec.add_dependency 'aptible-auth', '~> 1.2.4'
26
26
  spec.add_dependency 'aptible-billing', '~> 1.0'
27
27
  spec.add_dependency 'thor', '~> 0.20.0'
28
28
  spec.add_dependency 'git'
@@ -18,11 +18,13 @@ require_relative 'helpers/vhost/option_set_builder'
18
18
  require_relative 'helpers/tunnel'
19
19
  require_relative 'helpers/system'
20
20
  require_relative 'helpers/security_key'
21
+ require_relative 'helpers/config_path'
22
+ require_relative 'helpers/log_drain'
23
+ require_relative 'helpers/metric_drain'
21
24
 
22
25
  require_relative 'subcommands/apps'
23
26
  require_relative 'subcommands/config'
24
27
  require_relative 'subcommands/db'
25
- require_relative 'subcommands/domains'
26
28
  require_relative 'subcommands/environment'
27
29
  require_relative 'subcommands/logs'
28
30
  require_relative 'subcommands/rebuild'
@@ -34,6 +36,8 @@ require_relative 'subcommands/backup'
34
36
  require_relative 'subcommands/operation'
35
37
  require_relative 'subcommands/inspect'
36
38
  require_relative 'subcommands/endpoints'
39
+ require_relative 'subcommands/log_drain'
40
+ require_relative 'subcommands/metric_drain'
37
41
 
38
42
  module Aptible
39
43
  module CLI
@@ -43,10 +47,10 @@ module Aptible
43
47
  include Helpers::Token
44
48
  include Helpers::Ssh
45
49
  include Helpers::System
50
+ include Helpers::ConfigPath
46
51
  include Subcommands::Apps
47
52
  include Subcommands::Config
48
53
  include Subcommands::DB
49
- include Subcommands::Domains
50
54
  include Subcommands::Environment
51
55
  include Subcommands::Logs
52
56
  include Subcommands::Rebuild
@@ -58,6 +62,8 @@ module Aptible
58
62
  include Subcommands::Operation
59
63
  include Subcommands::Inspect
60
64
  include Subcommands::Endpoints
65
+ include Subcommands::LogDrain
66
+ include Subcommands::MetricDrain
61
67
 
62
68
  # Forward return codes on failures.
63
69
  def self.exit_on_failure?
@@ -209,7 +215,7 @@ module Aptible
209
215
  # further: to do so, edit the file `.aptible/nag_toolbelt` and put a
210
216
  # timestamp far into the future. For example, writing 1577836800 will
211
217
  # disable the warning until 2020.
212
- nag_file = File.join ENV['HOME'], '.aptible', 'nag_toolbelt'
218
+ nag_file = File.join aptible_config_path, 'nag_toolbelt'
213
219
  nag_frequency = 12.hours
214
220
 
215
221
  last_nag = begin
@@ -0,0 +1,11 @@
1
+ module Aptible
2
+ module CLI
3
+ module Helpers
4
+ module ConfigPath
5
+ def aptible_config_path
6
+ ENV['APTIBLE_CONFIG_PATH'] || (File.join ENV['HOME'], '.aptible')
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,85 @@
1
+ module Aptible
2
+ module CLI
3
+ module Helpers
4
+ module LogDrain
5
+ include Helpers::Token
6
+
7
+ def create_log_drain(account, drain_opts)
8
+ drain = account.create_log_drain!(drain_opts)
9
+ op = drain.create_operation(type: :provision)
10
+
11
+ if op.errors.any?
12
+ # NOTE: If we fail to provision the log drain, we should try and
13
+ # clean it up immediately.
14
+ drain.create_operation(type: :deprovision)
15
+ raise Thor::Error, op.errors.full_messages.first
16
+ end
17
+
18
+ attach_to_operation_logs(op)
19
+ end
20
+
21
+ def create_https_based_log_drain(handle, options, url_format_msg: nil)
22
+ account = ensure_environment(options)
23
+ url = ensure_url(options, url_format_msg: url_format_msg)
24
+
25
+ opts = {
26
+ handle: handle,
27
+ url: url,
28
+ drain_apps: options[:drain_apps],
29
+ drain_databases: options[:drain_databases],
30
+ drain_ephemeral_sessions: options[:drain_ephemeral_sessions],
31
+ drain_proxies: options[:drain_proxies],
32
+ drain_type: :https_post
33
+ }
34
+ create_log_drain(account, opts)
35
+ end
36
+
37
+ def create_syslog_based_log_drain(handle, options)
38
+ account = ensure_environment(options)
39
+
40
+ opts = {
41
+ handle: handle,
42
+ drain_host: options[:host],
43
+ drain_port: options[:port],
44
+ logging_token: options[:token],
45
+ drain_apps: options[:drain_apps],
46
+ drain_databases: options[:drain_databases],
47
+ drain_ephemeral_sessions: options[:drain_ephemeral_sessions],
48
+ drain_proxies: options[:drain_proxies],
49
+ drain_type: :syslog_tls_tcp
50
+ }
51
+ create_log_drain(account, opts)
52
+ end
53
+
54
+ def ensure_url(options, url_format_msg: nil)
55
+ msg = '--url is required.'
56
+ msg = "#{msg} #{url_format_msg}" unless url_format_msg.nil?
57
+
58
+ url = options[:url]
59
+ raise Thor::Error, msg if url.nil?
60
+
61
+ # API already does url validation, so I'm not going
62
+ # to duplicate that logic here, even if it would
63
+ # get us an error faster
64
+ url
65
+ end
66
+
67
+ def ensure_log_drain(account, handle)
68
+ drains = account.log_drains.select { |d| d.handle == handle }
69
+
70
+ if drains.empty?
71
+ raise Thor::Error, "No drain found with handle #{handle}"
72
+ end
73
+
74
+ # Log Drain handles are globally unique, so this is excessive
75
+ unless drains.length == 1
76
+ raise Thor::Error, "#{drains.length} drains found with handle "\
77
+ "#{handle}"
78
+ end
79
+
80
+ drains.first
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,39 @@
1
+ module Aptible
2
+ module CLI
3
+ module Helpers
4
+ module MetricDrain
5
+ include Helpers::Token
6
+
7
+ def create_metric_drain(account, drain_opts)
8
+ drain = account.create_metric_drain!(drain_opts)
9
+ op = drain.create_operation(type: :provision)
10
+
11
+ if op.errors.any?
12
+ # NOTE: If we fail to provision the log drain, we should try and
13
+ # clean it up immediately.
14
+ drain.create_operation(type: :deprovision)
15
+ raise Thor::Error, op.errors.full_messages.first
16
+ end
17
+
18
+ attach_to_operation_logs(op)
19
+ end
20
+
21
+ def ensure_metric_drain(account, handle)
22
+ drains = account.metric_drains.select { |d| d.handle == handle }
23
+
24
+ if drains.empty?
25
+ raise Thor::Error, "No drain found with handle #{handle}"
26
+ end
27
+
28
+ # Metric Drain handles are globally unique, so this is excessive
29
+ unless drains.length == 1
30
+ raise Thor::Error, "#{drains.length} drains found with handle "\
31
+ "#{handle}"
32
+ end
33
+
34
+ drains.first
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,7 +1,11 @@
1
+ require_relative 'config_path'
2
+
1
3
  module Aptible
2
4
  module CLI
3
5
  module Helpers
4
6
  module Ssh
7
+ include Helpers::ConfigPath
8
+
5
9
  def connect_to_ssh_portal(operation, *extra_ssh_args)
6
10
  # NOTE: This is a little tricky to get rigt, so before you make any
7
11
  # changes, read this.
@@ -126,7 +130,7 @@ module Aptible
126
130
  end
127
131
 
128
132
  def ssh_dir
129
- File.join ENV['HOME'], '.aptible', 'ssh'
133
+ File.join aptible_config_path, 'ssh'
130
134
  end
131
135
 
132
136
  def ssh_config_file
@@ -1,9 +1,13 @@
1
1
  require 'aptible/auth'
2
2
 
3
+ require_relative 'config_path'
4
+
3
5
  module Aptible
4
6
  module CLI
5
7
  module Helpers
6
8
  module Token
9
+ include Helpers::ConfigPath
10
+
7
11
  TOKEN_ENV_VAR = 'APTIBLE_ACCESS_TOKEN'.freeze
8
12
 
9
13
  def fetch_token
@@ -40,7 +44,7 @@ module Aptible
40
44
  end
41
45
 
42
46
  def token_file
43
- File.join ENV['HOME'], '.aptible', 'tokens.json'
47
+ File.join(aptible_config_path, 'tokens.json').freeze
44
48
  end
45
49
  end
46
50
  end
@@ -22,7 +22,9 @@ module Aptible
22
22
  thor.instance_exec(self) do |builder|
23
23
  option :environment
24
24
 
25
- if builder.app?
25
+ if builder.database?
26
+ option :database
27
+ elsif builder.app?
26
28
  app_options
27
29
 
28
30
  if builder.create?
@@ -32,11 +34,6 @@ module Aptible
32
34
  desc: 'Enable Default Domain on this Endpoint'
33
35
  )
34
36
 
35
- option(
36
- :internal,
37
- type: :boolean,
38
- desc: 'Restrict this Endpoint to internal traffic'
39
- )
40
37
  end
41
38
 
42
39
  if builder.ports?
@@ -56,6 +53,14 @@ module Aptible
56
53
  end
57
54
  end
58
55
 
56
+ if builder.create?
57
+ option(
58
+ :internal,
59
+ type: :boolean,
60
+ desc: 'Restrict this Endpoint to internal traffic'
61
+ )
62
+ end
63
+
59
64
  option(
60
65
  :ip_whitelist,
61
66
  type: :array,
@@ -151,6 +156,12 @@ module Aptible
151
156
  end
152
157
 
153
158
  options.delete(:app)
159
+ elsif database?
160
+ params[:internal] = options.delete(:internal) do
161
+ create? ? false : nil
162
+ end
163
+
164
+ options.delete(:database)
154
165
  else
155
166
  params[:internal] = false
156
167
  end
@@ -5,8 +5,27 @@ module Aptible
5
5
  NO_NESTING = Object.new.freeze
6
6
 
7
7
  def inject_backup(node, backup, include_db: false)
8
+ bu_operation = begin
9
+ backup.created_from_operation
10
+ rescue HyperResource::ClientError
11
+ nil
12
+ end
13
+
14
+ origin = if backup.manual && !backup.copied_from
15
+ if bu_operation
16
+ "manual, #{bu_operation.user_email}"
17
+ else
18
+ 'manual, unknown'
19
+ end
20
+ elsif backup.manual && backup.copied_from
21
+ 'manual, copy'
22
+ elsif backup.copied_from
23
+ 'automatic, copy'
24
+ else
25
+ 'automatic'
26
+ end
8
27
  description = "#{backup.id}: #{backup.created_at}, " \
9
- "#{backup.aws_region}"
28
+ "#{backup.aws_region}, #{origin}"
10
29
 
11
30
  if include_db
12
31
  db = backup.database_with_deleted
@@ -30,6 +49,13 @@ module Aptible
30
49
  inject_backup(n, backup.copied_from)
31
50
  end
32
51
  end
52
+
53
+ if bu_operation && \
54
+ backup.manual && !backup.copied_from
55
+ node.keyed_object('created_from_operation', 'id') do |n|
56
+ inject_operation(n, bu_operation)
57
+ end
58
+ end
33
59
  end
34
60
 
35
61
  def inject_deleted_database(node, database, account)
@@ -49,7 +75,9 @@ module Aptible
49
75
  def inject_operation(node, operation)
50
76
  node.value('id', operation.id)
51
77
  node.value('status', operation.status)
52
- node.value('git_ref', operation.git_ref)
78
+ if %w(deploy rebuild).include?(operation.type)
79
+ node.value('git_ref', operation.git_ref)
80
+ end
53
81
  node.value('user_email', operation.user_email)
54
82
  node.value('created_at', operation.created_at)
55
83
  end
@@ -178,6 +206,36 @@ module Aptible
178
206
  attach_service(node, service)
179
207
  end
180
208
 
209
+ def inject_log_drain(node, log_drain, account)
210
+ node.value('id', log_drain.id)
211
+ node.value('handle', log_drain.handle)
212
+ node.value('drain_type', log_drain.drain_type)
213
+ node.value('created_at', log_drain.created_at)
214
+ node.value('drain_apps', log_drain.drain_apps)
215
+ node.value('drain_databases', log_drain.drain_databases)
216
+ node.value('drain_ephemeral_sessions',
217
+ log_drain.drain_ephemeral_sessions)
218
+ node.value('drain_proxies', log_drain.drain_proxies)
219
+
220
+ optional_attrs = %w(drain_username drain_host drain_port url)
221
+ optional_attrs.each do |attr|
222
+ value = log_drain.attributes[attr]
223
+ node.value(attr, value) unless value.nil?
224
+ end
225
+
226
+ attach_account(node, account)
227
+ end
228
+
229
+ def inject_metric_drain(node, metric_drain, account)
230
+ node.value('id', metric_drain.id)
231
+ node.value('handle', metric_drain.handle)
232
+ node.value('drain_type', metric_drain.drain_type)
233
+ node.value('created_at', metric_drain.created_at)
234
+ node.value('drain_configuration', metric_drain.drain_configuration)
235
+
236
+ attach_account(node, account)
237
+ end
238
+
181
239
  private
182
240
 
183
241
  def attach_account(node, account)
@@ -52,52 +52,17 @@ module Aptible
52
52
  app_options
53
53
  option :container_count, type: :numeric
54
54
  option :container_size, type: :numeric
55
- option :size, type: :numeric,
56
- desc: 'DEPRECATED, use --container-size'
57
- define_method 'apps:scale' do |type, *more|
55
+ define_method 'apps:scale' do |type|
58
56
  service = ensure_service(options, type)
59
57
 
60
58
  container_count = options[:container_count]
61
59
  container_size = options[:container_size]
62
60
 
63
- # There are two legacy options we have to process here:
64
- # - We used to accept apps:scale SERVICE COUNT
65
- # - We used to accept --size
66
- case more.size
67
- when 0
68
- # Noop
69
- when 1
70
- if container_count.nil?
71
- m = 'Passing container count as a positional ' \
72
- 'argument is deprecated, use --container-count'
73
- CLI.logger.warn(m)
74
- container_count = Integer(more.first)
75
- else
76
- raise Thor::Error, 'Container count was passed via both ' \
77
- 'the --container-count keyword argument ' \
78
- 'and a positional argument. ' \
79
- 'Use only --container-count to proceed.'
80
- end
81
- else
82
- # Unfortunately, Thor does not want to let us easily hook into
83
- # its usage formatting, so we have to work around it here.
84
- command = thor.commands.fetch('apps:scale')
85
- error = ArgumentError.new
86
- args = [type] + more
87
- thor.handle_argument_error(command, error, args, 1)
88
- end
89
-
90
61
  if options[:size]
91
- if container_size.nil?
92
- m = 'Passing container size via the --size keyword ' \
93
- 'argument is deprecated, use --container-size'
94
- CLI.logger.warn(m)
95
- container_size = options[:size]
96
- else
97
- raise Thor::Error, 'Container size was passed via both ' \
98
- '--container-size and --size. ' \
99
- 'Use only --container-size to proceed.'
100
- end
62
+ m = 'You have used the "--size" option to specify a container '\
63
+ 'size. This abiguous option has been removed.'\
64
+ 'Please use the "--container-size" option, instead.'
65
+ raise Thor::Error, m
101
66
  end
102
67
 
103
68
  if container_count.nil? && container_size.nil?