azure-blob 0.5.6 → 0.5.7.1

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: 4ae3b7fceea9be12467a971a8145a7ebc24e4e20c9debc0ad13ec2388fdf65b8
4
- data.tar.gz: 057cd633b835d5481e73666f2656a5e0e7bc78de5110805e647a2f95f10e0c93
3
+ metadata.gz: b05479c9f6ba44b76af4d096021a2a887e8774caf4dcd1c2e02a98c8a2998426
4
+ data.tar.gz: 75c680b7c740b541e078cb9a1fc4f7c213719abfa68d3057a21982a1a0977320
5
5
  SHA512:
6
- metadata.gz: 3ace2b7d5b08599d59db6c2d0df8bc376c9c1cc1b50b8671691c04ac4f72945e10fb588f115d5d34f662db126ddb5b8ded1f7263cf3b06f3a5e9b5141d02c084
7
- data.tar.gz: 1f3407a9e1826f63f77c51acb0d1583724a4b30dd64418f53369d58cdf2c3da66bc48eba7899405e01c844823e9ab64c45ffde6fc68e73264cc107e3f764ec19
6
+ metadata.gz: 1116f9eec87e05685dd8177f400cc322b1a393e0d96eaf91bfe52cfb465ebc7ded753ff1c040f9dbed031038c6cca2cab80bd7eec591d4e020ac151c7a1b59af
7
+ data.tar.gz: 76a9a8840903de54253fce878ccee22ba55be7097f018c171a3b6863862fa19e2656475dbf415b609426a428212acb14d35117c55c6d8905060f3909be28d61a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.7.1] 2025-04-22
4
+
5
+ - Fixed a bug when reusing the account name in the container name. #22
6
+
7
+ ## [0.5.7] 2025-02-21
8
+
9
+ - Add `copy_blob`
10
+ - Update `compose` to use `copy_blob` if 1 source key and blob is <= 256MiB
11
+
3
12
  ## [0.5.6] 2025-01-17
4
13
 
5
14
  - Fix user delegation key not refreshing (#14)
data/Rakefile CHANGED
@@ -20,6 +20,15 @@ end
20
20
  task default: %i[test]
21
21
 
22
22
  task :test do
23
+ [
24
+ "AZURE_ACCOUNT_NAME",
25
+ "AZURE_PRIVATE_CONTAINER",
26
+ "AZURE_PUBLIC_CONTAINER",
27
+ ].each do |env|
28
+ value = ENV[env]
29
+ raise "#{env} variable need to be set if you are using the nix/devenv environment, consider running generate-env-file" if value.nil? || value.empty?
30
+ end
31
+
23
32
  Rake::Task["test_client"].execute
24
33
  Rake::Task["test_rails"].execute
25
34
  end
@@ -123,16 +123,22 @@ module ActiveStorage
123
123
  def compose(source_keys, destination_key, filename: nil, content_type: nil, disposition: nil, custom_metadata: {})
124
124
  content_disposition = content_disposition_with(type: disposition, filename: filename) if disposition && filename
125
125
 
126
- client.create_append_blob(
127
- destination_key,
128
- content_type: content_type,
129
- content_disposition: content_disposition,
130
- metadata: custom_metadata,
131
- )
132
-
133
- source_keys.each do |source_key|
134
- stream(source_key) do |chunk|
135
- client.append_blob_block(destination_key, chunk)
126
+ # use copy_blob operation if composing a new blob from a single existing blob
127
+ # and that single blob is <= 256 MiB which is the upper limit for copy_blob operation
128
+ if source_keys.length == 1 && client.get_blob_properties(source_keys[0]).size <= 256.megabytes
129
+ client.copy_blob(destination_key, source_keys[0], metadata: custom_metadata)
130
+ else
131
+ client.create_append_blob(
132
+ destination_key,
133
+ content_type: content_type,
134
+ content_disposition: content_disposition,
135
+ metadata: custom_metadata,
136
+ )
137
+
138
+ source_keys.each do |source_key|
139
+ stream(source_key) do |chunk|
140
+ client.append_blob_block(destination_key, chunk)
141
+ end
136
142
  end
137
143
  end
138
144
  end
@@ -77,6 +77,25 @@ module AzureBlob
77
77
  Http.new(uri, headers, signer:).get
78
78
  end
79
79
 
80
+ # Copy a blob
81
+ #
82
+ # Calls to {Copy Blob From URL}[https://learn.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url]
83
+ #
84
+ # Takes a key (path) and a source_key (path).
85
+ #
86
+ def copy_blob(key, source_key, options = {})
87
+ uri = generate_uri("#{container}/#{key}")
88
+
89
+ source_uri = signed_uri(source_key, permissions: "r", expiry: Time.at(Time.now.to_i + 300).utc.iso8601)
90
+
91
+ headers = {
92
+ "x-ms-copy-source": source_uri.to_s,
93
+ "x-ms-requires-sync": "true",
94
+ }
95
+
96
+ Http.new(uri, headers, signer:, **options.slice(:metadata, :tags)).put
97
+ end
98
+
80
99
  # Delete a blob
81
100
  #
82
101
  # Calls to {Delete Blob}[https://learn.microsoft.com/en-us/rest/api/storageservices/delete-blob]
@@ -202,7 +221,7 @@ module AzureBlob
202
221
  uri = generate_uri(container)
203
222
  headers = {}
204
223
  headers[:"x-ms-blob-public-access"] = "blob" if options[:public_access]
205
- headers[:"x-ms-blob-public-access"] = options[:public_access] if ["container","blob"].include?(options[:public_access])
224
+ headers[:"x-ms-blob-public-access"] = options[:public_access] if [ "container", "blob" ].include?(options[:public_access])
206
225
 
207
226
  uri.query = URI.encode_www_form(restype: "container")
208
227
  response = Http.new(uri, headers, signer:).put
@@ -11,7 +11,7 @@ module AzureBlob
11
11
  @account_name = account_name
12
12
  @access_key = Base64.decode64(access_key)
13
13
  @host = host
14
- @remove_prefix = @host.include?("/#{@account_name}")
14
+ @remove_prefix = @host.end_with?("/#{@account_name}")
15
15
  end
16
16
 
17
17
  def authorization_header(uri:, verb:, headers: {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AzureBlob
4
- VERSION = "0.5.6"
4
+ VERSION = "0.5.7.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-blob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis