Skip to content

rs_server_common/settings.md

<< Back to index

Store diverse objects and values used throughout the application.

del_http_client() async

Close and delete HTTP client.

Source code in docs/rs-server/services/common/rs_server_common/settings.py
102
103
104
105
106
107
async def del_http_client():
    """Close and delete HTTP client."""
    global __HTTP_CLIENT  # pylint: disable=global-statement
    if __HTTP_CLIENT:
        await __HTTP_CLIENT.aclose()
    __HTTP_CLIENT = None

docs_params(prefix='')

Return the docs parameters for the FastAPI application.

Parameters:

Name Type Description Default
prefix str

Prefix to prepend to default values, when RSPY_DOCS_URL is not set. Defaults to "".

''

Returns:

Type Description
dict[str, str]

dict[str, str]: dict with FastAPI docs_url and openapi_url keys.

Source code in docs/rs-server/services/common/rs_server_common/settings.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def docs_params(prefix: str = "") -> dict[str, str]:
    """
    Return the docs parameters for the FastAPI application.

    Args:
        prefix (str, optional): Prefix to prepend to default values, when RSPY_DOCS_URL is not set. Defaults to "".

    Returns:
        dict[str, str]: dict with FastAPI docs_url and openapi_url keys.
    """
    # For cluster deployment: override the swagger /docs URL from an environment variable.
    # Also set the openapi.json URL under the same path.
    if "RSPY_DOCS_URL" in env:
        docs_url = env["RSPY_DOCS_URL"].strip("/")
        return {"docs_url": f"/{docs_url}", "openapi_url": f"/{docs_url}/openapi.json"}
    return {"docs_url": prefix + "/api.html", "openapi_url": prefix + "/api"}  # Default values from stac-fastapi

env_bool(var, default)

Return True if an environemnt variable is set to 1, true or yes (case insensitive). Return False if set to 0, false or no (case insensitive). Return the default value if not set or set to a different value.

Source code in docs/rs-server/services/common/rs_server_common/settings.py
28
29
30
31
32
33
34
35
36
37
38
39
def env_bool(var: str, default: bool) -> bool:
    """
    Return True if an environemnt variable is set to 1, true or yes (case insensitive).
    Return False if set to 0, false or no (case insensitive).
    Return the default value if not set or set to a different value.
    """
    val = os.getenv(var, str(default)).lower()
    if val in ("y", "yes", "t", "true", "on", "1"):
        return True
    if val in ("n", "no", "f", "false", "off", "0"):
        return False
    return default

http_client()

Get HTTP client

Source code in docs/rs-server/services/common/rs_server_common/settings.py
91
92
93
def http_client():
    """Get HTTP client"""
    return __HTTP_CLIENT

request_from_stacbrowser(request)

Return if the HTTP request comes from the STAC browser.

Source code in docs/rs-server/services/common/rs_server_common/settings.py
53
54
55
def request_from_stacbrowser(request: Request) -> bool:
    """Return if the HTTP request comes from the STAC browser."""
    return bool((origin := request.headers.get("origin")) and (origin.rstrip("/") in CORS_ORIGINS))

set_http_client(value)

Set HTTP client

Source code in docs/rs-server/services/common/rs_server_common/settings.py
96
97
98
99
def set_http_client(value):
    """Set HTTP client"""
    global __HTTP_CLIENT  # pylint: disable=global-statement
    __HTTP_CLIENT = value