-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major Refactor introducing Dependency Injection
- Loading branch information
1 parent
80a1119
commit ea9c432
Showing
23 changed files
with
1,707 additions
and
3,975 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
|
||
import boto3 | ||
from injector import inject | ||
|
||
|
||
class AWSStorage: | ||
|
||
@inject | ||
def __init__(self): | ||
# S3 | ||
self.s3_client = boto3.client( | ||
's3', | ||
aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'), | ||
aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'), | ||
) | ||
|
||
def upload_file(self, file_path: str, bucket_name: str, object_name: str): | ||
self.s3_client.upload_file(file_path, bucket_name, object_name) | ||
|
||
def download_file(self, object_name: str, bucket_name: str, file_path: str): | ||
self.s3_client.download_file(bucket_name, object_name, file_path) | ||
|
||
def delete_file(self, bucket_name: str, s3_path: str): | ||
self.s3_client.delete_object(Bucket=bucket_name, Key=s3_path) | ||
|
||
def generatePresignedUrl(self, object: str, bucket_name: str, s3_path: str, expiration: int = 3600): | ||
# generate presigned URL | ||
return self.s3_client.generate_presigned_url('get_object', | ||
Params={ | ||
'Bucket': bucket_name, | ||
'Key': s3_path | ||
}, | ||
ExpiresIn=expiration) |
Oops, something went wrong.