fog-brightbox 1.7.1 → 1.8.0

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: 6e454f9c0dfb541dfcb036712499e20160fb9743ab0da50776252bc6f53516f7
4
- data.tar.gz: a69d2679435006c7c1da3997aa61b38ce5f180b0d1f20b422f7e2c370dc1b753
3
+ metadata.gz: 2fd48abde8380eb206f3b30abcb6000a8bec7c066d1913649efdde89719f0a79
4
+ data.tar.gz: b75f15aabc38798dcb1a8bcb13eb3e0b66e9ee9fe93beb91e462808d822f9fb7
5
5
  SHA512:
6
- metadata.gz: 00302c2501178651b3aa88100cceec4a5acd33f6feb39ae27aa03935e8e95c5796b2f5c144bb457936d1694791afcaa3b0689cae1e16d81ca02b8c81c63383bb
7
- data.tar.gz: b072d486bfd7f2a8a4b7a0cf747be18c3db59a7e8b66553ae4183500c33a4e4adb67baa405c58dd7063ba6630141879c92ba380c82da4f9233d9fdb40589b0b9
6
+ metadata.gz: 6ea1059b94824d5ae37fda327001f94704a544fd29bfa7825627599cef850653fdcb55c18d493352af9bb1afd6864faf89c2d824da4baccd9fcdbd0d020096e4
7
+ data.tar.gz: 464af05ddefa022497cce27fb7535eaac5f9db282e32037e922780f0ab05f96eb1f72ccad07f9ad5860c5a2e62228a5a05c676ee83e666507d1a62191e7f3580
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ### 1.8.0 / 2022-08-31
2
+
3
+ Changes:
4
+
5
+ * Allow custom `volume_size` in server creation where supported
6
+
7
+ ### 1.7.3 / 2022-08-17
8
+
9
+ Bug fixes:
10
+
11
+ * Fix to deduplicate forward slashes in `Storage::File#public_url` when object keys are prefixed with "/"
12
+
13
+ ### 1.7.2 / 2022-08-17
14
+
15
+ Bug fixes:
16
+
17
+ * Fix in `Storage.escape` regexp which failed to handle dashes correctly and broke generated URLs.
18
+
1
19
  ### 1.7.1 / 2022-08-17
2
20
 
3
21
  Bug fixes:
@@ -8,6 +8,7 @@ module Fog
8
8
  include Fog::Brightbox::Compute::ResourceLocking
9
9
 
10
10
  attr_accessor :volume_id
11
+ attr_accessor :volume_size
11
12
 
12
13
  identity :id
13
14
  attribute :resource_type
@@ -197,7 +198,16 @@ module Fog
197
198
  options.merge!(:disk_encrypted => disk_encrypted) if disk_encrypted
198
199
 
199
200
  if volume_id
200
- options.merge!(:volumes => [:volume => volume_id])
201
+ options.merge!(:volumes => [{ volume: volume_id }])
202
+ elsif volume_size
203
+ options.merge!(
204
+ volumes: [
205
+ {
206
+ image: image_id,
207
+ size: volume_size
208
+ }
209
+ ]
210
+ )
201
211
  else
202
212
  options.merge!(:image => image_id)
203
213
  end
@@ -32,7 +32,8 @@ module Fog
32
32
 
33
33
  def public_url
34
34
  requires :key
35
- @public_url ||= [service.management_url , Fog::Brightbox::Storage.escape(key, "/")].join("/")
35
+ @public_url ||= ::File.join(service.management_url.to_s,
36
+ Fog::Brightbox::Storage.escape(key, "/"))
36
37
  end
37
38
 
38
39
  def save
@@ -63,9 +63,9 @@ module Fog
63
63
 
64
64
  def get_url(key)
65
65
  requires :directory
66
- if directory.public_url
67
- "#{directory.public_url}/#{Fog::Brightbox::Storage.escape(key, "/")}"
68
- end
66
+ return unless directory.public_url
67
+
68
+ ::File.join(directory.public_url, Fog::Brightbox::Storage.escape(key, "/"))
69
69
  end
70
70
 
71
71
  def get_http_url(key, expires, options = {})
@@ -215,7 +215,8 @@ module Fog
215
215
 
216
216
  # CGI.escape, but without special treatment on spaces
217
217
  def self.escape(str, extra_exclude_chars = "")
