From f27a73d4d3870dd0aebe781edafdd189c8e0c12b Mon Sep 17 00:00:00 2001 From: Yaroslava Lukoyanova Date: Mon, 3 Feb 2025 12:44:21 +0300 Subject: [PATCH] [#354] Support of presigned url methods for S3 Signed-off-by: Yaroslava Lukoyanova --- src/frostfs_testlib/clients/s3/aws_cli_client.py | 9 +++++++++ src/frostfs_testlib/clients/s3/boto3_client.py | 13 ++++++++++++- src/frostfs_testlib/clients/s3/interfaces.py | 4 ++++ src/frostfs_testlib/steps/http_gate.py | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/frostfs_testlib/clients/s3/aws_cli_client.py b/src/frostfs_testlib/clients/s3/aws_cli_client.py index accc289..3a98141 100644 --- a/src/frostfs_testlib/clients/s3/aws_cli_client.py +++ b/src/frostfs_testlib/clients/s3/aws_cli_client.py @@ -957,6 +957,15 @@ class AwsCliClient(S3ClientWrapper): return json_output + @reporter.step("Create presign url for the object") + def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600): + # AWS CLI does not support method definition and world only in 'get_object' state by default + cmd = f"aws {self.common_flags} s3 presign s3://{bucket}/{key} " f"--endpoint-url {self.s3gate_endpoint} --profile {self.profile}" + if expires_in: + cmd += f" --expires-in {expires_in}" + response = self.local_shell.exec(cmd).stdout + return response.strip() + # IAM METHODS # # Some methods don't have checks because AWS is silent in some cases (delete, attach, etc.) diff --git a/src/frostfs_testlib/clients/s3/boto3_client.py b/src/frostfs_testlib/clients/s3/boto3_client.py index 890b4e9..36a7bf4 100644 --- a/src/frostfs_testlib/clients/s3/boto3_client.py +++ b/src/frostfs_testlib/clients/s3/boto3_client.py @@ -50,10 +50,11 @@ class Boto3ClientWrapper(S3ClientWrapper): self.session = boto3.Session() self.config = Config( + signature_version="s3v4", retries={ "max_attempts": MAX_REQUEST_ATTEMPTS, "mode": RETRY_MODE, - } + }, ) self.set_endpoint(s3gate_endpoint) @@ -816,6 +817,16 @@ class Boto3ClientWrapper(S3ClientWrapper): ) -> dict: raise NotImplementedError("Cp is not supported for boto3 client") + @reporter.step("Create presign url for the object") + def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600): + response = self._exec_request( + method=self.boto3_client.generate_presigned_url, + params={"ClientMethod": method, "Params": {"Bucket": bucket, "Key": key}, "ExpiresIn": expires_in}, + endpoint=self.s3gate_endpoint, + profile=self.profile, + ) + return response + # END OBJECT METHODS # # IAM METHODS # diff --git a/src/frostfs_testlib/clients/s3/interfaces.py b/src/frostfs_testlib/clients/s3/interfaces.py index 7ce9f31..3fc1414 100644 --- a/src/frostfs_testlib/clients/s3/interfaces.py +++ b/src/frostfs_testlib/clients/s3/interfaces.py @@ -417,6 +417,10 @@ class S3ClientWrapper(HumanReadableABC): ) -> dict: """cp directory TODO: Add proper description""" + @abstractmethod + def create_presign_url(self, method: str, bucket: str, key: str, expires_in: Optional[int] = 3600): + """Creates presign URL""" + # END OF OBJECT METHODS # # IAM METHODS # diff --git a/src/frostfs_testlib/steps/http_gate.py b/src/frostfs_testlib/steps/http_gate.py index 51b0301..aa4abf2 100644 --- a/src/frostfs_testlib/steps/http_gate.py +++ b/src/frostfs_testlib/steps/http_gate.py @@ -33,6 +33,7 @@ def get_via_http_gate( oid: str, node: ClusterNode, request_path: Optional[str] = None, + presigned_url: Optional[str] = None, timeout: Optional[int] = 300, ): """ @@ -47,6 +48,9 @@ def get_via_http_gate( if request_path: request = f"{node.http_gate.get_endpoint()}{request_path}" + if presigned_url: + request = presigned_url + response = requests.get(request, stream=True, timeout=timeout, verify=False) if not response.ok: