Config Manager#
- class ConfigManager(service_name: str = 'Patcher', in_memory_credentials: dict[str, str] | None = None)[source]#
Resolves Jamf credentials from the macOS keychain, or holds them in memory for library use.
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 under the specified key. Primarily intended for use with the
--resetflag (Seereset_config()).Deletion is best-effort and always reports success: an absent credential is already in the desired state, and a present-but-undeletable one is overwritten at the next setup. A genuinely broken keyring fails loudly at write time in
set_credential(), which is the right place to surface it.
- 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