diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e14ed1..0874f89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Allow lazy loading the signer + ## [0.5.4] 2024-11-18 - Allow creating public container diff --git a/README.md b/README.md index 550d1b0..a8a02db 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,21 @@ client.delete_blob(path) For the full list of methods: https://www.rubydoc.info/gems/azure-blob/AzureBlob/Client +## options + +### Lazy loading + +The client is setup to raise early for missing credentials so that it crashes before becoming healthy. +That is sometimes undesirable. During assets precompilation for example. + +To lazy load and ignore missing credentials, set the lazy option: + + +`AzureBlob::Client.new(account_name: nil, access_key: nil, container: nil, lazy: true)` + +or add `lazy: true` to your `config/storage.yml` for Active Storage. + + ## Contributing ### Dev environment diff --git a/lib/azure_blob/client.rb b/lib/azure_blob/client.rb index 0fdbd1f..7660517 100644 --- a/lib/azure_blob/client.rb +++ b/lib/azure_blob/client.rb @@ -23,6 +23,7 @@ def initialize(account_name:, access_key: nil, principal_id: nil, container:, ho @access_key = access_key @principal_id = principal_id @use_managed_identities = options[:use_managed_identities] + signer unless options[:lazy] end # 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. diff --git a/test/client/test_client.rb b/test/client/test_client.rb index 6585723..a295f0e 100644 --- a/test/client/test_client.rb +++ b/test/client/test_client.rb @@ -66,6 +66,18 @@ def test_without_credentials ) end + def test_lazy_loading_doesnt_raise_before_querying + client = AzureBlob::Client.new( + account_name: @account_name, + container: @container, + lazy: true, + ) + + assert_raises(AzureBlob::Error) do + client.create_block_blob(key, content) + end + end + def test_single_block_upload client.create_block_blob(key, content)