Skip to content

Commit a61f8ba

Browse files
committed
Allow tenant to be configurable
1 parent d0bc72a commit a61f8ba

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

scripts/ci/aura_api_ci.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import logging
2-
import os
32
import time
43
from time import sleep
54
from typing import Any, Dict, Optional
65

76
import requests
87

9-
CLIENT_ID = os.environ["AURA_API_CLIENT_ID"]
10-
CLIENT_SECRET = os.environ["AURA_API_CLIENT_SECRET"]
11-
128

139
class AuraApiCI:
1410
class AuraAuthToken:
@@ -25,9 +21,11 @@ def __init__(self, json: Dict[str, Any]) -> None:
2521
def is_expired(self) -> bool:
2622
return self.expires_at >= int(time.time())
2723

28-
def __init__(self) -> None:
24+
def __init__(self, client_id: str, client_secret: str, tenant_id: Optional[str] = None) -> None:
2925
self._token: Optional[AuraApiCI.AuraAuthToken] = None
3026
self._logger = logging.getLogger()
27+
self._auth = (client_id, client_secret)
28+
self._tenant_id = tenant_id
3129

3230
def _build_header(self) -> Dict[str, str]:
3331
return {"Authorization": f"Bearer {self._auth_token()}", "User-agent": "neo4j-graphdatascience-ci"}
@@ -44,7 +42,7 @@ def _update_token(self) -> AuraAuthToken:
4442

4543
self._logger.debug("Updating oauth token")
4644

47-
response = requests.post("https://api-staging.neo4j.io/oauth/token", data=data, auth=(CLIENT_ID, CLIENT_SECRET))
45+
response = requests.post("https://api-staging.neo4j.io/oauth/token", data=data, auth=self._auth)
4846

4947
response.raise_for_status()
5048

@@ -143,6 +141,9 @@ def teardown_instance(self, db_id: str) -> None:
143141
response.raise_for_status()
144142

145143
def get_tenant_id(self) -> str:
144+
if self._tenant_id:
145+
return self._tenant_id
146+
146147
response = requests.get(
147148
"https://api-staging.neo4j.io/v1/tenants",
148149
headers=self._build_header(),

scripts/ci/run_targeting_aura.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def run_notebooks(uri: str, username: str, password: str) -> None:
2626

2727

2828
def main() -> None:
29-
aura_api = AuraApiCI()
29+
client_id = os.environ["AURA_API_CLIENT_ID"]
30+
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
31+
tenant_id = os.environ.get("TENANT_ID")
32+
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)
3033

3134
MAX_INT = 1000000
3235
instance_name = f"ci-build-{sys.argv[2]}" if len(sys.argv) > 1 else "ci-instance-" + str(rd.randint(0, MAX_INT))

scripts/ci/run_targeting_aura_sessions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212

1313
def main() -> None:
14-
aura_api = AuraApiCI()
14+
client_id = os.environ["AURA_API_CLIENT_ID"]
15+
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
16+
tenant_id = os.environ.get("TENANT_ID")
17+
aura_api = AuraApiCI(client_id=client_id, client_secret=client_secret, tenant_id=tenant_id)
1518

1619
MAX_INT = 1000000
17-
instance_name = f"ci-build-{sys.argv[1]}" if len(sys.argv) > 0 else "ci-instance-" + str(rd.randint(0, MAX_INT))
20+
instance_name = f"ci-build-{sys.argv[1]}" if len(sys.argv) > 1 else "ci-instance-" + str(rd.randint(0, MAX_INT))
1821

1922
create_result = aura_api.create_instance(instance_name, memory="1GB", type="professional-db")
2023
instance_id = create_result["id"]

0 commit comments

Comments
 (0)