Config Manager¶
- class ConfigManager(service_name: str = 'Patcher', in_memory_credentials: dict[str, str] | None = None)[source]¶
Manages configuration settings, primarily focused on handling credentials stored in the macOS keychain.
This class provides methods to securely store, retrieve, and manage sensitive information such as API tokens and client credentials. It integrates with the
keyringlibrary to interface with the macOS keychain.ConfigManagerobjects are initialized with a default service name of “Patcher”, which is used as a namespace for storing and retrieving credentials in macOS keychain.For non-interactive use (CI/CD environments without a keychain backend), pass
in_memory_credentialsto bypass the keychain entirely. Reads check the in-memory dict first and fall through to keyring only if the key is absent. Writes go to the in-memory dict only; keyring is not touched.- Parameters:
- property in_memory_mode: bool[source]¶
Whether this manager bypasses the keyring (CI/CD-friendly mode).
- get_credential(key: str) str[source]¶
Retrieves a credential by key. In in-memory mode, returns from the in-memory dict (or
Noneif absent). Otherwise reads from the macOS keychain.- Parameters:
key (str) – The key of the credential to retrieve, typically a descriptive name like ‘API_KEY’.
- Returns:
The retrieved credential value.
- Return type:
- Raises:
CredentialError – If the specified credential could not be retrieved.
- set_credential(key: str, value: str) None[source]¶
Stores a credential. In in-memory mode, writes to the in-memory dict only; the keychain is never touched. Otherwise writes to the macOS keychain.
- Parameters:
- Raises:
CredentialError – If the specified credential could not be saved.
- Return type:
None
- delete_credential(key: str) bool[source]¶
Deletes the provided credential in the keyring under the specified key. Primarily intended for use with the
--resetflag (Seereset_config()).If the specified credential could not be deleted, an error is logged.
- create_client(client: JamfCredentials, token: AccessToken) None[source]¶
Persist a
JamfCredentialsobject plus its bearer token into the configured credential backend (keyring or in-memory).Used during setup once a JamfCredentials has been validated and a token has been fetched. Stores
CLIENT_ID,CLIENT_SECRET,URL,TOKEN,TOKEN_EXPIRATION.- Parameters:
client (
JamfCredentials) – TheJamfCredentialsobject whose values will be stored.token (
AccessToken) – TheAccessTokenobject to save.
- Raises:
CredentialError – If any individual credential write fails (propagated from
set_credential()).- Return type:
None