Skip to content

config

Configuration of the FastAPI server

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(v) 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, v):
    """Replace string variables with environment variables, if possible"""
    res: str = v
    for match in re.finditer(r"\{[^{}]+\}", v):
        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:
            warnings.warn(
                f"Could not find an environment variable for {match.group()!r} from mongo_uri: {v}",
                OptimadeGatewayWarning,
            )
    return res
Back to top