From 6e1a134bab3b5ce95d3c31a0a52a78972a369280 Mon Sep 17 00:00:00 2001 From: Sebastian Stolz <4427510+sstolz84@users.noreply.github.com> Date: Mon, 30 Oct 2017 14:26:42 +0100 Subject: [PATCH 1/3] Update commandline.py Add option --azure-region to choose Azure Region (Global, Germany, China) --- duplicity/commandline.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/duplicity/commandline.py b/duplicity/commandline.py index 5d12b1db..a4c90393 100644 --- a/duplicity/commandline.py +++ b/duplicity/commandline.py @@ -580,6 +580,9 @@ def add_rename(o, s, v, p): # The number for the maximum parallel connections to use when the blob size exceeds 64MB. # max_connections (int) - Maximum number of parallel connections to use when the blob size exceeds 64MB. parser.add_option("--azure-max-connections", type="int", metavar=_("number")) + + # The used Azure region, for Azure Germany and Azure China they used different storage endpoints + parser.add_option("--azure-region", metavar=_("global|germany|china")) # scp command to use (ssh pexpect backend) parser.add_option("--scp-command", metavar=_("command")) From 24a2cdb1511111f2322081fdf829199f7fe52ed9 Mon Sep 17 00:00:00 2001 From: Sebastian Stolz <4427510+sstolz84@users.noreply.github.com> Date: Mon, 30 Oct 2017 14:28:28 +0100 Subject: [PATCH 2/3] Update globals.py Add global variable azure_region --- duplicity/globals.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/duplicity/globals.py b/duplicity/globals.py index 3cd90100..2e6498b8 100644 --- a/duplicity/globals.py +++ b/duplicity/globals.py @@ -228,6 +228,9 @@ # Maximum number of parallel connections to use when the blob size for azure exceeds 64MB azure_max_connections = None +# The Azure Region +azure_region = "global" + # Whether to use the full email address as the user name when # logging into an imap server. If false just the user name # part of the email address is used. From df44e77b0576dc390f897706124ce64cae01717d Mon Sep 17 00:00:00 2001 From: Sebastian Stolz <4427510+sstolz84@users.noreply.github.com> Date: Mon, 30 Oct 2017 14:31:39 +0100 Subject: [PATCH 3/3] Update azurebackend.py Add endpoint_suffix based on selected Azure Region (different endpoints for germany and china) --- duplicity/backends/azurebackend.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/duplicity/backends/azurebackend.py b/duplicity/backends/azurebackend.py index 7e88c8f0..8e7cc505 100644 --- a/duplicity/backends/azurebackend.py +++ b/duplicity/backends/azurebackend.py @@ -59,17 +59,26 @@ def __init__(self, parsed_url): # TODO: validate container name self.container = parsed_url.path.lstrip('/') + + if globals.azure_region == 'global': + suffix = "core.windows.net" + elif globals.azure_region == 'germany': + suffix = "core.cloudapi.de" + elif globals.azure_region == 'china': + suffix = "core.chinacloudapi.cn" if 'AZURE_ACCOUNT_NAME' not in os.environ: raise BackendException('AZURE_ACCOUNT_NAME environment variable not set.') if 'AZURE_ACCOUNT_KEY' in os.environ: self.blob_service = BlobService(account_name=os.environ['AZURE_ACCOUNT_NAME'], - account_key=os.environ['AZURE_ACCOUNT_KEY']) + account_key=os.environ['AZURE_ACCOUNT_KEY'], + endpoint_suffix=suffix) self._create_container() elif 'AZURE_SHARED_ACCESS_SIGNATURE' in os.environ: self.blob_service = BlobService(account_name=os.environ['AZURE_ACCOUNT_NAME'], - sas_token=os.environ['AZURE_SHARED_ACCESS_SIGNATURE']) + sas_token=os.environ['AZURE_SHARED_ACCESS_SIGNATURE'], + endpoint_suffix=suffix) else: raise BackendException( 'Neither AZURE_ACCOUNT_KEY nor AZURE_SHARED_ACCESS_SIGNATURE environment variable not set.')