brightbox-cli 4.8.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +6 -2
  3. data/CHANGELOG.md +60 -0
  4. data/Gemfile.lock +17 -10
  5. data/brightbox-cli.gemspec +3 -7
  6. data/lib/brightbox-cli/accounts.rb +5 -1
  7. data/lib/brightbox-cli/api.rb +34 -1
  8. data/lib/brightbox-cli/cloud_ips.rb +6 -6
  9. data/lib/brightbox-cli/collaboration.rb +3 -7
  10. data/lib/brightbox-cli/commands/cloudips/unmap.rb +1 -1
  11. data/lib/brightbox-cli/commands/firewall/policies_apply.rb +1 -1
  12. data/lib/brightbox-cli/commands/firewall/policies_create.rb +1 -1
  13. data/lib/brightbox-cli/commands/firewall/policies_destroy.rb +1 -1
  14. data/lib/brightbox-cli/commands/firewall/policies_list.rb +1 -1
  15. data/lib/brightbox-cli/commands/firewall/policies_remove.rb +1 -1
  16. data/lib/brightbox-cli/commands/firewall/policies_show.rb +1 -1
  17. data/lib/brightbox-cli/commands/firewall/policies_update.rb +1 -1
  18. data/lib/brightbox-cli/commands/lbs/create.rb +28 -16
  19. data/lib/brightbox-cli/commands/lbs/show.rb +5 -0
  20. data/lib/brightbox-cli/commands/lbs/update.rb +9 -2
  21. data/lib/brightbox-cli/config.rb +12 -5
  22. data/lib/brightbox-cli/database_server.rb +20 -20
  23. data/lib/brightbox-cli/database_snapshot.rb +5 -5
  24. data/lib/brightbox-cli/database_type.rb +4 -8
  25. data/lib/brightbox-cli/detailed_server.rb +26 -28
  26. data/lib/brightbox-cli/detailed_server_group.rb +2 -2
  27. data/lib/brightbox-cli/firewall_policy.rb +5 -9
  28. data/lib/brightbox-cli/firewall_rule.rb +14 -15
  29. data/lib/brightbox-cli/images.rb +21 -20
  30. data/lib/brightbox-cli/indifferent_access_hash.rb +50 -0
  31. data/lib/brightbox-cli/load_balancers.rb +38 -4
  32. data/lib/brightbox-cli/server_groups.rb +4 -8
  33. data/lib/brightbox-cli/servers.rb +22 -16
  34. data/lib/brightbox-cli/types.rb +4 -8
  35. data/lib/brightbox-cli/user_collaboration.rb +1 -1
  36. data/lib/brightbox-cli/users.rb +3 -5
  37. data/lib/brightbox-cli/version.rb +1 -1
  38. data/lib/brightbox-cli/volume.rb +9 -13
  39. data/lib/brightbox-cli/zones.rb +0 -4
  40. data/lib/brightbox_cli.rb +1 -0
  41. data/spec/commands/cloudips/update_spec.rb +7 -5
  42. data/spec/commands/configmaps/create_spec.rb +6 -6
  43. data/spec/commands/configmaps/destroy_spec.rb +1 -1
  44. data/spec/commands/configmaps/list_spec.rb +1 -1
  45. data/spec/commands/configmaps/show_spec.rb +3 -3
  46. data/spec/commands/configmaps/update_spec.rb +9 -9
  47. data/spec/commands/lbs/create_spec.rb +158 -6
  48. data/spec/commands/lbs/show_spec.rb +99 -3
  49. data/spec/commands/lbs/update_spec.rb +50 -6
  50. data/spec/commands/servers/update_spec.rb +7 -7
  51. data/spec/commands/sql/instances/create_spec.rb +8 -8
  52. data/spec/commands/sql/instances/reset_spec.rb +3 -3
  53. data/spec/commands/sql/instances/resize_spec.rb +4 -4
  54. data/spec/commands/sql/instances/show_spec.rb +2 -1
  55. data/spec/commands/sql/instances/update_spec.rb +3 -3
  56. data/spec/commands/sql/snapshots/list_spec.rb +1 -1
  57. data/spec/commands/sql/snapshots/show_spec.rb +50 -7
  58. data/spec/commands/volumes/attach_spec.rb +4 -4
  59. data/spec/commands/volumes/copy_spec.rb +2 -2
  60. data/spec/commands/volumes/destroy_spec.rb +1 -1
  61. data/spec/commands/volumes/detach_spec.rb +1 -1
  62. data/spec/commands/volumes/list_spec.rb +1 -1
  63. data/spec/commands/volumes/resize_spec.rb +3 -3
  64. data/spec/commands/volumes/show_spec.rb +1 -1
  65. data/spec/commands/volumes/update_spec.rb +4 -4
  66. data/spec/spec_helper.rb +16 -0
  67. data/spec/support/shared/api_resource_examples.rb +25 -0
  68. data/spec/unit/brightbox/account/attributes_spec.rb +13 -0
  69. data/spec/unit/brightbox/api/attributes_spec.rb +65 -0
  70. data/spec/unit/brightbox/api/fog_attributes_spec.rb +65 -0
  71. data/spec/unit/brightbox/bb_config/config_directory_spec.rb +23 -3
  72. data/spec/unit/brightbox/cloud_ip/attributes_spec.rb +19 -0
  73. data/spec/unit/brightbox/collaborating_account/attributes_spec.rb +13 -0
  74. data/spec/unit/brightbox/database_server/attributes_spec.rb +13 -0
  75. data/spec/unit/brightbox/database_snapshot/attributes_spec.rb +13 -0
  76. data/spec/unit/brightbox/database_type/attributes_spec.rb +20 -0
  77. data/spec/unit/brightbox/detailed_server/attributes_spec.rb +29 -0
  78. data/spec/unit/brightbox/detailed_server_group/attributes_spec.rb +13 -0
  79. data/spec/unit/brightbox/firewall_policy/attributes_spec.rb +21 -0
  80. data/spec/unit/brightbox/firewall_rule/attributes_spec.rb +18 -0
  81. data/spec/unit/brightbox/image/attributes_spec.rb +13 -0
  82. data/spec/unit/brightbox/image/status_spec.rb +67 -0
  83. data/spec/unit/brightbox/load_balancer/acme_cert_spec.rb +75 -0
  84. data/spec/unit/brightbox/load_balancer/attributes_spec.rb +13 -0
  85. data/spec/unit/brightbox/load_balancer/formatted_acme_domains_spec.rb +78 -0
  86. data/spec/unit/brightbox/server/attributes_spec.rb +29 -0
  87. data/spec/unit/brightbox/server/hostname_spec.rb +27 -0
  88. data/spec/unit/brightbox/server_group/attributes_spec.rb +13 -0
  89. data/spec/unit/brightbox/type/attributes_spec.rb +20 -0
  90. data/spec/unit/brightbox/user/attributes_spec.rb +13 -0
  91. data/spec/unit/brightbox/user_collaboration/attributes_spec.rb +13 -0
  92. metadata +68 -23
  93. data/spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml +0 -93
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::FirewallPolicy, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "res-12345",
10
+ attributes: model_attributes,
11
+ description: "",
12
+ server_group_id: "grp-12345",
13
+ name: "my-policy"
14
+ )
15
+ end
16
+ let(:model_attributes) { { id: "fwp-12345" } }
17
+
18
+ it "returns an IndifferentAccessHash" do
19
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::FirewallRule, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "fwr-12345",
10
+ attributes: model_attributes
11
+ )
12
+ end
13
+ let(:model_attributes) { { id: "fwr-12345" } }
14
+
15
+ it "returns an IndifferentAccessHash" do
16
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Image, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Image, "#status" do
4
+ subject(:image) { Brightbox::Image.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Compute::Brightbox::Image",
9
+ id: "img-12345",
10
+ attributes: {
11
+ "id": "img-12345",
12
+ "status": status,
13
+ "public": is_public
14
+ },
15
+ public: is_public
16
+ )
17
+ end
18
+ let(:is_public) { false }
19
+
20
+ context "when the image is pending" do
21
+ let(:status) { "pending" }
22
+
23
+ it "returns 'pending'" do
24
+ expect(image.status).to eq("pending")
25
+ end
26
+ end
27
+
28
+ context "when the image is available" do
29
+ let(:status) { "available" }
30
+
31
+ context "with public visibility" do
32
+ let(:is_public) { true }
33
+
34
+ it "returns 'public'" do
35
+ expect(image.status).to eq("public")
36
+ end
37
+ end
38
+
39
+ context "without public visibility" do
40
+ let(:is_public) { false }
41
+
42
+ it "returns 'private'" do
43
+ expect(image.status).to eq("private")
44
+ end
45
+ end
46
+ end
47
+
48
+ context "when the image is deprecated" do
49
+ let(:status) { "deprecated" }
50
+
51
+ context "with public visibility" do
52
+ let(:is_public) { true }
53
+
54
+ it "returns 'deprecated'" do
55
+ expect(image.status).to eq("deprecated")
56
+ end
57
+ end
58
+
59
+ context "without public visibility" do
60
+ let(:is_public) { false }
61
+
62
+ it "returns 'private'" do
63
+ expect(image.status).to eq("private")
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,75 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::LoadBalancer, "#acme_cert" do
4
+ subject(:acme_cert) { load_balancer.acme_cert }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Compute::Brightbox::LoadBalancer",
9
+ id: "lba-12345",
10
+ attributes: lba_attributes
11
+ )
12
+ end
13
+ let(:load_balancer) { Brightbox::LoadBalancer.new(fog_model) }
14
+
15
+ context "when ACME is not setup" do
16
+ let(:lba_attributes) { { acme: nil } }
17
+
18
+ it "returns an empty string" do
19
+ expect(acme_cert).not_to be_nil
20
+ end
21
+ end
22
+
23
+ context "when ACME is setup" do
24
+ context "without certificate" do
25
+ let(:lba_attributes) do
26
+ { acme: { certificate: nil }}
27
+ end
28
+
29
+ it "returns an object without keys" do
30
+ expect(acme_cert).not_to be_nil
31
+
32
+ expect(acme_cert).to have_attributes(
33
+ expires_at: "",
34
+ fingerprint: "",
35
+ issued_at: "",
36
+ subjects: ""
37
+ )
38
+ end
39
+ end
40
+
41
+ context "with certificate" do
42
+ let(:expected_formatting) { "example.com:verified,example.net:pending" }
43
+ let(:lba_attributes) do
44
+ {
45
+ acme: {
46
+ domains: [
47
+ { identifier: "domain.one.test", status: "verified" },
48
+ { identifier: "domain.two.test", status: "verified" }
49
+ ],
50
+ certificate: {
51
+ domains: [
52
+ "domain.one.test",
53
+ "domain.two.test"
54
+ ],
55
+ expires_at: "2025-12-31T23:59:59Z",
56
+ fingerprint: "TLS-fingerprint",
57
+ issued_at: "2025-01-01T00:00:00Z"
58
+ }
59
+ }
60
+ }
61
+ end
62
+
63
+ it "returns an object with the correct keys" do
64
+ expect(acme_cert).not_to be_nil
65
+
66
+ expect(acme_cert).to have_attributes(
67
+ expires_at: "2025-12-31T23:59:59Z",
68
+ fingerprint: "TLS-fingerprint",
69
+ issued_at: "2025-01-01T00:00:00Z",
70
+ subjects: "domain.one.test,domain.two.test"
71
+ )
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::LoadBalancer, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::LoadBalancer, "#formatted_acme_domains" do
4
+ subject(:load_balancer) { Brightbox::LoadBalancer.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Compute::Brightbox::LoadBalancer",
9
+ id: "lba-12345",
10
+ attributes: lba_attributes
11
+ )
12
+ end
13
+ let(:lba_attributes) do
14
+ # Encode/decode JSON to get final key/value forms
15
+ JSON.parse({
16
+ id: "lba-12345",
17
+ acme: acme_details
18
+ }.to_json)
19
+ end
20
+
21
+ context "when ACME is not setup" do
22
+ let(:acme_details) { nil }
23
+
24
+ it "returns an empty array" do
25
+ expect(load_balancer.formatted_acme_domains).to eq("")
26
+ end
27
+ end
28
+
29
+ context "when no domains are returned" do
30
+ let(:acme_details) do
31
+ { domains: [] }
32
+ end
33
+
34
+ it "returns an empty array" do
35
+ expect(load_balancer.formatted_acme_domains).to eq("")
36
+ end
37
+ end
38
+
39
+ context "when multiple domains are returned" do
40
+ let(:acme_details) do
41
+ {
42
+ domains: [
43
+ {
44
+ identifier: "example.com",
45
+ status: "verified"
46
+ },
47
+ {
48
+ identifier: "example.net",
49
+ status: "pending"
50
+ }
51
+ ]
52
+ }
53
+ end
54
+ let(:expected_formatting) do
55
+ "example.com:verified,example.net:pending"
56
+ end
57
+
58
+ it "returns a comma separated list of domains and statuses" do
59
+ expect(load_balancer.formatted_acme_domains).to eq(expected_formatting)
60
+ end
61
+ end
62
+
63
+ context "when error occurs" do
64
+ let(:lba_attributes) do
65
+ # Encode/decode JSON to get final key/value forms
66
+ JSON.parse({
67
+ id: "lba-12345",
68
+ acme: {
69
+ domains: nil
70
+ }
71
+ }.to_json)
72
+ end
73
+
74
+ it "returns an empty array" do
75
+ expect(load_balancer.formatted_acme_domains).to eq("")
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Server, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "srv-12345",
10
+ attributes: model_attributes,
11
+ cloud_ips: [],
12
+ created_at: Time.parse("2025-01-01T12:00:00Z"),
13
+ created_on: "2025-01-01",
14
+ hostname: "srv-12345.gb1.brightbox.com",
15
+ image_id: "img-12345",
16
+ interfaces: [],
17
+ locked?: false,
18
+ type: "typ-12345",
19
+ state: "active",
20
+ server_type: "typ-12345",
21
+ zone: { id: "zon-12345", handle: "gb1-a" }
22
+ )
23
+ end
24
+ let(:model_attributes) { { id: "srv-12345" } }
25
+
26
+ it "returns an IndifferentAccessHash" do
27
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/server"
3
+
4
+ RSpec.describe Brightbox::Server, "#hostname" do
5
+ let(:fog_model) { Fog::Brightbox::Compute::Server.new(fog_settings) }
6
+ let(:server) { described_class.new(fog_model) }
7
+
8
+ context "when hostname is not equal to id" do
9
+ let(:fog_settings) do
10
+ {
11
+ id: "srv-12345",
12
+ cloud_ips: [],
13
+ hostname: "server-hostname",
14
+ image_id: "img-12345",
15
+ interfaces: [],
16
+ server_type: "typ-12345"
17
+ }
18
+ end
19
+
20
+ it "returns the hostname" do
21
+ expect(server.attributes[:id]).to eq("srv-12345")
22
+ expect(server.attributes[:hostname]).to eq("server-hostname")
23
+
24
+ expect(server.hostname).to eq("server-hostname")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::ServerGroup, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::Type, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double(
8
+ "Fog::Model",
9
+ id: "typ-12345",
10
+ attributes: model_attributes,
11
+ ram: 1_024,
12
+ disk: 10_240
13
+ )
14
+ end
15
+ let(:model_attributes) { { id: "typ-12345" } }
16
+
17
+ it "returns an IndifferentAccessHash" do
18
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::User, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Brightbox::UserCollaboration, "#attributes" do
4
+ subject { described_class.new(fog_model) }
5
+
6
+ let(:fog_model) do
7
+ double("Fog::Model", id: "res-12345", attributes: { id: "res-12345"})
8
+ end
9
+
10
+ it "returns an IndifferentAccessHash" do
11
+ expect(subject.attributes).to be_a(IndifferentAccessHash)
12
+ end
13
+ end