mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
initial
This commit is contained in:
@@ -22,6 +22,17 @@ def get_s3_object(bucket_name, file_location, access_key, secret_key, region):
|
||||
return s3.Object(bucket_name, file_location)
|
||||
|
||||
|
||||
def purge_bucket(bucket_name, access_key, secret_key, region):
|
||||
session = Session(
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
region_name=region,
|
||||
)
|
||||
s3 = session.resource("s3", config=AWS_CLIENT_CONFIG)
|
||||
bucket = s3.Bucket(bucket_name)
|
||||
bucket.objects.all().delete()
|
||||
|
||||
|
||||
def file_exists(bucket_name, file_location, access_key, secret_key, region):
|
||||
try:
|
||||
# try and access metadata of object
|
||||
|
||||
@@ -841,3 +841,14 @@ def promote_user_to_platform_admin(user_email_address):
|
||||
user.platform_admin = True
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@notify_command(name="purge-csv-bucket")
|
||||
def purge_csv_bucket():
|
||||
bucket_name = getenv("CSV_BUCKEY_NAME")
|
||||
access_key = getenv("CSV_AWS_ACCESS_KEY_ID")
|
||||
secret = getenv("CSV_AWS_SECRET_ACCESS_KEY")
|
||||
region = getenv("CSV_AWS_REGION")
|
||||
print("ABOUT TO RUN PURGE CSV BUCKET")
|
||||
s3.purge_bucket(bucket_name, access_key, secret, region)
|
||||
print("RAN PURGE CSV BUCKET")
|
||||
|
||||
Reference in New Issue
Block a user