diff --git a/python/lsst/daf/butler/remote_butler/server/_config.py b/python/lsst/daf/butler/remote_butler/server/_config.py new file mode 100644 index 0000000000..6aad27028d --- /dev/null +++ b/python/lsst/daf/butler/remote_butler/server/_config.py @@ -0,0 +1,46 @@ +# This file is part of daf_butler. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (http://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This software is dual licensed under the GNU General Public License and also +# under a 3-clause BSD license. Recipients may choose which of these licenses +# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, +# respectively. If you choose the GPL option then the following text applies +# (but note that there is still no warranty even if you opt for BSD instead): +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os +from dataclasses import dataclass + +__all__ = ("Config", "get_config_from_env") + + +@dataclass(frozen=True) +class Config: + butler_root: str + + +def get_config_from_env() -> Config: + butler_root = os.getenv("BUTLER_SERVER_BUTLER_ROOT") + if butler_root is None: + raise Exception( + "The environment variable BUTLER_SERVER_BUTLER_ROOT " + "must point to a Butler configuration to be used by the server" + ) + return Config(butler_root=butler_root) diff --git a/python/lsst/daf/butler/remote_butler/server/_server.py b/python/lsst/daf/butler/remote_butler/server/_server.py index 3be9348223..b9404d47a5 100644 --- a/python/lsst/daf/butler/remote_butler/server/_server.py +++ b/python/lsst/daf/butler/remote_butler/server/_server.py @@ -37,10 +37,9 @@ from fastapi.middleware.gzip import GZipMiddleware from lsst.daf.butler import Butler +from ._config import get_config_from_env from ._factory import Factory -BUTLER_ROOT = "ci_hsc_gen3/DATA" - log = logging.getLogger(__name__) app = FastAPI() @@ -49,7 +48,8 @@ @cache def _make_global_butler() -> Butler: - return Butler.from_config(BUTLER_ROOT) + config = get_config_from_env() + return Butler.from_config(config.butler_root) def factory_dependency() -> Factory: