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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15d8cb5bf91f904bff341c26f5f6b6392abbb14e0de1f092fab8697cabab75b1
4
- data.tar.gz: de847a4e6a9925b31ed1900dea10e8e0d078277f4af4e4e7f434b00e4e0bc298
3
+ metadata.gz: f67999e9a3c71ecac32f52a65dae1e4bf82e76704f97ecdaed08c84b66df5630
4
+ data.tar.gz: 19fedb6d95a7d1c14da8baa8e3f608b4c3ae8e99f76a68daa5a54efe7213858a
5
5
  SHA512:
6
- metadata.gz: ef60c4be02b9725ba53209234d471a71451fe7270a58c4fad908c5e06669cb686290cd7ce75e57dfced02fc1d1efee85e3201d0d05b868881abe16e13fb77e68
7
- data.tar.gz: 1460b8c46b849b0e1a89e2e628cf20dad0ba223dc3e090e7f8ce3bc16d124db497f0785144eed3a8c48210e2d085bb4c178f74d9ff18c77da98ce21d65f6af45
6
+ metadata.gz: 42405d38134512ed6ac88372c8a2e7383835e2d3558280b8dad0570532d905c6edaba6bfb84bd3fd2478f3a4456d575da5448bb223e016b89f99a96bd00bcec2
7
+ data.tar.gz: f5148357bb3ba47ea5d730ebc123a2ab901e8c9380d7c7d6620cf6fd6623ec495f9dc0659434be42458888f6a936ffd221bd9f27591f3fbce2f0b0361fee5b9f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.5] 2025-01-10
4
+
5
+ - Allow lazy loading the signer
6
+ - Add `blob_exist?`
7
+ - Add `container_exist?`
8
+
3
9
  ## [0.5.4] 2024-11-18
4
10
 
5
11
  - 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
@@ -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
- no_access_key = access_key.nil? || access_key&.empty?
25
- using_managed_identities = no_access_key && !principal_id.nil? || options[:use_managed_identities]
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 see if the blob exist or obtain metadata such as content type, disposition, checksum or Azure custom metadata.
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
- attr_reader :account_name, :signer, :container, :http, :cloud_regions
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AzureBlob
4
- VERSION = "0.5.4"
4
+ VERSION = "0.5.5"
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.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis