Config Manager#

Summary

The ConfigManager is responsible saving, updating and retrieving credentials from keychain.

class ConfigManager(service_name: AnyStr = '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 (AnyStr) – The name of the service for storing credentials in the keyring. Defaults to ‘Patcher’.

Example:

config = ConfigManager("MyService")
get_credential(key: AnyStr) AnyStr[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.

Parameters:

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

Returns:

The retrieved credential value. If the key does not exist, returns None.

Return type:

AnyStr

Example:

token = config.get_credential("API_TOKEN")
set_credential(key: AnyStr, value: AnyStr)[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.

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

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

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:

AccessToken

attach_client(custom_ca_file: str | None = None) 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.

Parameters:

custom_ca_file (Optional[str]) – Optional path to a custom CA file for SSL verification.

Returns:

The JamfClient object if validation is successful, None otherwise.

Return type:

Optional[JamfClient]

create_client(client: JamfClient)[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.