Skip to content

Commit

Permalink
Major Refactor introducing Dependency Injection
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-uiuc committed Mar 7, 2024
1 parent 80a1119 commit ea9c432
Show file tree
Hide file tree
Showing 23 changed files with 1,707 additions and 3,975 deletions.
64 changes: 0 additions & 64 deletions ai_ta_backend/aws.py

This file was deleted.

264 changes: 0 additions & 264 deletions ai_ta_backend/canvas.py

This file was deleted.

Empty file.
34 changes: 34 additions & 0 deletions ai_ta_backend/database/aws.py
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)
Loading

0 comments on commit ea9c432

Please sign in to comment.