Skip to content

Commit

Permalink
add bad url query
Browse files Browse the repository at this point in the history
  • Loading branch information
devksingh4 committed Jul 20, 2023
1 parent 99c78f4 commit 3c00ed0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion code/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def getResumeUrl(context, queryParams):
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
try:
url: str = get_resume_url(queryParams['uid'])
url: str | None = get_resume_url(queryParams['uid'])
if not url:
return badRequest("This UID has no resume.")
rval = {
"statusCode": 200,
"body": json.dumps({
Expand Down
14 changes: 12 additions & 2 deletions code/recruiter/get.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import boto3, os
s3 = boto3.client('s3', region_name=os.environ.get("AWS_REGION", "us-east-1"))
def get_resume_url(uid: str) -> str:
def check_key_exists(bucket, key):
try:
s3.head_object(Bucket='bucket_name', Key='file_path')
return True
except:
return False

def get_resume_url(uid: str) -> str | None:
bucket = 'infra-resume-book-pdfs'
filename = f'resume_{uid}.pdf'
if not check_key_exists(bucket, filename):
return None
return s3.generate_presigned_url(
ClientMethod="get_object",
Params={
"Bucket": 'infra-resume-book-pdfs',
"Bucket": bucket,
"Key": filename
},
ExpiresIn=3600
Expand Down

0 comments on commit 3c00ed0

Please sign in to comment.