Config Manager#
Summary
The ConfigManager
is responsible saving, updating and retrieving credentials from keychain.
- class ConfigManager(service_name: str = 'Patcher')[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
keyring
library to interface with the macOS keychain.Initializes the ConfigManager with a specific service name.
This service name is used as a namespace for storing and retrieving credentials in the keyring, allowing you to organize credentials by the service they pertain to.
- Parameters:
service_name (str) – The name of the service for storing credentials in the keyring. Defaults to ‘Patcher’.
- get_credential(key: str) str [source]#
Retrieves a specified credential from the keyring associated with the given key.
This method is useful for accessing stored credentials without hardcoding them in scripts. It ensures that sensitive data like passwords or API tokens are securely stored and retrieved.
- set_credential(key: str, value: str) None [source]#
Stores a credential in the keyring under the specified key.
Method is used to securely store sensitive data such as Jamf URL, API Tokens, usernames and passwords.
- load_token() AccessToken [source]#
Loads the access token and its expiration from the keyring.
- Returns:
An
AccessToken
object containing the token and its expiration date.- Return type:
- attach_client() JamfClient | None [source]#
Creates and returns a
patcher.models.jamf_client
object using the stored credentials. Allows for an optional custom CA file to be passed, which can be useful for environments with custom certificate authorities.- Returns:
The
JamfClient
object if validation is successful, None otherwise.- Return type:
Optional[JamfClient]
- create_client(client: JamfClient) None [source]#
Stores a
JamfClient
object’s credentials in the keyring.This method is typically used during the setup process to save the credentials and token of a
JamfClient
object into the keyring for secure storage and later use.- Parameters:
client (JamfClient) – The
JamfClient
object whose credentials will be stored.- Return type:
None