diff --git a/.env.example b/.env.example index ba06ef8..2149a50 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ SOURCE_FOLDER="" # (Required) Name of the remote bucket or container TARGET_BUCKET="" -# (Required) Cloud provider (gcs, s3, azure) +# (Required) Cloud provider (gcloud, aws, azure) SERVICE_NAME="" # (Required) Cloud provider access string or path to key file SERVICE_KEY="" diff --git a/src/cloud/aws.py b/src/cloud/aws.py new file mode 100644 index 0000000..66da6c9 --- /dev/null +++ b/src/cloud/aws.py @@ -0,0 +1,40 @@ +import os +import boto3 +from botocore.exceptions import ClientError + +from ..fs.utils import get_file + +class StorageClient: + def __init__(self): + self.set_access_key() + self.client = boto3.client("s3") + + self._error = None + + @property + def error(self): + return self._error + + @error.setter + def error(self, state): + self._error = state + + # Get IAM user access key and ID + def set_access_key(self): + key = os.getenv("SERVICE_KEY").split(";") + if len(key) != 2: + self.error = "Invalid AWS service key" + return False + + os.environ["aws_access_key_id"] = key[0] + os.environ["aws_secret_access_key"] = key[1] + + def upload(self, path: str) -> bool: + name = get_file(path) + + try: + resp = self.client.upload_file(path, os.getenv("TARGET_BUCKET"), name) + except ClientError as e: + self.error = e + return False + return True \ No newline at end of file diff --git a/src/cloud/gcs.py b/src/cloud/gcloud.py similarity index 100% rename from src/cloud/gcs.py rename to src/cloud/gcloud.py