Skip to content

Commit 021c265

Browse files
committed
Support for other cloud regions
1 parent 64ec473 commit 021c265

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add get_container_properties
44
- Add create_container
55
- Add delete_container
6+
- Support for Azure China, US Gov and Germany
67

78
## [0.5.1] 2024-09-09
89

lib/azure_blob/client.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ class Client
1717
def initialize(account_name:, access_key:, container:, **options)
1818
@account_name = account_name
1919
@container = container
20+
@cloud_regions = options[:cloud_regions]&.to_sym || :global
2021

2122
@signer = !access_key.nil? && !access_key.empty? ?
2223
AzureBlob::SharedKeySigner.new(account_name:, access_key:) :
23-
AzureBlob::EntraIdSigner.new(account_name:, **options.slice(:principal_id))
24+
AzureBlob::EntraIdSigner.new(account_name:, host:, **options.slice(:principal_id))
2425
end
2526

2627
# 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.
@@ -331,10 +332,10 @@ def put_blob_single(key, content, options = {})
331332
Http.new(uri, headers, metadata: options[:metadata], signer:).put(content.read)
332333
end
333334

334-
attr_reader :account_name, :signer, :container, :http
335-
336335
def host
337-
"https://#{account_name}.blob.core.windows.net"
336+
@host ||= "https://#{account_name}.blob.#{CLOUD_REGIONS_SUFFIX[cloud_regions]}"
338337
end
338+
339+
attr_reader :account_name, :signer, :container, :http, :cloud_regions
339340
end
340341
end

lib/azure_blob/const.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ module AzureBlob
55
MAX_UPLOAD_SIZE = 256 * 1024 * 1024 # 256 Megabytes
66
DEFAULT_BLOCK_SIZE = 128 * 1024 * 1024 # 128 Megabytes
77
BLOB_SERVICE = "b"
8+
CLOUD_REGIONS_SUFFIX = {
9+
global: "core.windows.net",
10+
cn: "core.chinacloudapi.cn",
11+
de: "core.cloudapi.de",
12+
usgovt: "core.usgovcloudapi.net",
13+
}
814
end

lib/azure_blob/entra_id_signer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class EntraIdSigner # :nodoc:
1313
attr_reader :token
1414
attr_reader :account_name
1515

16-
def initialize(account_name:, principal_id: nil)
16+
def initialize(account_name:, host:, principal_id: nil)
1717
@token = AzureBlob::IdentityToken.new(principal_id:)
1818
@account_name = account_name
19+
@host = host
1920
end
2021

2122
def authorization_header(uri:, verb:, headers: {})

lib/azure_blob/user_delegation_key.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class UserDelegationKey # :nodoc:
66
EXPIRATION_BUFFER = 3600 # 1 hours
77
def initialize(account_name:, signer:)
88
@uri = URI.parse(
9-
"https://#{account_name}.blob.core.windows.net/?restype=service&comp=userdelegationkey"
9+
"#{signer.host}/?restype=service&comp=userdelegationkey"
1010
)
1111

1212
@signer = signer

0 commit comments

Comments
 (0)