mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
merge from main
This commit is contained in:
@@ -95,6 +95,32 @@ def get_s3_file(bucket_name, file_location, access_key, secret_key, region):
|
||||
return s3_file.get()["Body"].read().decode("utf-8")
|
||||
|
||||
|
||||
def download_from_s3(
|
||||
bucket_name, s3_key, local_filename, access_key, secret_key, region
|
||||
):
|
||||
session = Session(
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
region_name=region,
|
||||
)
|
||||
s3 = session.client("s3", config=AWS_CLIENT_CONFIG)
|
||||
result = None
|
||||
try:
|
||||
result = s3.download_file(bucket_name, s3_key, local_filename)
|
||||
print(f"File downloaded successfully to {local_filename}")
|
||||
except botocore.exceptions.NoCredentialsError as nce:
|
||||
print("Credentials not found")
|
||||
raise Exception(nce)
|
||||
except botocore.exceptions.PartialCredentialsError as pce:
|
||||
print("Incomplete credentials provided")
|
||||
raise Exception(pce)
|
||||
except Exception as e:
|
||||
print(f"An error occurred {e}")
|
||||
text = f"EXCEPTION {e} local_filename {local_filename}"
|
||||
raise Exception(text)
|
||||
return result
|
||||
|
||||
|
||||
def get_s3_object(bucket_name, file_location, access_key, secret_key, region):
|
||||
session = Session(
|
||||
aws_access_key_id=access_key,
|
||||
|
||||
@@ -592,14 +592,18 @@ def process_row_from_job(job_id, job_row_number):
|
||||
|
||||
|
||||
@notify_command(name="download-csv-file-by-name")
|
||||
@click.option("-f", "--csv_filename", required=True, help="csv file name")
|
||||
@click.option("-f", "--csv_filename", required=True, help="S3 file location")
|
||||
def download_csv_file_by_name(csv_filename):
|
||||
|
||||
# poetry run flask command download-csv-file-by-name -f <s3 file location>
|
||||
# cf run-task notify-api-production --command "flask command download-csv-file-by-name -f <s3 location>"
|
||||
bucket_name = current_app.config["CSV_UPLOAD_BUCKET"]["bucket"]
|
||||
access_key = current_app.config["CSV_UPLOAD_BUCKET"]["access_key_id"]
|
||||
secret = current_app.config["CSV_UPLOAD_BUCKET"]["secret_access_key"]
|
||||
region = current_app.config["CSV_UPLOAD_BUCKET"]["region"]
|
||||
print(s3.get_s3_file(bucket_name, csv_filename, access_key, secret, region))
|
||||
|
||||
s3.download_from_s3(
|
||||
bucket_name, csv_filename, "download.csv", access_key, secret, region
|
||||
)
|
||||
|
||||
|
||||
@notify_command(name="dump-sms-senders")
|
||||
@@ -607,7 +611,7 @@ def download_csv_file_by_name(csv_filename):
|
||||
def dump_sms_senders(service_name):
|
||||
|
||||
# poetry run flask command dump-sms-senders MyServiceName
|
||||
# cf run-task notify-api-production --command "flask command dump-sms-senders MyServiceName"
|
||||
# cf run-task notify-api-production --command "flask command dump-sms-senders <MyServiceName>"
|
||||
services = get_services_by_partial_name(service_name)
|
||||
if len(services) > 1:
|
||||
raise ValueError(
|
||||
|
||||
Reference in New Issue
Block a user