Skip to content

config

Configuration model

FMGSyncSettings #

Bases: BaseSettings

Application settings

update_token_in_repo_url #

update_token_in_repo_url(v: str, info: ValidationInfo)

add token to url if needed

Source code in fortimanager_template_sync/config.py
@field_validator("template_repo", mode="after")
def update_token_in_repo_url(cls, v: str, info: ValidationInfo):
    """add token to url if needed"""
    url = AnyHttpUrl(v)
    git_token: SecretStr = info.data.get("git_token")  # type: ignore # calm mypy, type is assured by pydantic
    if not git_token:
        return v
    url_with_token = Url.build(
        scheme=url.scheme, username=git_token.get_secret_value(), host=url.host or "", port=url.port, path=url.path
    )
    return str(url_with_token)

validate_fmg_url #

validate_fmg_url(url: str)

convert value to string

Source code in fortimanager_template_sync/config.py
@field_validator("fmg_url", mode="after")
def validate_fmg_url(cls, url: str):
    """convert value to string"""
    assert AnyHttpUrl(url)
    return url

validate_local_repo #

validate_local_repo(path: Path)

ensure local repo exists

Source code in fortimanager_template_sync/config.py
@field_validator("local_repo")
def validate_local_repo(cls, path: Path):
    """ensure local repo exists"""
    path.mkdir(exist_ok=True)
    return path