brightbox-cli 4.4.0 → 4.5.0.rc1

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: 20cc19a7e6458988359a604fa90d67570b83c124b40c265a5f9beb0d3bc3a199
4
- data.tar.gz: 98072a6ccd8ab0dcf4a3e3ac7f27ecf6982a7f3cf275b86e979aae0fc12461d8
3
+ metadata.gz: f0ce8d035bac2e5f7df7990bbb5d1d726e3635b8a1bae0bea5ab2afa764755bc
4
+ data.tar.gz: 99eb62ee760ca495bcf2d5f38adf3eb2b1b5f95c0587b1acf1bc796db779b2ae
5
5
  SHA512:
6
- metadata.gz: 1c949f6d0679c9d72b7c7f61a6a0fd68b0669452911dde7da845a6f7e9a388c5b2a253ab0219bf6228faf4bc51ac6accfc559d714425c18499525d47b84ab73e
7
- data.tar.gz: 7975e2d18399cc35bcd49f474657f6766e5d694bdbf70a1d49b79288edcbc9c07ea1d54b0757bd992ef08c517d4eef0e2a684e9ebf102f4718f3c72bc31368f9
6
+ metadata.gz: f3630fd90082b69c561736854708c8132b7cb08e346bce2ea5f97318ce3478cc0fdbdc2840e393bf0816064e9894ebc857d866bebdfaf416cc8781e4914b39a5
7
+ data.tar.gz: 5188e419ae8dff029ddf0bf2ec1c8806774e50462628e4d0f5681ac42931505f5218fee300256755830f9c69c3041e4ec39af9ee64780c8fe2e13f5b0e3e9ee0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### v4.5.0.rc1 / 2023-01-26
2
+
3
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.4.0...v4.5.0)
4
+
5
+ Enhancements:
6
+
7
+ * Added `sql instances reset` subcommand for restarting DBMS on a database server.
8
+ * Added `sql instances resize` subcommand for increasing database server resources.
9
+
1
10
  ### v4.4.0 / 2023-01-26
2
11
 
3
12
  [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.3.2...v4.4.0)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightbox-cli (4.4.0)
4
+ brightbox-cli (4.5.0.rc1)
5
5
  dry-inflector (= 0.2.0)
6
- fog-brightbox (>= 1.10.0)
6
+ fog-brightbox (>= 1.11.0)
7
7
  fog-core (< 2.0)
8
8
  gli (~> 2.21)
9
9
  highline (~> 2.0)
@@ -26,7 +26,7 @@ GEM
26
26
  diff-lcs (1.5.0)
27
27
  dry-inflector (0.2.0)
28
28
  excon (0.97.2)
29
- fog-brightbox (1.10.0)
29
+ fog-brightbox (1.11.0)
30
30
  dry-inflector
31
31
  fog-core (>= 1.45, < 3.0)
32
32
  fog-json
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency "fog-brightbox", ">= 1.10.0"
24
+ s.add_dependency "fog-brightbox", ">= 1.11.0"
25
25
  s.add_dependency "fog-core", "< 2.0"
26
26
  s.add_dependency "gli", "~> 2.21"
27
27
  s.add_dependency "highline", "~> 2.0"
