Skip to content

Commit 4d5b925

Browse files
committed
Lazy loading test, readme and changelog
1 parent 34e1689 commit 4d5b925

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Allow lazy loading the signer
4+
35
## [0.5.4] 2024-11-18
46

57
- Allow creating public container

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ client.delete_blob(path)
9595

9696
For the full list of methods: https://www.rubydoc.info/gems/azure-blob/AzureBlob/Client
9797

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+
98111
## Contributing
99112

100113
### Dev environment

lib/azure_blob/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(account_name:, access_key: nil, principal_id: nil, container:, ho
2323
@access_key = access_key
2424
@principal_id = principal_id
2525
@use_managed_identities = options[:use_managed_identities]
26+
signer unless options[:lazy]
2627
end
2728

2829
# 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.

test/client/test_client.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ def test_without_credentials
6666
)
6767
end
6868

69+
def test_lazy_loading_doesnt_raise_before_querying
70+
client = AzureBlob::Client.new(
71+
account_name: @account_name,
72+
container: @container,
73+
lazy: true,
74+
)
75+
76+
assert_raises(AzureBlob::Error) do
77+
client.create_block_blob(key, content)
78+
end
79+
end
80+
6981
def test_single_block_upload
7082
client.create_block_blob(key, content)
7183

0 commit comments

Comments
 (0)