mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-03 02:57:25 +02:00
Change logging and add secrets
This commit is contained in:
parent
b4caa85dd1
commit
59950a1fde
6 changed files with 86 additions and 37 deletions
|
@ -12,7 +12,7 @@ from login_required import login_not_required
|
|||
|
||||
from cachetools.func import ttl_cache
|
||||
|
||||
from registrar.utility.s3_bucket import S3ClientHelper
|
||||
from registrar.utility.s3_bucket import S3ClientError, S3ClientHelper
|
||||
|
||||
|
||||
DOMAIN_FILE_URL = "https://raw.githubusercontent.com/cisagov/dotgov-data/main/current-full.csv"
|
||||
|
@ -103,31 +103,32 @@ def available(request, domain=""):
|
|||
|
||||
@require_http_methods(["GET"])
|
||||
@login_not_required
|
||||
def get_current_full(request, file_path="migrationdata/current-full.csv"):
|
||||
def get_current_full(request, file_name="current-full.csv"):
|
||||
"""This will return the file content of current-full.csv which is the command
|
||||
output of generate_current_full_report.py. This command iterates through each Domain
|
||||
and returns a CSV representation."""
|
||||
return serve_file(file_path, "current-full.csv")
|
||||
return serve_file(file_name)
|
||||
|
||||
|
||||
@require_http_methods(["GET"])
|
||||
@login_not_required
|
||||
def get_current_federal(request, file_path="migrationdata/current-federal.csv"):
|
||||
def get_current_federal(request, file_name="current-federal.csv"):
|
||||
"""This will return the file content of current-federal.csv which is the command
|
||||
output of generate_current_federal_report.py. This command iterates through each Domain
|
||||
and returns a CSV representation."""
|
||||
return serve_file(file_path, "current-federal.csv")
|
||||
return serve_file(file_name)
|
||||
|
||||
|
||||
def serve_file(file_path, file_name):
|
||||
"""Downloads a file based on a given filepath. Returns a 404 if not found."""
|
||||
def serve_file(file_name):
|
||||
"""Downloads a file based on a given filepath. Returns a 500 if not found."""
|
||||
s3_client = S3ClientHelper()
|
||||
# TODO - #1403, grab from the S3 instance instead
|
||||
# TODO - check if file exists in s3, not here
|
||||
if os.path.exists(file_path):
|
||||
# Serve the CSV file
|
||||
file = s3_client.get_file(file_name)
|
||||
response = FileResponse(file)
|
||||
return response
|
||||
else:
|
||||
return HttpResponse("File not found", status=404)
|
||||
# Serve the CSV file. If not found, an exception will be thrown.
|
||||
# This will then be caught by flat, causing it to not read it - which is what we want.
|
||||
try:
|
||||
file = s3_client.get_file(file_name, decode_to_utf=True)
|
||||
except S3ClientError as err:
|
||||
# TODO - #1317: Notify operations when auto report generation fails
|
||||
raise err
|
||||
|
||||
response = HttpResponse(file)
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue