sasvi.settings
Resolve the SASVI_* connection settings and say where each came from.
resolve_settings is the one place that decides which tenant, which TLS
setting and which credential a client gets. sasvi.SVIClient.from_env
calls it, and so does every sasvi command, so the two cannot disagree.
Precedence, highest first:
- explicit overrides (keyword arguments, command-line options);
- the process environment;
- the keys of a
.envfile, when one is named; - a named profile from
profiles.toml(seesasvi.profiles); - the
sasvi auth logincache, when asked for. It supplies the credential (and the base URL and TLS setting when nothing above sets them), and only for the origin the login was made for.
The SDK reads a .env file, a profile or the login cache only when the
caller asks for it. With no options the result is the SASVI_* part of the
process environment, which is what from_env has always read. Nothing here
writes to os.environ.
SettingSource Objects
class SettingSource(StrEnum)
Where an effective setting came from.
OVERRIDE
ENVIRONMENT
ENV_FILE
PROFILE
LOGIN_CACHE
SECRET_SETTINGS
Settings whose value is a credential. ResolvedSettings.redacted hides them.
LoginCacheDecision Objects
@dataclass(frozen=True)
class LoginCacheDecision()
What the sasvi auth login cache contributed, and why.
Arguments:
reason- One ofused;not-requested(the caller did not ask for the cache);token-preset(a higher layer setsSASVI_ACCESS_TOKEN);no-cache;unreadable(the file exists but does not load);expired; ororigin-mismatch(the base URL in use is not the one the login was made for).supplied_keys- TheSASVI_*settings the cache supplied.cached_base_url- The origin of the cached login, forusedandorigin-mismatch.path- The cache file that was consulted, orNonewhen none was.
reason
supplied_keys
cached_base_url
path
used
@property
def used() -> bool
Whether the cached login supplies the credential.
ResolvedSettings Objects
@dataclass(frozen=True)
class ResolvedSettings()
The effective SASVI_* settings and the source of each.
Arguments:
values- Setting name to value. It holds credentials, so it is left out ofrepr; useredactedto show it.sources- Setting name to the layer that supplied it.env_file- The.envfile that was read, orNone.profile- The profile that was applied, orNone.login_cache- What the login cache contributed.warnings- Sentences about settings that were ignored or do not match the profile, already logged at WARNING.
values
sources
env_file
profile
login_cache
warnings
get
def get(key: str, default: str | None = None) -> str | None
Return the effective value of one setting.
Arguments:
key- ASASVI_*name.default- Returned when no layer sets it.
Returns:
The value, or default.
source_of
def source_of(key: str) -> SettingSource | None
Return the layer that supplied a setting.
Arguments:
key- ASASVI_*name.
Returns:
The source, or None when no layer sets it.
credential_mode
@property
def credential_mode() -> str | None
The credential from_env builds from these settings, or None.
The order is the one from_env uses: an access token (token, or
login when the login cache supplied it), then client-credentials,
then password.
redacted
def redacted() -> dict[str, str]
Return the values with every credential replaced by <set>.
Returns:
A copy that is safe to print.
to_dict
def to_dict() -> PythonObject
Return a printable summary: redacted values, sources, file, profile and cache.
Returns:
A JSON-serializable mapping that holds no credential.
read_env_file
def read_env_file(path: str | os.PathLike[str]) -> dict[str, str]
Parse a .env file without touching the environment.
The accepted grammar is one KEY=value per line. A leading export
is dropped, blank lines and lines starting with # are skipped, a value
may be wrapped in single or double quotes, and an unquoted value ends at
the first #. When a key repeats, the first one wins.
Arguments:
path- The file to read.
Returns:
Every key the file sets, with its value.
Raises:
SVIConfigurationError- When the path is not a readable regular file.
resolve_settings
def resolve_settings(
*,
env_file: str | os.PathLike[str] | None = None,
use_login_cache: bool = False,
profile: str | None = None,
environ: Mapping[str, str] | None = None,
overrides: Mapping[str, str] | None = None,
base_url: str | None = None,
login_cache_path: str | os.PathLike[str] | None = None,
profiles_file: str | os.PathLike[str] | None = None
) -> ResolvedSettings
Resolve the effective SASVI_* settings and their sources.
See the module docstring for the precedence. With no arguments the result
is the SASVI_* part of os.environ.
Arguments:
env_file- A.envfile whose keys sit below the process environment.use_login_cache- Read thesasvi auth logincache. It suppliesSASVI_ACCESS_TOKENwhen no layer above sets one and the base URL in use is the cached origin, plusSASVI_BASE_URLandSASVI_VERIFY_SSLwhen no layer above sets them.profile- A profile name fromprofiles.toml. The SDK does not readSASVI_PROFILEor the file's default on its own; seesasvi.profiles.active_profile_name.environ- The process environment to read; defaults toos.environ.overrides-SASVI_*values that win over every layer.base_url- The base URL the client will use when it is passed in code rather than asSASVI_BASE_URL. The login cache is used only when it is the cached origin.login_cache_path- The cache file; defaults to the profile's cache, or the default one without a profile.profiles_file- The profiles file; defaults tosasvi.profiles.profiles_path.
Returns:
The settings, their sources, and what the profile and cache contributed.
Raises:
SVIConfigurationError- When the.envfile is missing or unreadable.sasvi.profiles.ProfileNotFoundError- When the profile is not defined.sasvi.profiles.ProfileFileError- When the profiles file is not valid.