aptible-cli 0.26.2 → 0.26.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/aptible/cli/agent.rb +7 -4
  5. data/lib/aptible/cli/helpers/app.rb +29 -16
  6. data/lib/aptible/cli/helpers/database.rb +49 -32
  7. data/lib/aptible/cli/helpers/environment.rb +5 -4
  8. data/lib/aptible/cli/helpers/log_drain.rb +3 -1
  9. data/lib/aptible/cli/helpers/metric_drain.rb +3 -1
  10. data/lib/aptible/cli/resource_formatter.rb +14 -1
  11. data/lib/aptible/cli/subcommands/backup.rb +1 -1
  12. data/lib/aptible/cli/subcommands/config.rb +2 -2
  13. data/lib/aptible/cli/subcommands/db.rb +4 -3
  14. data/lib/aptible/cli/subcommands/log_drain.rb +2 -0
  15. data/lib/aptible/cli/subcommands/logs.rb +5 -5
  16. data/lib/aptible/cli/subcommands/metric_drain.rb +2 -0
  17. data/lib/aptible/cli/version.rb +1 -1
  18. data/lib/aptible/cli.rb +14 -0
  19. data/spec/aptible/cli/subcommands/apps_spec.rb +34 -21
  20. data/spec/aptible/cli/subcommands/backup_retention_policy_spec.rb +3 -1
  21. data/spec/aptible/cli/subcommands/backup_spec.rb +28 -3
  22. data/spec/aptible/cli/subcommands/config_spec.rb +11 -3
  23. data/spec/aptible/cli/subcommands/db_spec.rb +49 -95
  24. data/spec/aptible/cli/subcommands/deploy_spec.rb +8 -3
  25. data/spec/aptible/cli/subcommands/endpoints_spec.rb +20 -4
  26. data/spec/aptible/cli/subcommands/environment_spec.rb +4 -0
  27. data/spec/aptible/cli/subcommands/log_drain_spec.rb +15 -0
  28. data/spec/aptible/cli/subcommands/logs_spec.rb +16 -4
  29. data/spec/aptible/cli/subcommands/maintenance_spec.rb +7 -2
  30. data/spec/aptible/cli/subcommands/metric_drain_spec.rb +14 -2
  31. data/spec/aptible/cli/subcommands/services_spec.rb +3 -4
  32. data/spec/fabricators/account_fabricator.rb +9 -1
  33. data/spec/fabricators/app_external_aws_rds_connection_fabricator.rb +1 -1
  34. data/spec/fabricators/app_fabricator.rb +1 -1
  35. data/spec/fabricators/backup_fabricator.rb +1 -1
  36. data/spec/fabricators/backup_retention_policy_fabricator.rb +1 -1
  37. data/spec/fabricators/certificate_fabricator.rb +1 -1
  38. data/spec/fabricators/configuration_fabricator.rb +1 -1
  39. data/spec/fabricators/database_credential_fabricator.rb +1 -1
  40. data/spec/fabricators/database_disk_fabricator.rb +1 -1
  41. data/spec/fabricators/database_fabricator.rb +10 -1
  42. data/spec/fabricators/database_image_fabricator.rb +1 -1
  43. data/spec/fabricators/external_aws_account_fabricator.rb +1 -1
  44. data/spec/fabricators/external_aws_database_credential_fabricator.rb +1 -1
  45. data/spec/fabricators/external_aws_resource_fabricator.rb +1 -1
  46. data/spec/fabricators/log_drain_fabricator.rb +1 -1
  47. data/spec/fabricators/maintenance_app_fabricator.rb +1 -1
  48. data/spec/fabricators/maintenance_database_fabricator.rb +1 -1
  49. data/spec/fabricators/metric_drain_fabricator.rb +15 -1
  50. data/spec/fabricators/operation_fabricator.rb +1 -1
  51. data/spec/fabricators/service_fabricator.rb +1 -1
  52. data/spec/fabricators/service_sizing_policy_fabricator.rb +1 -1
  53. data/spec/fabricators/stack_fabricator.rb +1 -1
  54. data/spec/fabricators/vhost_fabricator.rb +1 -1
  55. data/spec/spec_helper.rb +7 -0
  56. data/spec/support/stub_aptible_resource.rb +25 -0
  57. metadata +5 -2
