[#354] Support of presigned url methods for S3

Signed-off-by: Yaroslava Lukoyanova <y.lukoyanova@yadro.com>
This commit is contained in:
Yaroslava Lukoyanova 2025-02-03 12:44:21 +03:00 committed by ylukoyan
parent c4ab14fce8
commit d38808a1f5
4 changed files with 34 additions and 1 deletions

View file

@ -959,6 +959,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) -> str:
# 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.)

View file

@ -48,7 +48,13 @@ class Boto3ClientWrapper(S3ClientWrapper):
self.region = region
self.session = boto3.Session()
self.config = Config(retries={"max_attempts": MAX_REQUEST_ATTEMPTS, "mode": RETRY_MODE})
self.config = Config(
signature_version="s3v4",
retries={
"max_attempts": MAX_REQUEST_ATTEMPTS,
"mode": RETRY_MODE,
},
)
self.set_endpoint(s3gate_endpoint)
@ -813,6 +819,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) -> str:
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 #

View file

@ -425,6 +425,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) -> str:
"""Creates presign URL"""
# END OF OBJECT METHODS #
# IAM METHODS #