aptible-cli 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -50
  3. data/lib/aptible/cli/agent.rb +9 -3
  4. data/lib/aptible/cli/helpers/config_path.rb +11 -0
  5. data/lib/aptible/cli/helpers/log_drain.rb +85 -0
  6. data/lib/aptible/cli/helpers/metric_drain.rb +39 -0
  7. data/lib/aptible/cli/helpers/ssh.rb +5 -1
  8. data/lib/aptible/cli/helpers/token.rb +5 -1
  9. data/lib/aptible/cli/resource_formatter.rb +66 -3
  10. data/lib/aptible/cli/subcommands/apps.rb +5 -40
  11. data/lib/aptible/cli/subcommands/backup.rb +15 -7
  12. data/lib/aptible/cli/subcommands/db.rb +24 -21
  13. data/lib/aptible/cli/subcommands/log_drain.rb +159 -0
  14. data/lib/aptible/cli/subcommands/metric_drain.rb +137 -0
  15. data/lib/aptible/cli/version.rb +1 -1
  16. data/spec/aptible/cli/resource_formatter_spec.rb +1 -0
  17. data/spec/aptible/cli/subcommands/apps_spec.rb +10 -51
  18. data/spec/aptible/cli/subcommands/backup_spec.rb +1 -1
  19. data/spec/aptible/cli/subcommands/db_spec.rb +0 -26
  20. data/spec/aptible/cli/subcommands/environment_spec.rb +4 -2
  21. data/spec/aptible/cli/subcommands/log_drain_spec.rb +207 -0
  22. data/spec/aptible/cli/subcommands/metric_drain_spec.rb +183 -0
  23. data/spec/fabricators/account_fabricator.rb +3 -0
  24. data/spec/fabricators/app_fabricator.rb +1 -0
  25. data/spec/fabricators/database_disk_fabricator.rb +2 -1
  26. data/spec/fabricators/database_fabricator.rb +1 -0
  27. data/spec/fabricators/log_drain_fabricator.rb +21 -0
  28. data/spec/fabricators/metric_drain_fabricator.rb +8 -0
  29. data/spec/fabricators/service_fabricator.rb +1 -0
  30. data/spec/fabricators/vhost_fabricator.rb +1 -0
  31. data/spec/spec_helper.rb +4 -0
  32. metadata +15 -5
  33. data/lib/aptible/cli/subcommands/domains.rb +0 -40
  34. data/spec/aptible/cli/subcommands/domains_spec.rb +0 -76
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ffdd3315dbbee4f94b8b02bb6c6695829c511cf950448997b603cce77253d20
4
- data.tar.gz: ac9983ee76d69580194e58d1f1acd6927f4addcbe2dbaec132ae133aa13d215a
3
+ metadata.gz: ee325f4c1746513670e64830cd10d8856fc39cc96e836c8f822e4c34ed6c45ea
4
+ data.tar.gz: 0dab373981390ea9d3429a6f0f43634eef13285bd090542329866bb1ff24620c
5
5
  SHA512:
