Config Manager#

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.

ConfigManager objects are initialized with a default service name of “Patcher”, which is used as a namespace for storing and retrieving credentials in macOS keychain.

Parameters:

service_name (str) – Service name for storing credentials in the keyring. Defaults to ‘Patcher’.

get_credential(key: str) str[source]#

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.

Parameters:

key (str) – The key of the credential to retrieve, typically a descriptive name like ‘API_KEY’.

Returns:

The retrieved credential value.

Return type:

str

Raises:

CredentialError – If the specified credential could not be 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, and API credentials such as client ID and client secret.

Parameters:
  • key (str) – The key under which the credential will be stored. This acts as an identifier for the credential.

  • value (str) – The value of the credential to store, such as a password or API token.

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 --reset flag (See reset()).

If the specified credential could not be deleted, an error is logged.

Parameters:

key (str) – The credential to delete.

Returns:

True if the credential was successfully deleted, False otherwise.

Return type:

bool

create_client(client: JamfClient, token: AccessToken) 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.

If any of the client credentials could not be saved, a CredentialError is raised via the set_credential() method.

Parameters:
  • client (JamfClient) – The JamfClient object whose credentials will be stored.

  • token (AccessToken) – The AccessToken object to save.

Return type:

None

reset_config() bool[source]#

Resets all credentials by deleting them from the keyring.

Returns:

True if all credentials were successfully deleted, False otherwise.

Return type:

bool