brightbox-cli 4.3.2 → 4.5.0.rc1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c813c009698fa955e24ce5399a95d658f8e0f657881071fcea65a3349d958676
4
- data.tar.gz: b7d1cfd6faf802ea27599226aedf2632b7d33dff89b4a018b26bd4587cc5069a
3
+ metadata.gz: f0ce8d035bac2e5f7df7990bbb5d1d726e3635b8a1bae0bea5ab2afa764755bc
4
+ data.tar.gz: 99eb62ee760ca495bcf2d5f38adf3eb2b1b5f95c0587b1acf1bc796db779b2ae
5
5
  SHA512:
6
- metadata.gz: ccd5f260951570479dacfbd428abb919a5ab35447d2699f05ff8552ba1c2fb0d3b27dfc9a749a3b0c9b0e4522d5a21b4bf13cecf5c13560798505548a10a9e4d
7
- data.tar.gz: '051800a849a0b1f62b6351866e3daa687016b4cb2b6eb62aa0dc7c057fb73896c6bc23a30dc7e0c01b5a9b5fc92c25a7a723daa0245e16cb733c4d40b10de03d'
6
+ metadata.gz: f3630fd90082b69c561736854708c8132b7cb08e346bce2ea5f97318ce3478cc0fdbdc2840e393bf0816064e9894ebc857d866bebdfaf416cc8781e4914b39a5
7
+ data.tar.gz: 5188e419ae8dff029ddf0bf2ec1c8806774e50462628e4d0f5681ac42931505f5218fee300256755830f9c69c3041e4ec39af9ee64780c8fe2e13f5b0e3e9ee0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
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
+
10
+ ### v4.4.0 / 2023-01-26
11
+
12
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.3.2...v4.4.0)
13
+
14
+ Enhancements:
15
+
16
+ * Added `configmaps` subcommand for manage config management.
17
+
1
18
  ### v4.3.2 / 2023-01-12
2
19
 
3
20
  [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v4.3.1...v4.3.2)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightbox-cli (4.3.2)
4
+ brightbox-cli (4.5.0.rc1)
5
5
  dry-inflector (= 0.2.0)
6
- fog-brightbox (>= 1.9.1)
6
+ fog-brightbox (>= 1.11.0)
7
7
  fog-core (< 2.0)
8
8
  gli (~> 2.21)
9
9
  highline (~> 2.0)
@@ -20,13 +20,13 @@ GEM
20
20
  ast (2.4.2)
21
21
  builder (3.2.4)
22
22
  coderay (1.1.3)
23
- concurrent-ruby (1.1.10)
23
+ concurrent-ruby (1.2.0)
24
24
  crack (0.4.5)
25
25
  rexml
26
26
  diff-lcs (1.5.0)
27
27
  dry-inflector (0.2.0)
