config¶
Configuration of the FastAPI server.
ServerConfig (ServerConfig)
pydantic-model
¶
This class stores server config parameters in a way that can be easily extended for new config file types.
databases_collection: str
pydantic-field
¶
Mongo collection name for /databases
endpoint resources.
gateways_collection: str
pydantic-field
¶
Mongo collection name for /gateways
endpoint resources.
load_optimade_providers_databases: bool
pydantic-field
¶
Whether or not to load all valid OPTIMADE providers' databases from the Materials-Consortia list of OPTIMADE providers on server startup.
queries_collection: str
pydantic-field
¶
Mongo collection name for /queries
endpoint resources.
replace_with_env_vars(value)
classmethod
¶
Replace string variables with environment variables, if possible
Source code in optimade_gateway/common/config.py
@validator("mongo_uri")
def replace_with_env_vars(cls, value: str) -> str:
"""Replace string variables with environment variables, if possible"""
res = value
for match in re.finditer(r"\{[^{}]+\}", value):
string_var = match.group()[1:-1]
env_var = os.getenv(
string_var, os.getenv(string_var.upper(), os.getenv(string_var.lower()))
)
if env_var is not None:
res = res.replace(match.group(), env_var)
else:
warn(
OptimadeGatewayWarning(
detail=(
"Could not find an environment variable for "
f"{match.group()!r} from mongo_uri: {value}"
)
)
)
return res