azure-blob 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +13 -0
- data/lib/azure_blob/client.rb +41 -14
- 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: f67999e9a3c71ecac32f52a65dae1e4bf82e76704f97ecdaed08c84b66df5630
|
4
|
+
data.tar.gz: 19fedb6d95a7d1c14da8baa8e3f608b4c3ae8e99f76a68daa5a54efe7213858a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42405d38134512ed6ac88372c8a2e7383835e2d3558280b8dad0570532d905c6edaba6bfb84bd3fd2478f3a4456d575da5448bb223e016b89f99a96bd00bcec2
|
7
|
+
data.tar.gz: f5148357bb3ba47ea5d730ebc123a2ab901e8c9380d7c7d6620cf6fd6623ec495f9dc0659434be42458888f6a936ffd221bd9f27591f3fbce2f0b0361fee5b9f
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/azure_blob/version.rb
CHANGED