From 5de33ab768eb69ce8531998108960fdf5a660d5a Mon Sep 17 00:00:00 2001 From: Chris Woodward Date: Fri, 22 Jul 2022 17:21:54 -0400 Subject: [PATCH 1/6] adds Optional for tutorialName and cred provider --- adb_cloud_connector/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/adb_cloud_connector/utils.py b/adb_cloud_connector/utils.py index a6c8325..6a6ce3b 100644 --- a/adb_cloud_connector/utils.py +++ b/adb_cloud_connector/utils.py @@ -2,7 +2,7 @@ import os import time from json.decoder import JSONDecodeError -from typing import Any, Dict +from typing import Any, Dict, Optional import requests from requests.exceptions import HTTPError @@ -11,7 +11,10 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) -def get_temp_credentials() -> Json: +def get_temp_credentials( + tutorialName: Optional[str] = None, + credentialProvider: Optional[str] = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB" + ) -> Json: creds_file = f"{dir_path}/data/creds.json" try: @@ -26,8 +29,9 @@ def get_temp_credentials() -> Json: except (JSONDecodeError, HTTPError): print("Log: requesting new credentials...") - url = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB" - response = requests.post(url, data=json.dumps({})) + url = credentialProvider + body = {"tutorialName": tutorialName} if tutorialName else "{}" + response = requests.post(url, data=json.dumps(body)) response.raise_for_status() data: Json = response.json() From 6a7ed4c1c9faf7569bc8dcffb338cab5b5a2efe9 Mon Sep 17 00:00:00 2001 From: Chris Woodward Date: Fri, 22 Jul 2022 17:22:07 -0400 Subject: [PATCH 2/6] updates test case --- tests/test_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index e5031e6..471a6d1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,8 +1,8 @@ from adb_cloud_connector import get_temp_credentials - def test_get_temp_credentials() -> None: new_creds = get_temp_credentials() + print(new_creds) assert new_creds.keys() == { "url", "hostname", @@ -13,3 +13,5 @@ def test_get_temp_credentials() -> None: } cached_creds = get_temp_credentials() assert cached_creds == new_creds +test_get_temp_credentials() + From e37d09bd799d644b213879e568414fbd027b46eb Mon Sep 17 00:00:00 2001 From: Chris Woodward Date: Fri, 22 Jul 2022 17:29:11 -0400 Subject: [PATCH 3/6] fixes formatting --- adb_cloud_connector/utils.py | 8 +++++--- tests/test_utils.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/adb_cloud_connector/utils.py b/adb_cloud_connector/utils.py index 6a6ce3b..be50f70 100644 --- a/adb_cloud_connector/utils.py +++ b/adb_cloud_connector/utils.py @@ -12,9 +12,11 @@ def get_temp_credentials( - tutorialName: Optional[str] = None, - credentialProvider: Optional[str] = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB" - ) -> Json: + tutorialName: Optional[str] = None, + credentialProvider: Optional[ + str + ] = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB", +) -> Json: creds_file = f"{dir_path}/data/creds.json" try: diff --git a/tests/test_utils.py b/tests/test_utils.py index 471a6d1..092addf 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,6 @@ from adb_cloud_connector import get_temp_credentials + def test_get_temp_credentials() -> None: new_creds = get_temp_credentials() print(new_creds) @@ -13,5 +14,6 @@ def test_get_temp_credentials() -> None: } cached_creds = get_temp_credentials() assert cached_creds == new_creds + + test_get_temp_credentials() - From 4dd178c3c20aaa02081623a1b07640ef000d8bc4 Mon Sep 17 00:00:00 2001 From: Chris Woodward Date: Fri, 22 Jul 2022 17:31:16 -0400 Subject: [PATCH 4/6] removes unneeded method call --- tests/test_utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 092addf..1c55f2f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,7 +13,4 @@ def test_get_temp_credentials() -> None: "password", } cached_creds = get_temp_credentials() - assert cached_creds == new_creds - - -test_get_temp_credentials() + assert cached_creds == new_creds \ No newline at end of file From c69490f4e24d904e6719ad466df4bf48ed399b69 Mon Sep 17 00:00:00 2001 From: aMahanna Date: Fri, 22 Jul 2022 17:33:44 -0400 Subject: [PATCH 5/6] fix: black is being silly --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1c55f2f..967e084 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,4 +13,4 @@ def test_get_temp_credentials() -> None: "password", } cached_creds = get_temp_credentials() - assert cached_creds == new_creds \ No newline at end of file + assert cached_creds == new_creds From abba8f16eef441a08369e52167e2518f2198c883 Mon Sep 17 00:00:00 2001 From: aMahanna Date: Fri, 22 Jul 2022 17:37:55 -0400 Subject: [PATCH 6/6] fix: mypy --- adb_cloud_connector/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adb_cloud_connector/utils.py b/adb_cloud_connector/utils.py index be50f70..3dfbbce 100644 --- a/adb_cloud_connector/utils.py +++ b/adb_cloud_connector/utils.py @@ -13,9 +13,7 @@ def get_temp_credentials( tutorialName: Optional[str] = None, - credentialProvider: Optional[ - str - ] = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB", + credentialProvider: str = "https://tutorials.arangodb.cloud:8529/_db/_system/tutorialDB/tutorialDB", ) -> Json: creds_file = f"{dir_path}/data/creds.json"