-
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.
LGA-2574 use new irsa service account (#971)
* Use new irsa service account * Upgrade celery
- Loading branch information
Showing
22 changed files
with
160 additions
and
190 deletions.
There are no files selected for viewing
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -1,5 +1,46 @@ | ||
from tempfile import NamedTemporaryFile | ||
from storages.backends.s3boto3 import S3Boto3Storage | ||
from botocore.exceptions import ClientError | ||
|
||
|
||
class ClientError(ClientError): | ||
pass | ||
|
||
|
||
class StaticS3Storage(S3Boto3Storage): | ||
default_acl = "public-read" | ||
|
||
|
||
class ReportsS3: | ||
@classmethod | ||
def clean_name(cls, name): | ||
return name.strip("/") | ||
|
||
@classmethod | ||
def get_s3_connection(cls, bucket_name): | ||
return S3Boto3Storage(bucket=bucket_name) | ||
|
||
@classmethod | ||
def download_file(cls, bucket_name, key): | ||
try: | ||
obj = cls.get_s3_connection(bucket_name).bucket.Object(cls.clean_name(key)) | ||
data = NamedTemporaryFile() | ||
obj.download_fileobj(data) | ||
# This required otherwise any file reads will start at the end which | ||
# leads to an empty file being downloaded (zero bytes) | ||
data.seek(0) | ||
return {"headers": {"Content-Type": obj.content_type}, "body": data} | ||
except ClientError: | ||
return None | ||
|
||
@classmethod | ||
def save_file(cls, bucket_name, key, path): | ||
cls.get_s3_connection(bucket_name).bucket.Object(cls.clean_name(key)).upload_file(path) | ||
|
||
@classmethod | ||
def delete_file(cls, bucket_name, key): | ||
cls.get_s3_connection(bucket_name).delete(cls.clean_name(key)) | ||
|
||
@classmethod | ||
def save_data_to_bucket(cls, bucket_name, key, content): | ||
cls.get_s3_connection(bucket_name).bucket.Object(key).put(Body=content) |
Oops, something went wrong.