New methods S3 client

Signed-off-by: Dmitriy Zayakin <d.zayakin@yadro.com>
This commit is contained in:
Dmitriy Zayakin 2023-06-19 13:39:35 +03:00
parent 98f5075715
commit c0f63e3783
3 changed files with 26 additions and 6 deletions

View file

@ -39,6 +39,10 @@ class AwsCliClient(S3ClientWrapper):
except Exception as err: except Exception as err:
raise RuntimeError("Error while configuring AwsCliClient") from err raise RuntimeError("Error while configuring AwsCliClient") from err
@reporter.step_deco("Set endpoint S3 to {s3gate_endpoint}")
def set_endpoint(self, s3gate_endpoint: str):
self.s3gate_endpoint = s3gate_endpoint
@reporter.step_deco("Create bucket S3") @reporter.step_deco("Create bucket S3")
def create_bucket( def create_bucket(
self, self,

View file

@ -47,19 +47,31 @@ class Boto3ClientWrapper(S3ClientWrapper):
@reporter.step_deco("Configure S3 client (boto3)") @reporter.step_deco("Configure S3 client (boto3)")
@report_error @report_error
def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None: def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None:
session = boto3.Session() self.boto3_client: S3Client = None
config = Config( self.session = boto3.Session()
self.config = Config(
retries={ retries={
"max_attempts": MAX_REQUEST_ATTEMPTS, "max_attempts": MAX_REQUEST_ATTEMPTS,
"mode": RETRY_MODE, "mode": RETRY_MODE,
} }
) )
self.access_key_id: str = access_key_id
self.secret_access_key: str = secret_access_key
self.s3gate_endpoint: str = ""
self.set_endpoint(s3gate_endpoint)
self.boto3_client: S3Client = session.client( @reporter.step_deco("Set endpoint S3 to {s3gate_endpoint}")
def set_endpoint(self, s3gate_endpoint: str):
if self.s3gate_endpoint == s3gate_endpoint:
return
self.s3gate_endpoint = s3gate_endpoint
self.boto3_client: S3Client = self.session.client(
service_name="s3", service_name="s3",
aws_access_key_id=access_key_id, aws_access_key_id=self.access_key_id,
aws_secret_access_key=secret_access_key, aws_secret_access_key=self.secret_access_key,
config=config, config=self.config,
endpoint_url=s3gate_endpoint, endpoint_url=s3gate_endpoint,
verify=False, verify=False,
) )

View file

@ -34,6 +34,10 @@ class S3ClientWrapper(ABC):
def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None: def __init__(self, access_key_id: str, secret_access_key: str, s3gate_endpoint: str) -> None:
pass pass
@abstractmethod
def set_endpoint(self, s3gate_endpoint: str):
"""Set endpoint"""
@abstractmethod @abstractmethod
def create_bucket( def create_bucket(
self, self,