@@ -0,0 +1,33 @@
1
+ module Brightbox
2
+ command [:sql] do |product|
3
+ product.command [:instances] do |cmd|
4
+ cmd.desc I18n.t("sql.instances.reset_password.desc")
5
+ cmd.arg_name "server-id"
6
+ cmd.command [:reset] do |c|
7
+ c.action do |global_options, _options, args|
8
+ dbs_id = args.shift
9
+
10
+ unless dbs_id =~ /^dbs-/
11
+ raise I18n.t("sql.instances.args.invalid")
12
+ end
13
+
14
+ server = DatabaseServer.find dbs_id
15
+
16
+ info I18n.t("sql.instances.reset.acting", database_server: server)
17
+ begin
18
+ server.reset
19
+ rescue Brightbox::Api::Conflict
20
+ error I18n.t("sql.instances.reset.failed", database_server: server)
21
+ end
22
+
23
+ table_options = global_options.merge(
24
+ :vertical => true,
25
+ :fields => DatabaseServer.detailed_fields
26
+ )
27
+
28
+ render_table([server], table_options)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ module Brightbox
2
+ command [:sql] do |product|
3
+ product.command [:instances] do |cmd|
4
+ cmd.desc I18n.t("sql.instances.reset_password.desc")
5
+ cmd.arg_name "server-id"
6
+ cmd.command [:resize] do |c|
7
+ # Database type
8
+ c.desc I18n.t("sql.instances.options.type.desc")
9
+ c.flag %i[t type]
10
+
11
+ c.action do |global_options, options, args|
12
+ dbs_id = args.shift
13
+
14
+ unless dbs_id =~ /^dbs-/
15
+ raise I18n.t("sql.instances.args.invalid")
16
+ end
17
+
18
+ new_type = options[:type]
19
+ unless new_type =~ /^dbt-/
20
+ raise I18n.t("sql.instances.options.type.invalid")
21
+ end
22
+
23
+ server = DatabaseServer.find dbs_id
24
+
25
+ info I18n.t("sql.instances.resize.acting", database_server: server)
26
+ begin
27
+ server.resize(new_type: new_type)
28
+ rescue Brightbox::Api::Conflict
29
+ error I18n.t("sql.instances.resize.failed", database_server: server)
30
+ end
31
+
32
+ table_options = global_options.merge(
33
+ :vertical => true,
34
+ :fields => DatabaseServer.detailed_fields
35
+ )
36
+
37
+ render_table([server], table_options)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -24,10 +24,18 @@ module Brightbox
24
24
  self
25
25
  end
26
26
 
27
+ def reset
28
+ fog_model.reset
29
+ end
30
+
27
31
  def reset_password
28
32
  fog_model.reset_password
29
33
  end
30
34
 
35
+ def resize(options)
36
+ fog_model.resize(options[:new_type])
37
+ end
38
+
31
39
  def destroy
32
40
  fog_model.destroy
33
41
  end
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "4.4.0".freeze unless defined?(Brightbox::VERSION)
2
+ VERSION = "4.5.0.rc1".freeze unless defined?(Brightbox::VERSION)
3
3
  end
data/locales/en.yml CHANGED
@@ -207,6 +207,14 @@ en:
207
207
  desc: Manage an account's Cloud SQL instances and snapshots
208
208
  instances:
209
209
  desc: Manage Cloud SQL instances
210
+ args:
211
+ one: <sql-instance>
212
+ optional: "[<sql-instance>...]"
213
+ many: <sql-instance>...
214
+ specify_one_id_first: You must specify the SQL instance ID as the first argument
215
+ specify_many_ids: You must specify SQL instance IDs as arguments
216
+ invalid: You must specify a valid SQL instance ID as the first argument
217
+ unknown_id: Couldn't find %{database_server}
210
218
  options:
211
219
  allow_access:
212
220
  desc: Comma separated list of IPs or IDs for servers or groups to allow access
@@ -230,6 +238,7 @@ en:
230
238
  desc: Clear an existing snapshots schedule
231
239
  type:
232
240
  desc: ID of a Cloud SQL type
241
+ invalid: Cloud SQL type format is invalid
233
242
  zone:
234
243
  desc: Zone to locate the instance in
235
244
  create:
@@ -240,8 +249,16 @@ en:
240
249
  desc: Lock Cloud SQL instances
241
250
  list:
242
251
  desc: List Cloud SQL instances
252
+ reset:
253
+ desc: Reset a Cloud SQL instance
254
+ acting: Resetting %{database_server}
255
+ failed: Could not reset %{database_server}
243
256
  reset_password:
244
257
  desc: Reset the admin password of a Cloud SQL instance
258
+ resize:
259
+ desc: Resize a Cloud SQL instance to use a new type
260
+ acting: Resizing %{database_server}
261
+ failed: Could not resize %{database_server}
245
262
  show:
246
263
  desc: Show details of Cloud SQL instances
247
264
  snapshot:
