Skip to content

Commit

Permalink
refactor(managed-data): switch to new nucleus_api_route
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-s committed Apr 11, 2024
1 parent 7c7a084 commit 0d615fc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
from ..exceptions import DeepOriginException

CONFIG_DIR = pathlib.Path(__file__).parent
CONFIG_YML_LOCATION = os.path.expanduser(
os.path.join(
"~",
".deep-origin",
"config.yml",
)
)

__all__ = ["get_value"]


@functools.cache
def get_value(
user_config_filenames: collections.abc.Iterable[str] = (
os.path.expanduser(os.path.join("~", ".deep-origin", "config.yml")),
CONFIG_YML_LOCATION,
os.path.join(".deep-origin", "config.yml"),
),
) -> confuse.templates.AttrDict:
Expand Down Expand Up @@ -47,8 +54,9 @@ def get_value(
"organization_id": confuse.String(),
"bench_id": confuse.String(),
"env": confuse.String(),
"nucleus_api_endpoint": confuse.String(),
"api_endpoint": confuse.String(),
"api_endpoint": confuse.Optional(confuse.String()),
"nucleus_api_route": confuse.String(),
"graphql_api_route": confuse.String(),
"auth_domain": confuse.String(),
"auth_device_code_endpoint": confuse.String(),
"auth_token_endpoint": confuse.String(),
Expand Down
7 changes: 4 additions & 3 deletions src/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ env: local
organization_id: null
bench_id: null
api_endpoint: null
nucleus_api_endpoint: null
nucleus_api_route: nucleus-api/api/
graphql_api_route: api/graphql/
auth_domain: null
auth_device_code_endpoint: /oauth/device/code
auth_token_endpoint: /oauth/token
auth_device_code_endpoint: oauth/device/code/
auth_token_endpoint: oauth/token/
auth_audience: null
auth_grant_type: urn:ietf:params:oauth:grant-type:device_code
auth_client_id: null
Expand Down
1 change: 0 additions & 1 deletion src/do_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def get_do_api_tokens() -> tuple[str, str]:
config = get_config()

if os.path.isfile(config.api_tokens_filename):
print(f"file exists @ {config.api_tokens_filename}")
tokens = read_cached_do_api_tokens()
refresh_token = tokens["refresh"]

Expand Down
3 changes: 2 additions & 1 deletion src/managed_data/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from deeporigin import cache_do_api_tokens, get_do_api_tokens
from deeporigin.config import get_value
from deeporigin.exceptions import DeepOriginException
from deeporigin.utils import _nucleus_url

API_URL = get_value()["nucleus_api_endpoint"]
ORG_ID = get_value()["organization_id"]
API_URL = _nucleus_url()


@beartype
Expand Down
14 changes: 14 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import os
from urllib.parse import urljoin

from beartype import beartype
from deeporigin.config import get_value

__all__ = [
"expand_user",
Expand All @@ -8,6 +12,16 @@
PREFIX = "deeporigin://"


@beartype
def _nucleus_url() -> str:
"""returns URL for nucleus API endpoint"""
return urljoin(
get_value()["api_endpoint"],
get_value()["nucleus_api_route"],
)


@beartype
def expand_user(path, user_home_dirname: str = os.path.expanduser("~")) -> str:
"""Expand paths that start with `~` by replacing it the user's home directory
Expand Down
4 changes: 3 additions & 1 deletion tests/test_low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from deeporigin.config import get_value
from deeporigin.exceptions import DeepOriginException
from deeporigin.managed_data import _api, api
from deeporigin.utils import _nucleus_url

API_URL = _nucleus_url()
# constants
row_description_keys = {
"id",
Expand Down Expand Up @@ -62,7 +64,7 @@

# if we're running against a real instance, determine
# if the database has any files in it
if get_value()["nucleus_api_endpoint"] != MOCK_URL:
if API_URL != MOCK_URL:
df = api.get_dataframe(DB_NAME)
file_ids = df.attrs["file_ids"]
if len(file_ids) == 0:
Expand Down

0 comments on commit 0d615fc

Please sign in to comment.