-
Notifications
You must be signed in to change notification settings - Fork 926
Add support for Azure Government to Azure Blobs storage driver #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d0b5d1e
505894f
739a6a3
c581553
b16eb28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from libcloud.storage.types import Provider | ||
| from libcloud.storage.providers import get_driver | ||
|
|
||
| cls = get_driver(Provider.AZURE_BLOBS) | ||
|
|
||
| driver = cls(key='your storage account name', | ||
| secret='your access key', | ||
| host='blob.core.usgovcloudapi.net') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,9 @@ | |
| ) | ||
|
|
||
| AZURE_STORAGE_HOST_SUFFIX = 'blob.core.windows.net' | ||
| AZURE_STORAGE_HOST_SUFFIX_CHINA = 'blob.core.chinacloudapi.cn' | ||
| AZURE_STORAGE_HOST_SUFFIX_GOVERNMENT = 'blob.core.usgovcloudapi.net' | ||
| AZURE_STORAGE_HOST_SUFFIX_PRIVATELINK = 'privatelink.blob.core.windows.net' | ||
|
|
||
| AZURE_STORAGE_CDN_URL_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ' | ||
|
|
||
|
|
@@ -173,11 +176,12 @@ class AzureBlobsConnection(AzureConnection): | |
| these deployments, the parameter ``account_prefix`` must be set on the | ||
| connection. This is done by instantiating the driver with arguments such | ||
| as ``host='somewhere.tld'`` and ``key='theaccount'``. To specify a custom | ||
| host without an account prefix, e.g. for use-cases where the custom host | ||
| implements an auditing proxy or similar, the driver can be instantiated | ||
| with ``host='theaccount.somewhere.tld'`` and ``key=''``. | ||
| host without an account prefix, e.g. to connect to Azure Government or | ||
| Azure China, the driver can be instantiated with the appropriate storage | ||
| endpoint suffix, e.g. ``host='blob.core.usgovcloudapi.net'`` and | ||
| ``key='theaccount'``. | ||
|
|
||
| :param account_prefix: Optional prefix identifying the sotrage account. | ||
| :param account_prefix: Optional prefix identifying the storage account. | ||
| Used when connecting to a custom deployment of the | ||
| storage service like Azurite or IoT Edge Storage. | ||
| :type account_prefix: ``str`` | ||
|
|
@@ -206,7 +210,7 @@ class AzureBlobsStorageDriver(StorageDriver): | |
|
|
||
| def __init__(self, key, secret=None, secure=True, host=None, port=None, | ||
| **kwargs): | ||
| self._host_argument_set = bool(host) | ||
| self._host = host | ||
|
|
||
| # B64decode() this key and keep it, so that we don't have to do | ||
| # so for every request. Minor performance improvement | ||
|
|
@@ -217,15 +221,34 @@ def __init__(self, key, secret=None, secure=True, host=None, port=None, | |
| port=port, **kwargs) | ||
|
|
||
| def _ex_connection_class_kwargs(self): | ||
| result = {} | ||
|
|
||
| # host argument has precedence | ||
| if not self._host_argument_set: | ||
| result['host'] = '%s.%s' % (self.key, AZURE_STORAGE_HOST_SUFFIX) | ||
| # if the user didn't provide a custom host value, assume we're | ||
| # targeting the default Azure Storage endpoints | ||
| if self._host is None: | ||
| return {'host': '%s.%s' % (self.key, AZURE_STORAGE_HOST_SUFFIX)} | ||
|
|
||
| # connecting to a special storage region like Azure Government or | ||
| # Azure China requires setting a custom storage endpoint but we | ||
| # still use the same scheme to identify a specific account as for | ||
| # the standard storage endpoint | ||
| try: | ||
| host_suffix = next( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a situation where we may want to allow end user to specify full host as-is - aka so we don't add any prefix to it, but user already includes that in the I think this would give users more flexibility in some situations.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify - if a new endpoint ever gets added or similar, this would require use to update the code to support it. If we allowed user to specify a full arbitrary host, they may be able to use that instead (until a new version is released / similar). For us to be able to support that, we would likely need to add new argument to the constructor - e.g.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only current Azure Storage version that I'm aware of which wouldn't be covered by the approach proposed in this PR is Azure Stack Hub Storage. However the API version that libcloud uses ( I get the appeal of an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I didn't really mean it as an alternative, but in addition to your proposed changes (so the interface for the common case would still be the same, but in case there is a need to use a fully custom host, there is an easy way to do it). I also don't think that's a blocker for this PR so if you think it's a good idea, feel free to open a new PR with that change in the future.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case I'd say to defer the addition of |
||
| host_suffix | ||
| for host_suffix in ( | ||
| AZURE_STORAGE_HOST_SUFFIX_CHINA, | ||
| AZURE_STORAGE_HOST_SUFFIX_GOVERNMENT, | ||
| AZURE_STORAGE_HOST_SUFFIX_PRIVATELINK, | ||
| ) | ||
| if self._host.endswith(host_suffix) | ||
| ) | ||
| except StopIteration: | ||
| pass | ||
| else: | ||
| result['account_prefix'] = self.key | ||
| return {'host': '%s.%s' % (self.key, host_suffix)} | ||
|
|
||
| return result | ||
| # if the host isn't targeting one of the special storage regions, it | ||
| # must be pointing to Azurite or IoT Edge Storage so switch to prefix | ||
| # identification | ||
| return {'account_prefix': self.key} | ||
|
|
||
| def _xml_to_container(self, node): | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some unit tests for this method would be good.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests for the Azurite path in c581553 and for the new GovCloud path in 739a6a3.