@@ -0,0 +1,87 @@
1
+ require "spec_helper"
2
+
3
+ describe "brightbox sql instances reset" do
4
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
5
+ let(:stdout) { output.stdout }
6
+ let(:stderr) { output.stderr }
7
+
8
+ before do
9
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
10
+
11
+ stub_request(:post, "http://api.brightbox.localhost/token")
12
+ .to_return(
13
+ status: 200,
14
+ body: JSON.dump(
15
+ access_token: "ACCESS-TOKEN",
16
+ refresh_token: "REFRESH_TOKEN"
17
+ )
18
+ )
19
+
20
+ Brightbox.config.reauthenticate
21
+ end
22
+
23
+ context "without arguments" do
24
+ let(:argv) { %w[sql instances reset] }
25
+
26
+ it "does not error" do
27
+ expect { output }.to_not raise_error
28
+
29
+ expect(stderr).to eq("ERROR: You must specify a valid SQL instance ID as the first argument\n")
30
+
31
+ expect(stdout).to match("")
32
+ end
33
+ end
34
+
35
+ context "with invalid ID" do
36
+ let(:argv) { %w[sql instances reset dbs-l3kd4] }
37
+
38
+ before do
39
+ stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-l3kd4")
40
+ .with(query: hash_including(account_id: "acc-12345"))
41
+ .to_return(
42
+ status: 404,
43
+ body: ""
44
+ )
45
+ end
46
+
47
+ it "does not error" do
48
+ expect { output }.to_not raise_error
49
+
50
+ expect(stderr).to eq("ERROR: Couldn't find 'dbs-l3kd4'\n")
51
+
52
+ expect(stdout).to match("")
53
+ end
54
+ end
55
+
56
+ context "with valid ID" do
57
+ let(:argv) { %w[sql instances reset dbs-po953] }
58
+
59
+ before do
60
+ stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-po953")
61
+ .with(query: hash_including(account_id: "acc-12345"))
62
+ .to_return(
63
+ status: 200,
64
+ body: {
65
+ id: "dbs-po953"
66
+ }.to_json
67
+ )
68
+
69
+ stub_request(:post, "http://api.brightbox.localhost/1.0/database_servers/dbs-po953/reset")
70
+ .with(query: hash_including(account_id: "acc-12345"))
71
+ .to_return(
72
+ status: 202,
73
+ body: {
74
+ id: "dbs-po953"
75
+ }.to_json
76
+ )
77
+ end
78
+
79
+ it "does not error" do
80
+ expect { output }.to_not raise_error
81
+
82
+ expect(stderr).to eq("Resetting dbs-po953\n")
83
+
84
+ expect(stdout).to match("dbs-po953")
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,112 @@
1
+ require "spec_helper"
2
+
3
+ describe "brightbox sql instances resize" do
4
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
5
+ let(:stdout) { output.stdout }
6
+ let(:stderr) { output.stderr }
7
+
8
+ before do
9
+ config_from_contents(API_CLIENT_CONFIG_CONTENTS)
10
+
11
+ stub_request(:post, "http://api.brightbox.localhost/token")
12
+ .to_return(
13
+ status: 200,
14
+ body: JSON.dump(
15
+ access_token: "ACCESS-TOKEN",
16
+ refresh_token: "REFRESH_TOKEN"
17
+ )
18
+ )
19
+
20
+ Brightbox.config.reauthenticate
21
+ end
22
+
23
+ context "without arguments" do
24
+ let(:argv) { %w[sql instances resize] }
25
+
26
+ it "does not error" do
27
+ expect { output }.to_not raise_error
28
+
29
+ expect(stderr).to eq("ERROR: You must specify a valid SQL instance ID as the first argument\n")
30
+
31
+ expect(stdout).to match("")
32
+ end
33
+ end
34
+
35
+ context "with invalid ID" do
36
+ let(:argv) { %w[sql instances resize --type dbt-12345 dbs-xsd23] }
37
+
38
+ before do
39
+ stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-xsd23")
40
+ .with(query: hash_including(account_id: "acc-12345"))
41
+ .to_return(
42
+ status: 404,
43
+ body: ""
44
+ )
45
+ end
46
+
47
+ it "does not error" do
48
+ expect { output }.to_not raise_error
49
+
50
+ expect(stderr).to eq("ERROR: Couldn't find 'dbs-xsd23'\n")
51
+
52
+ expect(stdout).to match("")
53
+ end
54
+ end
55
+
56
+ context "with valid ID and invalid 'type'" do
57
+ let(:argv) { %w[sql instances resize --type embiggen dbs-e23ss] }
58
+
59
+ it "does not error" do
60
+ expect { output }.to_not raise_error
61
+
62
+ expect(stderr).to eq("ERROR: Cloud SQL type format is invalid\n")
63
+
64
+ expect(stdout).to match("")
65
+ end
66
+ end
67
+
68
+ context "with valid ID and 'type'" do
69
+ let(:argv) { %w[sql instances resize --type dbt-abcde dbs-zzasa] }
70
+
71
+ before do
72
+ stub_request(:get, "http://api.brightbox.localhost/1.0/database_servers/dbs-zzasa")
73
+ .with(query: hash_including(account_id: "acc-12345"))
74
+ .to_return(
75
+ status: 200,
76
+ body: {
77
+ id: "dbs-zzasa",
78
+ database_type: "dbt-12345"
79
+ }.to_json
80
+ )
81
+ .to_return(
82
+ status: 200,
83
+ body: {
84
+ id: "dbs-zzasa",
85
+ database_type: "dbt-abcde"
86
+ }.to_json
87
+ )
88
+
89
+ stub_request(:post, "http://api.brightbox.localhost/1.0/database_servers/dbs-zzasa/resize")
90
+ .with(query: hash_including(account_id: "acc-12345"),
91
+ body: {
92
+ new_type: "dbt-abcde"
93
+ }
94
+ )
95
+ .to_return(
96
+ status: 202,
97
+ body: {
98
+ id: "dbs-zzasa",
99
+ database_type: "dbt-abcde"
100
+ }.to_json
101
+ )
102
+ end
103
+
104
+ it "does not error" do
105
+ expect { output }.to_not raise_error
106
+
107
+ expect(stderr).to eq("Resizing dbs-zzasa\n")
108
+
109
+ expect(stdout).to match("dbs-zzasa")
110
+ end
111
+ end
112
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.5.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 1.10.0
20
+ version: 1.11.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 1.10.0
27
+ version: 1.11.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: fog-core
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -371,7 +371,9 @@ files:
371
371
  - lib/brightbox-cli/commands/sql/instances_destroy.rb
