Skip to content

Commit

Permalink
Merge pull request #3 from globus-labs/new-endpoint
Browse files Browse the repository at this point in the history
New endpoint
  • Loading branch information
haochenpan authored Jun 1, 2024
2 parents 1fe3d13 + f21629f commit 5fb73e7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DiasporaDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 12 additions & 1 deletion diaspora_event_sdk/sdk/_environments.py
Original file line number Diff line number Diff line change
@@ -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"])
6 changes: 4 additions & 2 deletions diaspora_event_sdk/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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"]

Expand Down
4 changes: 1 addition & 3 deletions diaspora_event_sdk/sdk/login_manager/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import globus_sdk

from .._environments import TOKEN_EXCHANGE

log = logging.getLogger(__name__)


Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions diaspora_event_sdk/sdk/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion diaspora_event_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.9"
__version__ = "0.3.0"

0 comments on commit 5fb73e7

Please sign in to comment.