Skip to content

Commit

Permalink
Lazy loading test, readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeDupuis committed Dec 10, 2024
1 parent 34e1689 commit 8e4ff6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Allow lazy loading the signer

## [0.5.4] 2024-11-18

- Allow creating public container
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/azure_blob/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions test/client/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8e4ff6e

Please sign in to comment.