-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DM-41830] Add some sanity checking on siav2 labels
- Loading branch information
Showing
1 changed file
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,47 @@ | ||
import os | ||
|
||
import pyvo | ||
from pyvo.dal import SIA2Service | ||
|
||
from .utils import get_pyvo_auth, get_service_url | ||
|
||
def get_siav2_service(*args: str) -> pyvo.dal.SIA2Service: | ||
|
||
LSST_CLOUD = [ | ||
"https://data.lsst.cloud", | ||
"https://data-int.lsst.cloud", | ||
"https://data-dev.lsst.cloud" | ||
] | ||
|
||
USDF = [ | ||
"https://usdf-rsp.slac.stanford.edu/", | ||
"https://usdf-rsp-dev.slac.stanford.edu/" | ||
] | ||
|
||
|
||
def get_siav2_service(*args: str) -> SIA2Service: | ||
"""Return a configured SIA2Service object that is ready to use.""" | ||
fqdn = os.environ["EXTERNAL_INSTANCE_URL"] | ||
|
||
if len(args) == 0: | ||
ds = "dp0.2" | ||
elif args == "latiss": | ||
ds = "latiss" | ||
# Use the default for each environment | ||
if fqdn in LSST_CLOUD: | ||
label = "dp0.2" | ||
elif fqdn in USDF: | ||
label = "latiss" | ||
else: | ||
raise Exception("Unknown environment" + fqdn) | ||
else: | ||
label = args[0] | ||
|
||
# If a label is passed, check that. | ||
if label not in ["dp0.2", "latiss"]: | ||
raise Exception(label + " is not a valid siav2 label") | ||
|
||
if label == "latiss" and fqdn not in USDF: | ||
raise Exception(label + " data not available at your location") | ||
if label == "dp0.2" and fqdn not in LSST_CLOUD: | ||
raise Exception(label + " data not available at your location") | ||
|
||
# No matter what, we've only got one sia server per environment | ||
# so for now just do some checking. | ||
return SIA2Service(get_service_url("siav2"), get_pyvo_auth()) |