218
- str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
218
+ # Includes fix to Regexp so "-" is correctly handled by placing last
219
+ str.gsub(/([^a-zA-Z0-9_.#{extra_exclude_chars}-]+)/) do
219
220
  "%" + Regexp.last_match[1].unpack("H2" * Regexp.last_match[1].bytesize).join("%").upcase
220
221
  end
221
222
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Brightbox
3
- VERSION = "1.7.1"
3
+ VERSION = "1.8.0"
4
4
  end
5
5
  end
@@ -0,0 +1,62 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+
4
+ describe Fog::Brightbox::Storage, ".escape" do
5
+ describe "when only excluded characters are used" do
6
+ it "escapes no letters" do
7
+ str = ("A".."Z").to_a.join
8
+ escaped = Fog::Brightbox::Storage.escape(str)
9
+ assert_equal str, escaped
10
+
11
+ str = ("a".."z").to_a.join
12
+ escaped = Fog::Brightbox::Storage.escape(str)
13
+ assert_equal str, escaped
14
+ end
15
+
16
+ it "escapes no numbers" do
17
+ str = ("0".."9").to_a.join
18
+ escaped = Fog::Brightbox::Storage.escape(str)
19
+ assert_equal str, escaped
20
+ end
21
+
22
+ it "does not escape dashes" do
23
+ str = "test-pattern123"
24
+ escaped = Fog::Brightbox::Storage.escape(str)
25
+ assert_equal str, escaped
26
+ end
27
+
28
+ it "does not escape dots" do
29
+ str = "sample.demo"
30
+ escaped = Fog::Brightbox::Storage.escape(str)
31
+ assert_equal str, escaped
32
+ end
33
+
34
+ it "does not escape underscores" do
35
+ str = "file_name"
36
+ escaped = Fog::Brightbox::Storage.escape(str)
37
+ assert_equal str, escaped
38
+ end
39
+ end
40
+
41
+ describe "when escaped characters are included" do
42
+ it "escapes those forward slashes" do
43
+ str = "test/pattern/123.txt"
44
+ escaped = Fog::Brightbox::Storage.escape(str)
45
+ assert_equal "test%2Fpattern%2F123.txt", escaped
46
+ end
47
+
48
+ it "escapes those backslashes" do
49
+ str = "test\\pattern\\123.txt"
50
+ escaped = Fog::Brightbox::Storage.escape(str)
51
+ assert_equal "test%5Cpattern%5C123.txt", escaped
52
+ end
53
+ end
54
+
55
+ describe "when additional characters are excluded" do
56
+ it "escapes those characters" do
57
+ str = "test/pattern/123.txt"
58
+ escaped = Fog::Brightbox::Storage.escape(str, "/")
59
+ assert_equal "test/pattern/123.txt", escaped
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,88 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+ require "fog/brightbox/models/storage/directory"
4
+ require "fog/brightbox/models/storage/files"
5
+
6
+ describe Fog::Brightbox::Storage::Files do
7
+ describe "#get_url" do
8
+ before do
9
+ @options = {
10
+ :brightbox_client_id => "cli-12345",
11
+ :brightbox_secret => "1234567890",
12
+ :brightbox_storage_management_url => "https://management.url/v1/acc-12345"
13
+ }
14
+ @service = Fog::Brightbox::Storage.new(@options)
15
+ end
16
+
17
+ describe "when directory can generate URL" do
18
+ describe "with object prefixed by forward slash" do
19
+ it do
20
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
21
+
22
+ directory = Fog::Brightbox::Storage::Directory.new(
23
+ service: @service,
24
+ key: "container-name"
25
+ )
26
+ assert_equal "https://management.url/v1/acc-12345/container-name", directory.public_url
27
+
28
+ files = Fog::Brightbox::Storage::Files.new(
29
+ service: @service,
30
+ directory: directory
31
+ )
32
+
33
+ expected = "https://management.url/v1/acc-12345/container-name/object"
34
+
35
+ assert_equal expected, files.get_url("/object")
36
+ end
37
+ end
38
+
39
+ describe "when object is correctly named" do
40
+ it do
41
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
42
+
43
+ directory = Fog::Brightbox::Storage::Directory.new(
44
+ service: @service,
45
+ key: "container-name"
46
+ )
47
+ assert_equal "https://management.url/v1/acc-12345/container-name", directory.public_url
48
+
49
+ files = Fog::Brightbox::Storage::Files.new(
50
+ service: @service,
51
+ directory: directory
52
+ )
53
+
54
+ expected = "https://management.url/v1/acc-12345/container-name/object"
55
+
56
+ assert_equal expected, files.get_url("object")
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "when no management URL" do
62
+ before do
63
+ @options = {
64
+ :brightbox_client_id => "cli-12345",
65
+ :brightbox_secret => "1234567890"
66
+ }
67
+ @service = Fog::Brightbox::Storage.new(@options)
68
+ end
69
+
70
+ it do
71
+ assert_equal "", @service.management_url.to_s
72
+
73
+ directory = Fog::Brightbox::Storage::Directory.new(
74
+ service: @service,
75
+ key: "container-name"
76
+ )
77
+ assert_equal "/container-name", directory.public_url
78
+
79
+ files = Fog::Brightbox::Storage::Files.new(
80
+ service: @service,
81
+ directory: directory
82
+ )
83
+
84
+ assert_equal "/container-name/object", files.get_url("/object")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,34 @@
1
+ require "minitest/autorun"
2
+ require "fog/brightbox"
3
+
4
+ describe Fog::Brightbox::Storage do
5
+ describe "when passed in configuration" do
6
+ before do
7
+ @options = {
8
+ :brightbox_client_id => "cli-12345",
9
+ :brightbox_secret => "1234567890",
10
+ :brightbox_storage_management_url => "https://management.url/v1/acc-12345"
11
+ }
12
+ @service = Fog::Brightbox::Storage.new(@options)
13
+ end
14
+
15
+ it "returns a URI matching config option" do
16
+ assert_kind_of URI, @service.management_url
17
+ assert_equal "https://management.url/v1/acc-12345", @service.management_url.to_s
18
+ end
19
+ end
20
+
21
+ describe "when unavailable" do
22
+ before do
23
+ @options = {
24
+ :brightbox_client_id => "cli-12345",
25
+ :brightbox_secret => "1234567890"
26
+ }
27
+ @service = Fog::Brightbox::Storage.new(@options)
28
+ end
29
+
30
+ it "returns nil" do
31
+ assert_nil @service.management_url
32
+ end
33
+ end
34
+ end
@@ -20,7 +20,7 @@ describe Fog::Brightbox::Compute::Server do
20
20
  end
21
21
 
22
22
  describe "when creating" do
23
- describe "with required image_id" do
23
+ describe "with image_id" do
24
24
  it "sends correct JSON" do
25
25
  options = {
26
26
  image_id: "img-12345"
@@ -38,6 +38,33 @@ describe Fog::Brightbox::Compute::Server do
38
38
  end
39
39
  end
40
40
 
41
+ describe "with image_id and custom size" do
42
+ it "sends correct JSON" do
43
+ options = {
44
+ image_id: "img-12345",
45
+ volume_size: 25_000
46
+ }
47
+ expected_args = {
48
+ volumes: [
49
+ {
50
+ image: "img-12345",
51
+ size: 25_000
52
+ }
53
+ ]
54
+ }
55
+
56
+ stub_request(:post, "http://localhost/1.0/servers").
57
+ with(:query => hash_including(:account_id),
58
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
59
+ "Content-Type" => "application/json" },
60
+ :body => hash_including(expected_args)).
61
+ to_return(:status => 202, :body => %q({"id":"srv-12345"}), :headers => {})
62
+
63
+ @server = Fog::Brightbox::Compute::Server.new({ :service => service }.merge(options))
64
+ assert @server.save
65
+ end
66
+ end
67
+
41
68
  describe "with additional disk_encrypted" do
42
69
  it "sends correct JSON" do
43
70
  options = {
@@ -61,6 +88,27 @@ describe Fog::Brightbox::Compute::Server do
61
88
  end
62
89
  end
63
90
 
91
+ describe "with volume_id" do
92
+ it "sends correct JSON" do
93
+ options = {
94
+ volume_id: "vol-12345"
95
+ }
96
+ expected_args = {
97
+ volumes: [{ volume: "vol-12345" }]
98
+ }
99
+
100
+ stub_request(:post, "http://localhost/1.0/servers").
101
+ with(:query => hash_including(:account_id),
102
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
103
+ "Content-Type" => "application/json" },
104
+ :body => hash_including(expected_args)).
105
+ to_return(:status => 202, :body => %q({"id":"srv-12345"}), :headers => {})
106
+
107
+ @server = Fog::Brightbox::Compute::Server.new({ :service => service }.merge(options))
108
+ assert @server.save
109
+ end
110
+ end
111
+
64
112
  describe "when snapshotting with no options" do
65
113
  it "returns the server" do
66
114
  stub_request(:post, "http://localhost/1.0/servers/srv-12345/snapshot").
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-brightbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Thornthwaite
@@ -403,6 +403,9 @@ files:
403
403
  - spec/fog/brightbox/storage/config_spec.rb
404
404
  - spec/fog/brightbox/storage/connection_errors_spec.rb
405
405
  - spec/fog/brightbox/storage/connection_spec.rb
406
+ - spec/fog/brightbox/storage/escape_spec.rb
407
+ - spec/fog/brightbox/storage/files_spec.rb
408
+ - spec/fog/brightbox/storage_spec.rb
406
409
  - spec/fog/compute/brightbox/account_spec.rb
407
410
  - spec/fog/compute/brightbox/api_client_spec.rb
408
411
  - spec/fog/compute/brightbox/application_spec.rb
@@ -513,6 +516,9 @@ test_files:
513
516
  - spec/fog/brightbox/storage/config_spec.rb
514
517
  - spec/fog/brightbox/storage/connection_errors_spec.rb
515
518
  - spec/fog/brightbox/storage/connection_spec.rb
519
+ - spec/fog/brightbox/storage/escape_spec.rb
520
+ - spec/fog/brightbox/storage/files_spec.rb
521
+ - spec/fog/brightbox/storage_spec.rb
516
522
  - spec/fog/compute/brightbox/account_spec.rb
517
523
  - spec/fog/compute/brightbox/api_client_spec.rb
518
524
  - spec/fog/compute/brightbox/application_spec.rb