-
Couldn't load subscription status.
- Fork 10
Upload json tagging data, update upload/download functions to use singular data_access library and configuration. #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9ec2ccd
2f4eed3
8cbb600
5bd7313
92959a8
be7e61f
29746c0
f1f495d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,3 +118,6 @@ tag/*.csv | |
|
|
||
| # TF exported graph files | ||
| .pb | ||
|
|
||
| # VSCode | ||
| .vscode/*.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,15 @@ | ||
| import os | ||
| import logging | ||
| import azure.functions as func | ||
| from ..shared import db_access_v2 as DB_Access_V2 | ||
| from azure.storage.blob import BlockBlobService, ContentSettings | ||
|
|
||
| from ..shared.db_provider import get_postgres_provider | ||
| from ..shared.db_access import ImageTagDataAccess, ImageInfo | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we exclusively using db_access_v2 at this point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, the code is in a file named db_access_v2.py, but it's been nested inside the db_access module. Check the /shared directory now. I'm going to delete the old db_access_v1 code in a follow up commit right now. |
||
| from azure.storage.blob import BlockBlobService | ||
|
|
||
| # TODO: User id as param to function - holding off until further discussion | ||
| # regarding whether user ID should be generated/looked up by the CLI or | ||
| # from within this function | ||
|
|
||
| default_db_host = "" | ||
| default_db_name = "" | ||
| default_db_user = "" | ||
| default_db_pass = "" | ||
|
|
||
| def main(req: func.HttpRequest) -> func.HttpResponse: | ||
| logging.info('Python HTTP trigger function processed a request.') | ||
|
|
||
|
|
@@ -41,19 +38,17 @@ def main(req: func.HttpRequest) -> func.HttpResponse: | |
| # Create ImageInfo object (def in db_access.py) | ||
| # Note: For testing, default image height/width are set to 50x50 | ||
| # TODO: Figure out where actual height/width need to come from | ||
| image = DB_Access_V2.ImageInfo(original_filename, url, 50, 50) | ||
| image = ImageInfo(original_filename, url, 50, 50) | ||
| # Append image object to the list | ||
| 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...") | ||
| db_config = DB_Access_V2.DatabaseInfo(os.getenv('DB_HOST', default_db_host), os.getenv('DB_NAME', default_db_name), os.getenv('DB_USER', default_db_user), os.getenv('DB_PASS', default_db_pass)) | ||
| data_access = DB_Access_V2.ImageTagDataAccess(DB_Access_V2.PostGresProvider(db_config)) | ||
| data_access = ImageTagDataAccess(get_postgres_provider()) | ||
| logging.info("Connected.") | ||
|
|
||
| # Create user id | ||
| user_id = data_access.create_user(DB_Access_V2.getpass.getuser()) | ||
| logging.info("The user id for '{0}' is {1}".format(DB_Access_V2.getpass.getuser(),user_id)) | ||
| user_id = data_access.create_user("testuser") # TODO: remove this hardcoding, should be passed in the request. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix this during next wave of changes. Plan to make user ID passed in the request. |
||
|
|
||
| # 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,39 @@ | ||
| import requests | ||
| import json | ||
| import pg8000 | ||
|
|
||
| # The following mock client imitates the CLI during the onboarding scenario for new images. | ||
| # The expectation is that the CLI uploads images to a temporary blob store, then gets a list | ||
| # of URLs to those images and passes the list to an HTTP trigger function in the format of | ||
| # a JSON string. The HTTP trigger function creates rows in the database for the images, | ||
| # retrieves the ImageId's for them, and then copies the images, each renamed as "ImageId.extension", | ||
| # into a permanent blob storage container. The HTTP function returns the list of URLs to | ||
| # the images in permanent blob storage. | ||
|
|
||
| print("\nTest client for CLI Onboarding scenario") | ||
| print('-' * 40) | ||
|
|
||
| # functionURL = "https://onboardinghttptrigger.azurewebsites.net/api/onboarding?code=lI1zl4IhiHcOcxTS85RsE7yZJXeNRxnr7tXSO1SrLWdpiN0W6hT3Jw==" | ||
| functionURL = "http://localhost:7071/api/onboarding" | ||
| # Sean's function URL: | ||
| # functionURL = "https://onboardinghttptrigger.azurewebsites.net/api/onboarding?code=lI1zl4IhiHcOcxTS85RsE7yZJXeNRxnr7tXSO1SrLWdpiN0W6hT3Jw==" | ||
| # functionURL = "https://abrig-linux-func.azurewebsites.net/api/onboarding" | ||
|
|
||
| urlList = { "imageUrls": ["https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies1.jpg", | ||
| "https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies2.jpg", | ||
| "https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies3.jpg"] } | ||
|
|
||
| headers = {"Content-Type": "application/json"} | ||
|
|
||
| print("Now executing POST request to onboard images...to:") | ||
| print("Function URL: " + functionURL) | ||
| print("Headers:") | ||
| for key, value in headers.items(): | ||
| print("\t" + key + ": " + value) | ||
| response = requests.post(url=functionURL, headers=headers, json=urlList) | ||
| print("Completed POST request.") | ||
|
|
||
| raw_response = response.text | ||
| response_array = raw_response.split(", ") | ||
| response_output = "\n".join(response_array) | ||
|
|
||
| print(f"Response status code: {response.status_code}") | ||
| print(f"Response string: {response_output}") | ||
| # import requests | ||
| # | ||
| # # The following mock client imitates the CLI during the onboarding scenario for new images. | ||
| # # The expectation is that the CLI uploads images to a temporary blob store, then gets a list | ||
| # # of URLs to those images and passes the list to an HTTP trigger function in the format of | ||
| # # a JSON string. The HTTP trigger function creates rows in the database for the images, | ||
| # # retrieves the ImageId's for them, and then copies the images, each renamed as "ImageId.extension", | ||
| # # into a permanent blob storage container. The HTTP function returns the list of URLs to | ||
| # # the images in permanent blob storage. | ||
| # | ||
| # print("\nTest client for CLI Onboarding scenario") | ||
| # print('-' * 40) | ||
| # | ||
| # # functionURL = "https://onboardinghttptrigger.azurewebsites.net/api/onboarding?code=lI1zl4IhiHcOcxTS85RsE7yZJXeNRxnr7tXSO1SrLWdpiN0W6hT3Jw==" | ||
| # functionURL = "http://localhost:7071/api/onboarding" | ||
| # # Sean's function URL: | ||
| # # functionURL = "https://onboardinghttptrigger.azurewebsites.net/api/onboarding?code=lI1zl4IhiHcOcxTS85RsE7yZJXeNRxnr7tXSO1SrLWdpiN0W6hT3Jw==" | ||
| # # functionURL = "https://abrig-linux-func.azurewebsites.net/api/onboarding" | ||
| # | ||
| # urlList = { "imageUrls": ["https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies1.jpg", | ||
| # "https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies2.jpg", | ||
| # "https://akaonboardingstorage.blob.core.windows.net/aka-temp-source-container/puppies3.jpg"] } | ||
| # | ||
| # headers = {"Content-Type": "application/json"} | ||
| # | ||
| # print("Now executing POST request to onboard images...to:") | ||
| # print("Function URL: " + functionURL) | ||
| # print("Headers:") | ||
| # for key, value in headers.items(): | ||
| # print("\t" + key + ": " + value) | ||
| # response = requests.post(url=functionURL, headers=headers, json=urlList) | ||
| # print("Completed POST request.") | ||
| # | ||
| # raw_response = response.text | ||
| # response_array = raw_response.split(", ") | ||
| # response_output = "\n".join(response_array) | ||
| # | ||
| # print(f"Response status code: {response.status_code}") | ||
| # print(f"Response string: {response_output}") |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .db_access_v2 import ImageTagDataAccess, ImageTag, ImageInfo, ImageTagState |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .db_provider import DatabaseInfo, DBProvider, PostGresProvider, get_postgres_provider |
Uh oh!
There was an error while loading. Please reload this page.