372
372
  - lib/brightbox-cli/commands/sql/instances_list.rb
373
373
  - lib/brightbox-cli/commands/sql/instances_locking.rb
374
+ - lib/brightbox-cli/commands/sql/instances_reset.rb
374
375
  - lib/brightbox-cli/commands/sql/instances_reset_password.rb
376
+ - lib/brightbox-cli/commands/sql/instances_resize.rb
375
377
  - lib/brightbox-cli/commands/sql/instances_show.rb
376
378
  - lib/brightbox-cli/commands/sql/instances_snapshot.rb
377
379
  - lib/brightbox-cli/commands/sql/instances_update.rb
@@ -656,6 +658,8 @@ files:
656
658
  - spec/commands/servers/update_spec.rb
657
659
  - spec/commands/sql/instances/create_spec.rb
658
660
  - spec/commands/sql/instances/locking_spec.rb
661
+ - spec/commands/sql/instances/reset_spec.rb
662
+ - spec/commands/sql/instances/resize_spec.rb
659
663
  - spec/commands/sql/instances/show_spec.rb
660
664
  - spec/commands/sql/instances/snapshot_spec.rb
661
665
  - spec/commands/sql/instances/update_spec.rb
@@ -813,9 +817,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
813
817
  version: '2.5'
814
818
  required_rubygems_version: !ruby/object:Gem::Requirement
815
819
  requirements:
816
- - - ">="
820
+ - - ">"
817
821
  - !ruby/object:Gem::Version
818
- version: '0'
822
+ version: 1.3.1
819
823
  requirements: []
820
824
  rubygems_version: 3.3.20
821
825
  signing_key:
@@ -1023,6 +1027,8 @@ test_files:
1023
1027
  - spec/commands/servers/update_spec.rb
1024
1028
  - spec/commands/sql/instances/create_spec.rb
1025
1029
  - spec/commands/sql/instances/locking_spec.rb
1030
+ - spec/commands/sql/instances/reset_spec.rb
1031
+ - spec/commands/sql/instances/resize_spec.rb
1026
1032
  - spec/commands/sql/instances/show_spec.rb
1027
1033
  - spec/commands/sql/instances/snapshot_spec.rb
1028
1034
  - spec/commands/sql/instances/update_spec.rb