@@ -14,9 +14,17 @@ describe Aptible::CLI::Agent do
14
14
  .with(token: token, href: '/metric_drains?per_page=5000')
15
15
  .and_return([metric_drain])
16
16
 
17
+ allow(Aptible::Api::MetricDrain).to receive(:all)
18
+ .with(token: token, href: "/accounts/#{account.id}/metric_drains")
19
+ .and_return([metric_drain])
20
+
17
21
  allow(Aptible::Api::Account).to receive(:all)
18
22
  .with(token: token, href: '/accounts?per_page=5000&no_embed=true')
19
23
  .and_return([account])
24
+
25
+ allow(Aptible::Api::Account).to receive(:find_by_url)
26
+ .with("/find/account?handle=#{account.handle}", token: token)
27
+ .and_return(account)
20
28
  end
21
29
 
22
30
  describe '#metric_drain:list' do
@@ -53,8 +61,6 @@ describe Aptible::CLI::Agent do
53
61
  it 'lists metric drains for a single account with --environment' do
54
62
  other_account = Fabricate(:account)
55
63
  Fabricate(:metric_drain, handle: 'test2', account: other_account)
56
- accounts = [account, other_account]
57
- allow(Aptible::Api::Account).to receive(:all).and_return(accounts)
58
64
 
59
65
  subject.options = { environment: account.handle }
60
66
  subject.send('metric_drain:list')
@@ -82,6 +88,12 @@ describe Aptible::CLI::Agent do
82
88
  context 'influxdb' do
83
89
  let(:db) { Fabricate(:database, account: account, id: 5) }
84
90
 
91
+ before do
92
+ allow(Aptible::Api::Database).to receive(:find_by_url)
93
+ .with("/find/database?handle=#{db.handle}&environment=#{db.account.handle}", token: token)
94
+ .and_return(db)
95
+ end
96
+
85
97
  it 'creates a new InfluxDB metric drain' do
86
98
  opts = {
87
99
  handle: 'test-influxdb',
@@ -6,10 +6,9 @@ describe Aptible::CLI::Agent do
6
6
 
7
7
  before do
8
8
  allow(subject).to receive(:fetch_token) { token }
9
- allow(Aptible::Api::App)
10
- .to receive(:all)
11
- .with(token: token, href: '/apps?per_page=5000&no_embed=true')
12
- .and_return([app])
9
+ allow(Aptible::Api::App).to receive(:find_by_url)
10
+ .with("/find/app?handle=#{app.handle}", token: token)
11
+ .and_return(app)
13
12
  end
14
13
 
15
14
  describe '#services' do
@@ -1,4 +1,4 @@
1
- class StubAccount < OpenStruct
1
+ class StubAccount < StubAptibleResource
2
2
  def each_app(&block)
3
3
  return enum_for(:each_app) if block.nil?
4
4
  apps.each(&block)
@@ -34,6 +34,14 @@ Fabricator(:account, from: :stub_account) do
34
34
  hash = {
35
35
  self: OpenStruct.new(
36
36
  href: "/accounts/#{attrs[:id]}"
37
+ ),
38
+ metric_drains: OpenStruct.new(
39
+ base_href: "/accounts/#{attrs[:id]}/metric_drains",
40
+ href: "/accounts/#{attrs[:id]}/metric_drains"
41
+ ),
42
+ log_drains: OpenStruct.new(
43
+ base_href: "/accounts/#{attrs[:id]}/log_drains",
44
+ href: "/accounts/#{attrs[:id]}/log_drains"
37
45
  )
38
46
  }
39
47
  OpenStruct.new(hash)
@@ -1,4 +1,4 @@
1
- class StubAppExternalAwsRdsConnection < OpenStruct
1
+ class StubAppExternalAwsRdsConnection < StubAptibleResource
2
2
  def attributes
3
3
  {
4
4
  'id' => id,
@@ -1,4 +1,4 @@
1
- class StubApp < OpenStruct
1
+ class StubApp < StubAptibleResource
2
2
  def vhosts
3
3
  services.map(&:vhosts).flatten
4
4
  end
@@ -1,4 +1,4 @@
1
- class StubBackup < OpenStruct; end
1
+ class StubBackup < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:backup, from: :stub_backup) do
4
4
  id { sequence(:backup_id) }
@@ -1,4 +1,4 @@
1
- class StubBackupRetentionPolicy < OpenStruct
1
+ class StubBackupRetentionPolicy < StubAptibleResource
2
2
  def reload
3
3
  self
4
4
  end
@@ -1,4 +1,4 @@
1
- class StubCertificate < OpenStruct; end
1
+ class StubCertificate < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:certificate, from: :stub_certificate) do
4
4
  account
