diff --git a/DiasporaDemo.ipynb b/DiasporaDemo.ipynb index 9a563c0..6891a65 100644 --- a/DiasporaDemo.ipynb +++ b/DiasporaDemo.ipynb @@ -17,7 +17,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "#### Available Methods to Web Service APIs (version 0.2.9)\n", + "#### Available Methods to Web Service APIs (version 0.3.0)\n", "\n", "| Function and Arguments | Description |\n", "|------------------------|-------------|\n", diff --git a/diaspora_event_sdk/sdk/_environments.py b/diaspora_event_sdk/sdk/_environments.py index 348d2e7..38fc095 100644 --- a/diaspora_event_sdk/sdk/_environments.py +++ b/diaspora_event_sdk/sdk/_environments.py @@ -1,9 +1,20 @@ import os +from typing import Union -TOKEN_EXCHANGE = "http://3.220.110.101/" +# TOKEN_EXCHANGE = "http://3.220.110.101/" DIASPORA_RESOURCE_SERVER = "2b9d2f5c-fa32-45b5-875b-b24cd343b917" def _get_envname(): return os.getenv("DIASPORA_SDK_ENVIRONMENT", "production") + +def get_web_service_url(envname: Union[str, None] = None) -> str: + env = envname or _get_envname() + urls = { + "production": "https://diaspora-web-service.ml22sevubfnks.us-east-1.cs.amazonlightsail.com", + "dev": "https://diaspora-web-service-dev.ml22sevubfnks.us-east-1.cs.amazonlightsail.com", + "local": "http://localhost:8000", + } + + return urls.get(env, urls["production"]) diff --git a/diaspora_event_sdk/sdk/client.py b/diaspora_event_sdk/sdk/client.py index ff9c0e6..c6a12b3 100644 --- a/diaspora_event_sdk/sdk/client.py +++ b/diaspora_event_sdk/sdk/client.py @@ -7,7 +7,7 @@ requires_login, ) -from ._environments import DIASPORA_RESOURCE_SERVER, TOKEN_EXCHANGE +from ._environments import DIASPORA_RESOURCE_SERVER, get_web_service_url class Client: @@ -16,6 +16,8 @@ def __init__( environment: Optional[str] = None, login_manager: Optional[LoginManagerProtocol] = None, ): + self.web_service_address = get_web_service_url(environment) + # if a login manager was passed, no login flow is triggered if login_manager is not None: self.login_manager: LoginManagerProtocol = login_manager @@ -26,7 +28,7 @@ def __init__( self.login_manager.ensure_logged_in() self.web_client = self.login_manager.get_web_client( - base_url=TOKEN_EXCHANGE) + base_url=self.web_service_address) self.auth_client = self.login_manager.get_auth_client() self.subject_openid = self.auth_client.oauth2_userinfo()["sub"] diff --git a/diaspora_event_sdk/sdk/login_manager/decorators.py b/diaspora_event_sdk/sdk/login_manager/decorators.py index 4c25237..24f27d2 100644 --- a/diaspora_event_sdk/sdk/login_manager/decorators.py +++ b/diaspora_event_sdk/sdk/login_manager/decorators.py @@ -3,8 +3,6 @@ import globus_sdk -from .._environments import TOKEN_EXCHANGE - log = logging.getLogger(__name__) @@ -27,7 +25,7 @@ def wrapper(self, *args, **kwargs): self.login_manager.run_login_flow() # Initiate a new web client with updated authorizer self.web_client = self.login_manager.get_web_client( - base_url=TOKEN_EXCHANGE + base_url=self.web_service_address ) return func(self, *args, **kwargs) diff --git a/diaspora_event_sdk/sdk/web_client.py b/diaspora_event_sdk/sdk/web_client.py index 336e1fa..a4a9371 100644 --- a/diaspora_event_sdk/sdk/web_client.py +++ b/diaspora_event_sdk/sdk/web_client.py @@ -5,7 +5,7 @@ from diaspora_event_sdk.sdk.utils.uuid_like import UUID_LIKE_T -from ._environments import TOKEN_EXCHANGE +from ._environments import get_web_service_url class WebClient(globus_sdk.BaseClient): @@ -18,7 +18,7 @@ def __init__( **kwargs, ): if base_url is None: - base_url = TOKEN_EXCHANGE + base_url = get_web_service_url(environment) super().__init__(environment=environment, base_url=base_url, **kwargs) diff --git a/diaspora_event_sdk/version.py b/diaspora_event_sdk/version.py index 75cf783..493f741 100644 --- a/diaspora_event_sdk/version.py +++ b/diaspora_event_sdk/version.py @@ -1 +1 @@ -__version__ = "0.2.9" +__version__ = "0.3.0"