added s3 client factory
This commit is contained in:
parent
b1d844a638
commit
09cdac5129
@ -12,3 +12,6 @@ class ProcessingFailure(Exception):
|
||||
|
||||
class UnknownStorageBackend(ValueError):
|
||||
pass
|
||||
|
||||
class InvalidEndpoint(ValueError):
|
||||
pass
|
||||
|
||||
@ -59,7 +59,6 @@ class AzureStorageAdapter(StorageAdapter):
|
||||
data = blob_data.readall()
|
||||
yield data
|
||||
|
||||
@_retry(ResourceExistsError)
|
||||
def purge(self, bucket_name):
|
||||
logger.debug(f"Purging Azure container '{bucket_name}'...")
|
||||
container_client = self.__client.get_container_client(bucket_name)
|
||||
|
||||
0
pyinfra/storage/adapters/s3.py
Normal file
0
pyinfra/storage/adapters/s3.py
Normal file
22
pyinfra/storage/clients/s3.py
Normal file
22
pyinfra/storage/clients/s3.py
Normal file
@ -0,0 +1,22 @@
|
||||
import re
|
||||
|
||||
from minio import Minio
|
||||
|
||||
from pyinfra.config import CONFIG
|
||||
from pyinfra.exceptions import InvalidEndpoint
|
||||
|
||||
|
||||
def parse_endpoint(endpoint):
|
||||
endpoint_pattern = r"(?P<protocol>https?)://(?P<address>.*:(?:\d{1,3}\.){3}\d{1,3})"
|
||||
|
||||
match = re.match(endpoint_pattern, endpoint)
|
||||
|
||||
if not match:
|
||||
raise InvalidEndpoint(f"Endpoint {endpoint} is invalid; expected {endpoint_pattern}")
|
||||
|
||||
return {"secure": match.group("protocol") == "https", "endpoint": match.group("address")}
|
||||
|
||||
|
||||
def get_s3_client(endpoint=None) -> Minio:
|
||||
endpoint = CONFIG.s3.endpoint if endpoint is None else endpoint
|
||||
return Minio(**parse_endpoint(endpoint), access_key=CONFIG.s3.secret_key, secret_key=CONFIG.s3.access_key)
|
||||
Loading…
x
Reference in New Issue
Block a user