@@ -1,4 +1,4 @@
1
- class StubConfiguration < OpenStruct
1
+ class StubConfiguration < StubAptibleResource
2
2
  end
3
3
 
4
4
  Fabricator(:configuration, from: :stub_configuration) do
@@ -1,4 +1,4 @@
1
- class StubDatabaseCredential < OpenStruct; end
1
+ class StubDatabaseCredential < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:database_credential, from: :stub_database_credential) do
4
4
  database
@@ -1,4 +1,4 @@
1
- class StubDatabaseDisk < OpenStruct
1
+ class StubDatabaseDisk < StubAptibleResource
2
2
  end
3
3
 
4
4
  Fabricator(:database_disk, from: :stub_database_disk) do
@@ -1,7 +1,13 @@
1
- class StubDatabase < OpenStruct
1
+ class StubDatabase < StubAptibleResource
2
2
  def provisioned?
3
3
  status == 'provisioned'
4
4
  end
5
+
6
+ def objects
7
+ {
8
+ 'database_credentials' => database_credentials
9
+ }
10
+ end
5
11
  end
6
12
 
7
13
  Fabricator(:database, from: :stub_database) do
@@ -23,6 +29,9 @@ Fabricator(:database, from: :stub_database) do
23
29
  hash = {
24
30
  account: OpenStruct.new(
25
31
  href: "/accounts/#{attrs[:account].id}"
32
+ ),
33
+ database_credentials: OpenStruct.new(
34
+ href: "/databases/#{attrs[:handle]}/database_credentials"
26
35
  )
27
36
  }
28
37
  OpenStruct.new(hash)
@@ -1,4 +1,4 @@
1
- class StubDatabaseImage < OpenStruct
1
+ class StubDatabaseImage < StubAptibleResource
2
2
  end
3
3
 
4
4
  Fabricator(:database_image, from: :stub_database_image) do
@@ -1,4 +1,4 @@
1
- class StubExternalAwsAccount < OpenStruct
1
+ class StubExternalAwsAccount < StubAptibleResource
2
2
  def attributes
