Skip to content

Commit

Permalink
Allow chris_superuser to be defined by environment variables CHRIS_US…
Browse files Browse the repository at this point in the history
…ERNAME and CHRIS_PASSWORD
  • Loading branch information
jennydaman committed Feb 12, 2024
1 parent 7917c10 commit 809284e
Show file tree
Hide file tree
Showing 4 changed files with 621 additions and 661 deletions.
23 changes: 22 additions & 1 deletion chrisomatic/spec/deserialize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

import serde
import strictyaml
import typer
from rich.console import Console
from rich.status import Status

Expand Down Expand Up @@ -30,4 +33,22 @@ def _load_from_yaml(input_config: str, filename: str, console: Console) -> Given
console.print(
f"[yellow]WARNING[/yellow]: on.chris_store_url in {filename} is deprecated."
)
return serde.from_dict(GivenConfig, parsed_yaml.data)
# messy new feature: if on.chris_superuser is not found in the YAML,
# get the superuser credentials from environment variables instead.
data = parsed_yaml.data
if "chris_superuser" not in parsed_yaml.data["on"]:
username = os.getenv("CHRIS_USERNAME", None)
password = os.getenv("CHRIS_PASSWORD", None)
if username is None or password is None:
console.print(f"[red]on.chris_superuser is not defined[/red]")
typer.Abort()
data |= {
"on": data["on"]
| {
"chris_superuser": {
"username": username,
"password": password,
}
}
}
return serde.from_dict(GivenConfig, data)
2 changes: 1 addition & 1 deletion chrisomatic/spec/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"on": Map(
{
"cube_url": api_url,
"chris_superuser": user,
Optional("chris_superuser"): user,
Optional(
"public_store", default=["https://cube.chrisproject.org/api/v1/"]
): EmptyList()
Expand Down
Loading

0 comments on commit 809284e

Please sign in to comment.