Skip to content

Commit

Permalink
Remove path config option from Azure service
Browse files Browse the repository at this point in the history
The Active Storage service for Azure Storage has an option called `path`
that is ambiguous in meaning. It needs to be set to the primary blob
storage endpoint but that can be determined from the blobs client anyway.

To simplify the configuration this commit removes the `path` option and
gets the endpoint from the blobs client instead.

Closes #32225.
  • Loading branch information
pixeltrix committed Mar 12, 2018
1 parent bb2fddc commit 50182d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions activestorage/CHANGELOG.md
@@ -1,3 +1,16 @@
* Remove path config option from Azure service.

The Active Storage service for Azure Storage has an option called `path`
that is ambiguous in meaning. It needs to be set to the primary blob
storage endpoint but that can be determined from the blobs client anyway.

To simplify the configuration, we've removed the `path` option and
now get the endpoint from the blobs client instead.

Closes #32225.

*Andrew White*

* Generate root-relative paths in disk service URL methods.

Obviate the disk service's `:host` configuration option.
Expand Down
16 changes: 10 additions & 6 deletions activestorage/lib/active_storage/service/azure_storage_service.rb
Expand Up @@ -8,14 +8,13 @@ module ActiveStorage
# Wraps the Microsoft Azure Storage Blob Service as an Active Storage service.
# See ActiveStorage::Service for the generic API documentation that applies to all services.
class Service::AzureStorageService < Service
attr_reader :client, :path, :blobs, :container, :signer
attr_reader :client, :blobs, :container, :signer

def initialize(path:, storage_account_name:, storage_access_key:, container:)
def initialize(storage_account_name:, storage_access_key:, container:)
@client = Azure::Storage::Client.create(storage_account_name: storage_account_name, storage_access_key: storage_access_key)
@signer = Azure::Storage::Core::Auth::SharedAccessSignature.new(storage_account_name, storage_access_key)
@blobs = client.blob_client
@container = container
@path = path
end

def upload(key, io, checksum: nil)
Expand Down Expand Up @@ -87,6 +86,7 @@ def url(key, expires_in:, filename:, disposition:, content_type:)
base_url = url_for(key)
generated_url = signer.signed_uri(
URI(base_url), false,
service: "b",
permissions: "r",
expiry: format_expiry(expires_in),
content_disposition: content_disposition_with(type: disposition, filename: filename),
Expand All @@ -102,8 +102,12 @@ def url(key, expires_in:, filename:, disposition:, content_type:)
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
instrument :url, key: key do |payload|
base_url = url_for(key)
generated_url = signer.signed_uri(URI(base_url), false, permissions: "rw",
expiry: format_expiry(expires_in)).to_s
generated_url = signer.signed_uri(
URI(base_url), false,
service: "b",
permissions: "rw",
expiry: format_expiry(expires_in)
).to_s

payload[:url] = generated_url

Expand All @@ -117,7 +121,7 @@ def headers_for_direct_upload(key, content_type:, checksum:, **)

private
def url_for(key)
"#{path}/#{container}/#{key}"
"#{blobs.host}/#{container}/#{key}"
end

def blob_for(key)
Expand Down
1 change: 0 additions & 1 deletion activestorage/test/service/configurations.example.yml
Expand Up @@ -24,7 +24,6 @@
#
# azure:
# service: AzureStorage
# path: ""
# storage_account_name: ""
# storage_access_key: ""
# container: ""
1 change: 0 additions & 1 deletion guides/source/active_storage_overview.md
Expand Up @@ -121,7 +121,6 @@ Declare an Azure Storage service in `config/storage.yml`:
```yaml
azure:
service: AzureStorage
path: ""
storage_account_name: ""
storage_access_key: ""
container: ""
Expand Down

0 comments on commit 50182d3

Please sign in to comment.