3
3
  {
4
4
  'aws_account_id' => aws_account_id,
@@ -1,4 +1,4 @@
1
- class StubExternalAwsDatabaseCredential < OpenStruct
1
+ class StubExternalAwsDatabaseCredential < StubAptibleResource
2
2
  def attributes
3
3
  {
4
4
  'id' => id,
@@ -1,4 +1,4 @@
1
- class StubExternalAwsResource < OpenStruct
1
+ class StubExternalAwsResource < StubAptibleResource
2
2
  def attributes
3
3
  {
4
4
  'id' => id,
@@ -1,4 +1,4 @@
1
- class StubLogDrain < OpenStruct
1
+ class StubLogDrain < StubAptibleResource
2
2
  def attributes
3
3
  # I foresee hard-coding values like this
4
4
  # being hard to debug in the future,
@@ -1,4 +1,4 @@
1
- class StubMaintenanceApp < OpenStruct; end
1
+ class StubMaintenanceApp < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:maintenance_app, from: :stub_maintenance_app) do
4
4
  id { Fabricate.sequence(:app_id) { |i| i } }
@@ -1,4 +1,4 @@
1
- class StubMaintenanceDatabase < OpenStruct; end
1
+ class StubMaintenanceDatabase < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:maintenance_database, from: :stub_maintenance_database) do
4
4
  id { Fabricate.sequence(:database_id) { |i| i } }
@@ -1,7 +1,21 @@
1
- class StubMetricDrain < OpenStruct; end
1
+ class StubMetricDrain < StubAptibleResource
2
+ def attributes
3
+ # Don't blame me, I'm just following the example in StubLogDrain,
4
+ # see the comment there.
5
+ {
6
+ 'drain_configuration' => drain_configuration
7
+ }
8
+ end
9
+ end
2
10
 
3
11
  Fabricator(:metric_drain, from: :stub_metric_drain) do
4
12
  id { sequence(:metric_drain_id) }
13
+ drain_configuration do
14
+ {
15
+ 'api_key' => 'asdf',
16
+ 'series_url' => 'https://localhost.aptible.in/api/v1/series'
17
+ }
18
+ end
5
19
  account
6
20
  links do |attrs|
7
21
  hash = {
@@ -1,4 +1,4 @@
1
- class StubOperation < OpenStruct; end
1
+ class StubOperation < StubAptibleResource; end
2
2
 
3
3
  def mock_logs_url(id)
4
4
  "https://api.aptible.com/operations/#{id}/logs"
@@ -1,4 +1,4 @@
1
- class StubService < OpenStruct
1
+ class StubService < StubAptibleResource
2
2
  def each_vhost(&block)
3
3
  return enum_for(:each_vhost) if block.nil?
4
4
  vhosts.each(&block)
@@ -1,4 +1,4 @@
1
- class StubServiceSizingPolicy < OpenStruct; end
1
+ class StubServiceSizingPolicy < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:service_sizing_policy, from: :stub_service_sizing_policy) do
4
4
  autoscaling 'vertical'
@@ -1,4 +1,4 @@
1
- class StubStack < OpenStruct; end
1
+ class StubStack < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:stack, from: :stub_stack) do
4
4
  name 'foo'
@@ -1,4 +1,4 @@
1
- class StubVhost < OpenStruct; end
1
+ class StubVhost < StubAptibleResource; end
2
2
 
3
3
  Fabricator(:vhost, from: :stub_vhost) do
4
4
  service
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,11 @@ Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
8
8
  require file
9
9
  end
10
10
 
11
+ # Load support files (shared classes used by fabricators, etc.)
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |file|
13
+ require file
14
+ end
15
+
11
16
  # Require library up front
12
17
  require 'aptible/cli'
13
18
 
@@ -76,6 +81,8 @@ module SpecHarness
76
81
  end
77
82
 
78
83
  RSpec.configure do |config|
84
+ config.example_status_persistence_file_path = 'spec/reports/examples.txt'
85
+
79
86
  config.before(:each) do
80
87
  reset_spec_harness
81
88
  begin
@@ -0,0 +1,25 @@
1
+ class StubAptibleResource < OpenStruct
2
+ def headers
3
+ @headers ||= {}
4
+ end
5
+
6
+ def find_by_url(_url)
7
+ self
8
+ end
9
+
10
+ def href
11
+ self[:href] || "/#{self.class.resource_path}/#{id}"
12
+ end
13
+
14
+ def self.resource_path
15
+ name = to_s.sub(/^Stub/, '')
16
+ snake = name.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
17
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
18
+ .downcase
19
+ if snake.end_with?('y')
20
+ snake.sub(/y$/, 'ies')
21
+ else
22
+ "#{snake}s"
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.2
4
+ version: 0.26.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-13 00:00:00.000000000 Z
11
+ date: 2026-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -478,6 +478,7 @@ files:
478
478
  - ".github/workflows/test.yml"
479
479
  - ".gitignore"
480
480
  - ".rspec"
481
+ - ".rubocop.yml"
481
482
  - Dockerfile
482
483
  - Gemfile
483
484
  - Gemfile.lock
@@ -619,6 +620,7 @@ files:
619
620
  - spec/script/ssh-spawn
620
621
  - spec/shared/mock_ssh_context.rb
621
622
  - spec/spec_helper.rb
623
+ - spec/support/stub_aptible_resource.rb
622
624
  homepage: https://github.com/aptible/aptible-cli
623
625
  licenses:
624
626
  - MIT
@@ -712,3 +714,4 @@ test_files:
712
714
  - spec/script/ssh-spawn
713
715
  - spec/shared/mock_ssh_context.rb
714
716
  - spec/spec_helper.rb
717
+ - spec/support/stub_aptible_resource.rb