azure-blob 0.5.4 → 0.5.6
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +13 -0
- data/lib/azure_blob/client.rb +41 -14
- data/lib/azure_blob/identity_token.rb +2 -1
- data/lib/azure_blob/user_delegation_key.rb +1 -0
- data/lib/azure_blob/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae3b7fceea9be12467a971a8145a7ebc24e4e20c9debc0ad13ec2388fdf65b8
|
4
|
+
data.tar.gz: 057cd633b835d5481e73666f2656a5e0e7bc78de5110805e647a2f95f10e0c93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ace2b7d5b08599d59db6c2d0df8bc376c9c1cc1b50b8671691c04ac4f72945e10fb588f115d5d34f662db126ddb5b8ded1f7263cf3b06f3a5e9b5141d02c084
|
7
|
+
data.tar.gz: 1f3407a9e1826f63f77c51acb0d1583724a4b30dd64418f53369d58cdf2c3da66bc48eba7899405e01c844823e9ab64c45ffde6fc68e73264cc107e3f764ec19
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.6] 2025-01-17
|
4
|
+
|
5
|
+
- Fix user delegation key not refreshing (#14)
|
6
|
+
|
7
|
+
## [0.5.5] 2025-01-10
|
8
|
+
|
9
|
+
- Allow lazy loading the signer
|
10
|
+
- Add `blob_exist?`
|
11
|
+
- Add `container_exist?`
|
12
|
+
|
3
13
|
## [0.5.4] 2024-11-18
|
4
14
|
|
5
15
|
- Allow creating public container
|
data/README.md
CHANGED
@@ -95,6 +95,19 @@ client.delete_blob(path)
|
|
95
95
|
|
96
96
|
For the full list of methods: https://www.rubydoc.info/gems/azure-blob/AzureBlob/Client
|
97
97
|
|
98
|
+
## options
|
99
|
+
|
100
|
+
### Lazy loading
|
101
|
+
|
102
|
+
The client is configured to raise an error early for missing credentials, causing it to crash before becoming healthy. This behavior can sometimes be undesirable, such as during assets precompilation.
|
103
|
+
|
104
|
+
To enable lazy loading and ignore missing credentials, set the `lazy` option:
|
105
|
+
|
106
|
+
`AzureBlob::Client.new(account_name: nil, access_key: nil, container: nil, lazy: true)`
|
107
|
+
|
108
|
+
or add `lazy: true` to your `config/storage.yml` for Active Storage.
|
109
|
+
|
110
|
+
|
98
111
|
## Contributing
|
99
112
|
|
100
113
|
### Dev environment
|
data/lib/azure_blob/client.rb
CHANGED
@@ -20,18 +20,10 @@ module AzureBlob
|
|
20
20
|
@container = container
|
21
21
|
@host = host
|
22
22
|
@cloud_regions = options[:cloud_regions]&.to_sym || :global
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if !using_managed_identities && no_access_key
|
28
|
-
raise AzureBlob::Error.new(
|
29
|
-
"`access_key` cannot be empty. To use managed identities instead, pass a `principal_id` or set `use_managed_identities` to true."
|
30
|
-
)
|
31
|
-
end
|
32
|
-
@signer = using_managed_identities ?
|
33
|
-
AzureBlob::EntraIdSigner.new(account_name:, host: self.host, principal_id:) :
|
34
|
-
AzureBlob::SharedKeySigner.new(account_name:, access_key:, host: self.host)
|
23
|
+
@access_key = access_key
|
24
|
+
@principal_id = principal_id
|
25
|
+
@use_managed_identities = options[:use_managed_identities]
|
26
|
+
signer unless options[:lazy]
|
35
27
|
end
|
36
28
|
|
37
29
|
# Create a blob of type block. Will automatically split the the blob in multiple block and send the blob in pieces (blocks) if the blob is too big.
|
@@ -150,7 +142,8 @@ module AzureBlob
|
|
150
142
|
#
|
151
143
|
# Calls to {Get Blob Properties}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties]
|
152
144
|
#
|
153
|
-
# This can be used to
|
145
|
+
# This can be used to obtain metadata such as content type, disposition, checksum or Azure custom metadata.
|
146
|
+
# To check for blob presence, look for `blob_exist?` as `get_blob_properties` raises on missing blob.
|
154
147
|
def get_blob_properties(key, options = {})
|
155
148
|
uri = generate_uri("#{container}/#{key}")
|
156
149
|
|
@@ -159,6 +152,15 @@ module AzureBlob
|
|
159
152
|
Blob.new(response)
|
160
153
|
end
|
161
154
|
|
155
|
+
# Returns a boolean indicating if the blob exists.
|
156
|
+
#
|
157
|
+
# Calls to {Get Blob Properties}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties]
|
158
|
+
def blob_exist?(key, options = {})
|
159
|
+
get_blob_properties(key, options).present?
|
160
|
+
rescue AzureBlob::Http::FileNotFoundError
|
161
|
+
false
|
162
|
+
end
|
163
|
+
|
162
164
|
# Returns the tags associated with a blob
|
163
165
|
#
|
164
166
|
# Calls to the {Get Blob Tags}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-tags] endpoint.
|
@@ -186,6 +188,13 @@ module AzureBlob
|
|
186
188
|
Container.new(response)
|
187
189
|
end
|
188
190
|
|
191
|
+
# Returns a boolean indicating if the container exists.
|
192
|
+
#
|
193
|
+
# Calls to {Get Container Properties}[https://learn.microsoft.com/en-us/rest/api/storageservices/get-container-properties]
|
194
|
+
def container_exist?(options = {})
|
195
|
+
get_container_properties(options = {}).present?
|
196
|
+
end
|
197
|
+
|
189
198
|
# Create the container
|
190
199
|
#
|
191
200
|
# Calls to {Create Container}[https://learn.microsoft.com/en-us/rest/api/storageservices/create-container]
|
@@ -364,6 +373,24 @@ module AzureBlob
|
|
364
373
|
@host ||= "https://#{account_name}.blob.#{CLOUD_REGIONS_SUFFIX[cloud_regions]}"
|
365
374
|
end
|
366
375
|
|
367
|
-
|
376
|
+
def signer
|
377
|
+
@signer ||=
|
378
|
+
begin
|
379
|
+
no_access_key = access_key.nil? || access_key&.empty?
|
380
|
+
using_managed_identities = no_access_key && !principal_id.nil? || use_managed_identities
|
381
|
+
|
382
|
+
if !using_managed_identities && no_access_key
|
383
|
+
raise AzureBlob::Error.new(
|
384
|
+
"`access_key` cannot be empty. To use managed identities instead, pass a `principal_id` or set `use_managed_identities` to true."
|
385
|
+
)
|
386
|
+
end
|
387
|
+
|
388
|
+
using_managed_identities ?
|
389
|
+
AzureBlob::EntraIdSigner.new(account_name:, host:, principal_id:) :
|
390
|
+
AzureBlob::SharedKeySigner.new(account_name:, access_key:, host:)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
attr_reader :account_name, :container, :http, :cloud_regions, :access_key, :principal_id, :use_managed_identities
|
368
395
|
end
|
369
396
|
end
|
@@ -19,7 +19,7 @@ module AzureBlob
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_s
|
22
|
-
refresh
|
22
|
+
refresh
|
23
23
|
token
|
24
24
|
end
|
25
25
|
|
@@ -30,6 +30,7 @@ module AzureBlob
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def refresh
|
33
|
+
return unless expired?
|
33
34
|
headers = { "Metadata" => "true" }
|
34
35
|
headers["X-IDENTITY-HEADER"] = ENV["IDENTITY_HEADER"] if ENV["IDENTITY_HEADER"]
|
35
36
|
|
data/lib/azure_blob/version.rb
CHANGED