28
- excon (0.97.1)
29
- fog-brightbox (1.9.1)
28
+ excon (0.97.2)
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.9.1"
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,183 @@
1
+ module Brightbox
2
+ desc I18n.t("configmaps.desc")
3
+ command [:configmaps] do |cmd|
4
+ cmd.default_command :list
5
+
6
+ cmd.desc I18n.t("configmaps.create.desc")
7
+ cmd.arg_name I18n.t("configmaps.args.one")
8
+ cmd.command [:create] do |c|
9
+ c.desc I18n.t("options.name.desc")
10
+ c.flag %i[n name]
11
+
12
+ c.desc I18n.t("configmaps.options.data_string")
13
+ c.flag %i[d data]
14
+
15
+ c.desc I18n.t("configmaps.options.data_file")
16
+ c.flag [:"data-file"]
17
+
18
+ c.action do |global_options, options, _args|
19
+ map_data = parse_configmap_data_options(options)
20
+
21
+ raise I18n.t("configmaps.create.data_required") if map_data.nil?
22
+
23
+ # Attempt to parse data as JSON but do not update
24
+ begin
25
+ JSON.parse(map_data)
26
+ rescue StandardError
27
+ raise I18n.t("configmaps.options.bad_data")
28
+ end
29
+
30
+ params = {
31
+ data: map_data
32
+ }
33
+ params[:name] = options[:name] if options[:name]
34
+
35
+ info I18n.t("configmaps.create.acting")
36
+ config_map = ConfigMap.create(params)
37
+
38
+ render_table([config_map], global_options)
39
+ end
40
+ end
41
+
42
+ cmd.desc I18n.t("configmaps.destroy.desc")
43
+ cmd.arg_name I18n.t("configmaps.args.many")
44
+ cmd.command [:destroy] do |c|
45
+ c.action do |_global_options, _options, args|
46
+ raise I18n.t("configmaps.args.specify_many_ids") if args.empty?
47
+
48
+ config_maps = ConfigMap.find_or_call(args) do |id|
49
+ raise I18n.t("configmaps.args.unknown_id", config_map: id)
50
+ end
51
+
52
+ config_maps.each do |config_map|
53
+ info I18n.t("configmaps.destroy.acting", config_map: config_map)
54
+
55
+ begin
56
+ config_map.destroy
57
+ rescue Brightbox::Api::Conflict
58
+ error I18n.t("configmaps.destroy.failed", config_map: id)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ cmd.desc I18n.t("configmaps.list.desc")
65
+ cmd.arg_name I18n.t("configmaps.args.optional")
66
+ cmd.command [:list] do |c|
67
+ c.action do |global_options, _options, args|
68
+ config_maps = ConfigMap.find_all_or_warn(args)
69
+
70
+ render_table(config_maps, global_options)
71
+ end
72
+ end
73
+
74
+ cmd.desc I18n.t("configmaps.show.desc")
75
+ cmd.arg_name I18n.t("configmaps.args.optional")
76
+ cmd.command [:show] do |c|
77
+ c.desc I18n.t("configmaps.options.data_output")
78
+ c.switch [:data], negatable: false, default: false
79
+
80
+ c.desc I18n.t("configmaps.options.data_format")
81
+ c.flag [:format]
82
+
83
+ c.action do |global_options, options, args|
84
+ if options[:data]
85
+ unless args.length == 1
86
+ raise I18n.t("configmaps.options.data_args")
87
+ end
88
+
89
+ cfg_id = args[0]
90
+
91
+ if cfg_id.nil? || !cfg_id.start_with?("cfg-")
92
+ raise I18n.t("configmaps.args.specify_one_id_first")
93
+ end
94
+
95
+ config_map = ConfigMap.find(cfg_id)
96
+ data(config_map.format_data(options[:format] || "json"))
97
+ else
98
+ if options[:format] && !options[:data]
99
+ raise I18n.t("configmaps.options.format_no_data")
100
+ end
101
+
102
+ config_maps = ConfigMap.find_all_or_warn(args)
103
+
104
+ table_opts = global_options.merge(
105
+ vertical: true
106
+ )
107
+ render_table(config_maps, table_opts)
108
+ end
109
+ end
110
+ end
111
+
112
+ cmd.desc I18n.t("configmaps.update.desc")
113
+ cmd.arg_name I18n.t("configmaps.args.one")
114
+ cmd.command [:update] do |c|
115
+ c.desc I18n.t("options.name.desc")
116
+ c.flag %i[n name]
117
+
118
+ c.desc I18n.t("configmaps.options.data_string")
119
+ c.flag %i[d data]
120
+
121
+ c.desc I18n.t("configmaps.options.data_file")
122
+ c.flag [:"data-file"]
123
+
124
+ c.action do |global_options, options, args|
125
+ cfg_id = args[0]
126
+
127
+ if cfg_id.nil? || !cfg_id.start_with?("cfg-")
128
+ raise I18n.t("configmaps.args.specify_one_id_first")
129
+ end
130
+
131
+ params = {}
132
+ params[:name] = options[:name] if options[:name]
133
+
134
+ map_data = parse_configmap_data_options(options)
135
+
136
+ if map_data
137
+ begin
138
+ map_data = JSON.parse(map_data)
139
+ rescue StandardError
140
+ raise I18n.t("configmaps.options.bad_data")
141
+ end
142
+
143
+ params[:data] = map_data
144
+ end
145
+
146
+ config_map = ConfigMap.find(cfg_id)
147
+
148
+ unless params.empty?
149
+ info I18n.t("configmaps.update.acting", config_map: config_map)
150
+ config_map.update(params)
151
+ end
152
+
153
+ render_table([config_map], global_options)
154
+ end
155
+ end
156
+ end
157
+
158
+ def parse_configmap_data_options(options)
159
+ if options[:data] && options[:"data-file"]
160
+ raise I18n.t("configmaps.options.multiple_data")
161
+ end
162
+
163
+ map_data = options[:data]
164
+ data_filename = options[:"data-file"]
165
+
166
+ if data_filename
167
+ file_handler = lambda do |file|
168
+ map_data = file.read
169
+ end
170
+
171
+ if data_filename == "-"
172
+ file_handler[$stdin]
173
+ else
174
+ File.open(data_filename, "r", &file_handler)
175
+ end
176
+
177
+ raise map_data.inspect if map_data.nil? || map_data == ""
178
+ end
179
+
180
+ map_data
181
+ end
182
+ module_function :parse_configmap_data_options
183
+ end
@@ -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
@@ -0,0 +1,53 @@
1
+ module Brightbox
2
+ class ConfigMap < Api
3
+ def self.require_account?; true; end
4
+
5
+ def self.all
6
+ conn.config_maps
7
+ end
8
+
9
+ def self.create(options)
10
+ new(conn.config_maps.create(options))
11
+ end
12
+
13
+ def self.get(id)
14
+ conn.config_maps.get(id)
15
+ end
16
+
17
+ def self.default_field_order
18
+ %i[id name]
19
+ end
20
+
21
+ def self.detailed_fields
22
+ %i[
23
+ id
24
+ name
25
+ ]
26
+ end
27
+
28
+ def format_data(format)
29
+ case format.to_sym
30
+ when :text
31
+ attributes[:data].map do |key, value|
32
+ "#{key.to_s.rjust(16)}: #{value}"
33
+ end.join("\n")
34
+ else
35
+ JSON.dump(data)
36
+ end
37
+ end
38
+
39
+ def to_row
40
+ {
41
+ id: attributes[:id],
42
+ name: attributes[:name],
43
+ data: attributes[:data]
44
+ }
45
+ end
46
+
47
+ def update(options)
48
+ self.class.conn.update_config_map(id, options)
49
+ reload
50
+ self
51
+ end
52
+ end
53
+ 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.3.2".freeze unless defined?(Brightbox::VERSION)
2
+ VERSION = "4.5.0.rc1".freeze unless defined?(Brightbox::VERSION)
3
3
  end
data/lib/brightbox_cli.rb CHANGED
@@ -53,6 +53,7 @@ module Brightbox
53
53
  autoload :FirewallRule, File.expand_path("brightbox-cli/firewall_rule", __dir__)
54
54
  autoload :FirewallRules, File.expand_path("brightbox-cli/firewall_rules", __dir__)
55
55
  autoload :Collaboration, File.expand_path("brightbox-cli/collaboration", __dir__)
56
+ autoload :ConfigMap, File.expand_path("brightbox-cli/config_map", __dir__)
56
57
  autoload :UserCollaboration, File.expand_path("brightbox-cli/user_collaboration", __dir__)
57
58
  autoload :DatabaseType, File.expand_path("brightbox-cli/database_type", __dir__)
58
59
  autoload :DatabaseServer, File.expand_path("brightbox-cli/database_server", __dir__)
data/locales/en.yml CHANGED
@@ -51,6 +51,39 @@ en:
51
51
  desc: Remove an API client from config
52
52
  user_add:
53
53
  desc: Add new user credentials to config
54
+ configmaps:
55
+ desc: Manage config maps
56
+ args:
57
+ one: <configmap>
58
+ optional: "[<configmap>...]"
59
+ many: <configmap>...
60
+ specify_one_id_first: You must specify the config map ID as the first argument
61
+ specify_many_ids: You must specify config map IDs as arguments
62
+ unknown_id: Couldn't find %{config_map}
63
+ options:
64
+ data_args: You can only access data for a single config map at a time
65
+ data_file: A path to a file contain a JSON object containing key/values, or '-' for STDIO
66
+ data_string: String representing a valid JSON object
67
+ data_output: Return the config map data key/values
68
+ data_format: "Format to return 'data' in: 'json' (default) or 'text'"
69
+ format_no_data: The 'format' option can only be used with 'data'
70
+ bad_data: Config map data was not valid JSON
71
+ multiple_data: Config map data can only be passed by either 'data' or 'data-file'
72
+ create:
73
+ desc: Create a config map
74
+ acting: Creating config map
75
+ data_required: Config map data is required as 'data' option
76
+ destroy:
77
+ desc: Destroy config maps
78
+ acting: Destroying %{config_map}
79
+ failed: Failed to destroy %{config_map}
80
+ list:
81
+ desc: List config maps
82
+ show:
83
+ desc: Show config maps
84
+ update:
85
+ desc: Update a config map
86
+ acting: Updating %{config_map}
54
87
  firewall:
55
88
  policies:
56
89
  desc: Manage firewall policies
@@ -174,6 +207,14 @@ en:
174
207
  desc: Manage an account's Cloud SQL instances and snapshots
175
208
  instances:
176
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}
177
218
  options:
178
219
  allow_access:
179
220
  desc: Comma separated list of IPs or IDs for servers or groups to allow access
@@ -197,6 +238,7 @@ en:
197
238
  desc: Clear an existing snapshots schedule
198
239
  type:
199
240
  desc: ID of a Cloud SQL type
241
+ invalid: Cloud SQL type format is invalid
200
242
  zone:
201
243
  desc: Zone to locate the instance in
202
244
  create:
@@ -207,8 +249,16 @@ en:
207
249
  desc: Lock Cloud SQL instances
208
250
  list:
209
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}
210
256
  reset_password:
211
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}
212
262
  show:
213
263
  desc: Show details of Cloud SQL instances
214
264
  snapshot: