From ff1828bdd61d141da129bfbc0be65803e935293d Mon Sep 17 00:00:00 2001 From: Bai Date: Fri, 10 Jan 2020 11:42:53 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9Swift=E5=BD=95?= =?UTF-8?q?=E5=83=8F=E5=AD=98=E5=82=A8=E5=88=9B=E5=BB=BA=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=8F=8AAPI=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/const.py | 1 + apps/terminal/forms/storage.py | 6 ++++++ apps/terminal/models.py | 13 +++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/terminal/const.py b/apps/terminal/const.py index b412c1624..4d19d007c 100644 --- a/apps/terminal/const.py +++ b/apps/terminal/const.py @@ -35,6 +35,7 @@ REPLAY_STORAGE_TYPE_SWIFT_FIELDS = [ {'name': 'SECRET_KEY', 'write_only': True}, {'name': 'REGION'}, {'name': 'ENDPOINT'}, + {'name': 'PROTOCOL'}, ] REPLAY_STORAGE_TYPE_OSS_FIELDS = [ {'name': 'BUCKET'}, diff --git a/apps/terminal/forms/storage.py b/apps/terminal/forms/storage.py index 28092380e..a94375e81 100644 --- a/apps/terminal/forms/storage.py +++ b/apps/terminal/forms/storage.py @@ -145,6 +145,12 @@ class ReplayStorageSwiftForm(BaseReplayStorageForm): swift_endpoint = forms.CharField( max_length=128, label=_('Endpoint'), required=False, ) + swift_protocol = forms.ChoiceField( + choices=( + ('HTTP', 'http'), + ('HTTPS', 'https') + ), initial='http', label=_('Protocol'), required=True, + ) class CommandStorageTypeESForm(BaseCommandStorageForm): diff --git a/apps/terminal/models.py b/apps/terminal/models.py index 6ad820563..04bc74c67 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -362,18 +362,23 @@ class ReplayStorage(CommonModelMixin): return self.name def convert_type(self): - s3_type_list = [ - const.REPLAY_STORAGE_TYPE_CEPH, const.REPLAY_STORAGE_TYPE_SWIFT - ] + s3_type_list = [const.REPLAY_STORAGE_TYPE_CEPH] tp = self.type if tp in s3_type_list: tp = const.REPLAY_STORAGE_TYPE_S3 return tp + def get_extra_config(self): + extra_config = {'TYPE': self.convert_type()} + if self.type == const.REPLAY_STORAGE_TYPE_SWIFT: + extra_config.update({'signer': 'S3SignerType'}) + return extra_config + @property def config(self): config = self.meta - config.update({'TYPE': self.convert_type()}) + extra_config = self.get_extra_config() + config.update(extra_config) return config def in_defaults(self):