11import logging
2- import os
32import time
43from time import sleep
54from typing import Any , Dict , Optional
65
76import requests
87
9- CLIENT_ID = os .environ ["AURA_API_CLIENT_ID" ]
10- CLIENT_SECRET = os .environ ["AURA_API_CLIENT_SECRET" ]
11-
128
139class 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 (),
0 commit comments