diff --git a/functions/pipeline/download/__init__.py b/functions/pipeline/download/__init__.py index 11a4e295..96f3965a 100644 --- a/functions/pipeline/download/__init__.py +++ b/functions/pipeline/download/__init__.py @@ -12,17 +12,17 @@ def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') image_count = int(req.params.get('imageCount')) - user_id = int(req.params.get('userId')) + user_name = req.params.get('userName') # setup response object headers = { "content-type": "application/json" } - if not user_id: + if not user_name: return func.HttpResponse( status_code=401, headers=headers, - body=json.dumps({"error": "invalid userId given or omitted"}) + body=json.dumps({"error": "invalid userName given or omitted"}) ) elif not image_count: return func.HttpResponse( @@ -34,7 +34,7 @@ def main(req: func.HttpRequest) -> func.HttpResponse: try: # DB configuration data_access = ImageTagDataAccess(get_postgres_provider()) - + user_id = data_access.create_user(user_name) image_urls = list(data_access.get_new_images(image_count, user_id)) # TODO: Populate starting json with tags, if any exist... (precomputed or retagging?) diff --git a/functions/pipeline/onboarding/__init__.py b/functions/pipeline/onboarding/__init__.py index 7e87ba9a..0961e3f2 100644 --- a/functions/pipeline/onboarding/__init__.py +++ b/functions/pipeline/onboarding/__init__.py @@ -1,5 +1,6 @@ import os import logging +import json import azure.functions as func from ..shared.db_provider import get_postgres_provider @@ -13,10 +14,14 @@ def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') - user_id = req.params.get('userId') + user_name = req.params.get('userName') - if not user_id: - return func.HttpResponse("userId query parameter invalid or omitted", status_code=401) + if not user_name: + return func.HttpResponse( + status_code=401, + headers={ "content-type": "application/json"}, + body=json.dumps({"error": "invalid userName given or omitted"}) + ) try: req_body = req.get_json() @@ -49,16 +54,11 @@ def main(req: func.HttpRequest) -> func.HttpResponse: image_object_list.append(image) # TODO: Wrap db access section in try/catch, send an appropriate http response in the event of an error - logging.info("Now connecting to database...") data_access = ImageTagDataAccess(get_postgres_provider()) - logging.info("Connected.") - - # Create user id - user_id_number = data_access.create_user(user_id) - logging.info("User id for {0} is {1}".format(user_id, str(user_id_number))) + user_id = data_access.create_user(user_name) # Add new images to the database, and retrieve a dictionary ImageId's mapped to ImageUrl's - image_id_url_map = data_access.add_new_images(image_object_list,user_id_number) + image_id_url_map = data_access.add_new_images(image_object_list,user_id) # Print out dictionary for debugging logging.info("Image ID and URL map dictionary:") @@ -119,7 +119,7 @@ def main(req: func.HttpRequest) -> func.HttpResponse: update_urls_dictionary[image_id] = permanent_storage_path logging.info("Now updating permanent URLs in the DB...") - data_access.update_image_urls(update_urls_dictionary, user_id_number) + data_access.update_image_urls(update_urls_dictionary, user_id) logging.info("Done.") # Construct response string of permanent URLs diff --git a/functions/pipeline/requirements.txt b/functions/pipeline/requirements.txt index fbf84768..41de3ac2 100644 --- a/functions/pipeline/requirements.txt +++ b/functions/pipeline/requirements.txt @@ -1,6 +1,6 @@ azure-functions==1.0.0a5 azure-functions-worker==1.0.0a6 -azure-storage +azure-storage-blob==1.4.0 grpcio==1.14.2 grpcio-tools==1.14.2 protobuf==3.6.1 diff --git a/functions/pipeline/upload/__init__.py b/functions/pipeline/upload/__init__.py index 417dc1e4..9fd4a701 100644 --- a/functions/pipeline/upload/__init__.py +++ b/functions/pipeline/upload/__init__.py @@ -19,11 +19,18 @@ def main(req: func.HttpRequest) -> func.HttpResponse: # TODO: Create if check for userId and valid json checks? vott_json = req.get_json() upload_data = process_vott_json(vott_json) - user_id = int(req.params.get('userId')) - upload_data['userId'] = user_id + user_name = req.params.get('userName') + + if not user_name: + return func.HttpResponse( + status_code=401, + headers={ "content-type": "application/json"}, + body=json.dumps({"error": "invalid userName given or omitted"}) + ) # DB configuration data_access = ImageTagDataAccess(get_postgres_provider()) + user_id = data_access.create_user(user_name) # Update tagged images ids_to_tags = upload_data["imageIdToTags"] @@ -45,9 +52,7 @@ def main(req: func.HttpRequest) -> func.HttpResponse: return func.HttpResponse( body=json.dumps(upload_data), status_code=200, - headers={ - "content-type": "application/json" - } + headers={ "content-type": "application/json"}, ) except Exception as e: return func.HttpResponse( diff --git a/requirements.txt b/requirements.txt index 9de0ccd9..b6871c9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ azure-functions==1.0.0a5 azure-functions-worker==1.0.0a6 -azure-storage +azure-storage-blob==1.4.0 grpcio==1.14.2 grpcio-tools==1.14.2 protobuf==3.6.1