6
- metadata.gz: d4721d191f0f6c35f6f75717b1896a5ca44441e3d912cb9af23bcde319f9f7678881a7eaf14de89e3222834c139d8c8c7bbe3eb9239d980ec55d32b47acbd835
7
- data.tar.gz: 2ced7b764b4b1b0db0ed460a0afd3f14836054a15ec32d5681af077a6811743fddff655c3d27121abc6858729116d385eff2da2d0c807cbbcef3abf92b2b0183
6
+ metadata.gz: 27fb8c12ceb02f977f29777bd418a2aa943c754d6b8cdc6a37ee55995bbe4a45dea9683c7191b4529017484b37dd3ef6dfcd3f2d70d2010ea032a0d1199409fd
7
+ data.tar.gz: b30888eb2d2855b388d04013eca773f4e69f77734c92aeee442499e7a266708c5a85800e0552ad0e739a40d1beb41956babcc4a2b9a0483d12be86939ac95c32
data/README.md CHANGED
@@ -28,56 +28,69 @@ 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:deprovision [--app APP | --database DATABASE] ENDPOINT_HOSTNAME # Deprovision an App or Database Endpoint
61
+ aptible endpoints:https:create [--app APP] SERVICE # Create an App HTTPS Endpoint
62
+ aptible endpoints:https:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App HTTPS Endpoint
63
+ aptible endpoints:list [--app APP | --database DATABASE] # List Endpoints for an App or Database
64
+ aptible endpoints:renew [--app APP] ENDPOINT_HOSTNAME # Renew an App Managed TLS Endpoint
65
+ aptible endpoints:tcp:create [--app APP] SERVICE # Create an App TCP Endpoint
66
+ aptible endpoints:tcp:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TCP Endpoint
67
+ aptible endpoints:tls:create [--app APP] SERVICE # Create an App TLS Endpoint
68
+ aptible endpoints:tls:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App TLS Endpoint
69
+ aptible environment:ca_cert # Retrieve the CA certificate associated with the environment
70
+ aptible environment:list # List all environments
71
+ aptible help [COMMAND] # Describe available commands or one specific command
72
+ 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
73
+ 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
74
+ 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
75
+ 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
76
+ 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
77
+ 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
78
+ 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
79
+ aptible log_drain:deprovision HANDLE --environment ENVIRONMENT # Deprovisions a log drain
80
+ aptible log_drain:list # List all Log Drains
81
+ aptible login # Log in to Aptible
82
+ aptible logs [--app APP | --database DATABASE] # Follows logs from a running app or database
83
+ aptible metric_drain:create:datadog HANDLE --api_key DATADOG_API_KEY --environment ENVIRONMENT # Create a Datadog Metric Drain
84
+ aptible metric_drain:create:influxdb HANDLE --db DATABASE_HANDLE --environment ENVIRONMENT # Create an InfluxDB Metric Drain
85
+ aptible metric_drain:create:influxdb:custom HANDLE --username USERNAME --password PASSWORD --url URL_INCLUDING_PORT # Create an InfluxDB Metric Drain
86
+ aptible metric_drain:deprovision HANDLE --environment ENVIRONMENT # Deprovisions a Metric Drain
87
+ aptible metric_drain:list # List all Metric Drains
88
+ aptible operation:cancel OPERATION_ID # Cancel a running operation
89
+ aptible rebuild # Rebuild an app, and restart its services
90
+ aptible restart # Restart all services associated with an app
91
+ aptible services # List Services for an App
92
+ aptible ssh [COMMAND] # Run a command against an app
93
+ aptible version # Print Aptible CLI version
81
94
  ```
82
95
  <!-- END USAGE -->
83
96
 
@@ -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
@@ -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)
@@ -43,12 +69,15 @@ module Aptible
43
69
  def inject_account(node, account)
44
70
  node.value('id', account.id)
45
71
  node.value('handle', account.handle)
72
+ node.value('created_at', account.created_at)
46
73
  end
47
74
 
48
75
  def inject_operation(node, operation)
49
76
  node.value('id', operation.id)
50
77
  node.value('status', operation.status)
51
- 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
52
81
  node.value('user_email', operation.user_email)
53
82
  node.value('created_at', operation.created_at)
54
83
  end
@@ -56,6 +85,7 @@ module Aptible
56
85
  def inject_app(node, app, account)
57
86
  node.value('id', app.id)
58
87
  node.value('handle', app.handle)
88
+ node.value('created_at', app.created_at)
59
89
 
60
90
  node.value('status', app.status)
61
91
  node.value('git_remote', app.git_repo)
@@ -80,6 +110,7 @@ module Aptible
80
110
  def inject_database(node, database, account)
81
111
  node.value('id', database.id)
82
112
  node.value('handle', database.handle)
113
+ node.value('created_at', database.created_at)
83
114
 
84
115
  node.value('type', database.type)
85
116
  node.value('version', database.database_image.version)
@@ -100,7 +131,7 @@ module Aptible
100
131
  node.value('disk_modification_progress',
101
132
  database.disk.modification_progress)
102
133
  node.value('disk_modification_status', database.disk.status)
103
- node.value('disk_provisioned_iops', database.disk.provisioned_iops)
134
+ node.value('disk_provisioned_iops', database.disk.baseline_iops)
104
135
  end
105
136
 
106
137
  if database.service
@@ -120,6 +151,7 @@ module Aptible
120
151
  def inject_service(node, service, app)
121
152
  node.value('id', service.id)
122
153
  node.value('service', service.process_type)
154
+ node.value('created_at', service.created_at)
123
155
 
124
156
  node.value('command', service.command || 'CMD')
125
157
  node.value('container_count', service.container_count)
@@ -132,6 +164,7 @@ module Aptible
132
164
  node.value('id', vhost.id)
133
165
  node.value('hostname', vhost.external_host)
134
166
  node.value('status', vhost.status)
167
+ node.value('created_at', vhost.created_at)
135
168
 
136
169
  case vhost.type
137
170
  when 'tcp', 'tls'
@@ -173,6 +206,36 @@ module Aptible
173
206
  attach_service(node, service)
174
207
  end
175
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
+
176
239
  private
177
240
 
178
241
  def attach_account(node, account)