Skip to content

Commit

Permalink
Merge pull request #126 from lsst-sqre/tickets/DM-42660
Browse files Browse the repository at this point in the history
DM-42660: Use Butler repository list from environment var
  • Loading branch information
dhirving authored Jan 26, 2024
2 parents 1871aaa + 378744c commit e7c97af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/start-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -n "$DATALINKER_TAP_METADATA_URL" ]; then
exit 1
fi
curl -L "$DATALINKER_TAP_METADATA_URL" -o /tmp/datalink-columns.zip
unzip /tmp/datalink-columns.zip -d "$DATALINKER_TAP_METADATA_DIR"
unzip -o /tmp/datalink-columns.zip -d "$DATALINKER_TAP_METADATA_DIR"
fi

rm -rf /tmp/secrets
Expand Down
24 changes: 23 additions & 1 deletion src/datalinker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
from __future__ import annotations

import os
from dataclasses import dataclass
from dataclasses import dataclass, field

from pydantic import TypeAdapter

__all__ = ["Configuration", "config"]


def _get_butler_repositories() -> dict[str, str] | None:
json = os.getenv("DAF_BUTLER_REPOSITORIES", None)
if json is not None:
return TypeAdapter(dict[str, str]).validate_json(json)

return None


@dataclass
class Configuration:
"""Configuration for datalinker."""
Expand Down Expand Up @@ -76,6 +86,18 @@ class Configuration:
Set with the ``S3_ENDPOINT_URL`` environment variable.
"""

# TODO DM-42660: butler_repositories can be removed once there is a release
# of daf_butler available that handles DAF_BUTLER_REPOSITORIES itself.
butler_repositories: dict[str, str] | None = field(
default_factory=_get_butler_repositories
)
"""Mapping from label to URI for Butler repositories used by this service.
Set with the ``DAF_BUTLER_REPOSITORIES`` environment variable. If not set,
Butler will fall back to looking this up from a file whose URI is given in
the ``DAF_BUTLER_REPOSITORY_INDEX`` environment variable.
"""


config = Configuration()
"""Configuration for datalinker."""
2 changes: 1 addition & 1 deletion src/datalinker/handlers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
external_router = APIRouter()
"""FastAPI router for all external handlers."""

_BUTLER_FACTORY = LabeledButlerFactory()
_BUTLER_FACTORY = LabeledButlerFactory(config.butler_repositories)
"""Factory for creating Butlers from a label and Gafaelfawr token."""

_TEMPLATES = Jinja2Templates(
Expand Down

0 comments on commit e7c97af

Please sign in to comment.