Configuration Reference
Config structures.
teams_lib_pzsp2_z1.config
Package config holds configuration structures used across the application.
This module defines data classes for authentication, request sending, and caching, as well as utility functions to load and validate these configurations from environment variables.
Classes
AuthConfig
dataclass
Holds configuration required for authentication via MSAL.
All fields are required to successfully acquire tokens.
Attributes:
| Name | Type | Description |
|---|---|---|
client_id |
str
|
The Application (client) ID assigned by the Azure portal. |
tenant |
str
|
The Directory (tenant) ID or domain. |
email |
str
|
The email address of the user to authenticate. |
scopes |
list[str]
|
A list of Graph API permission scopes (e.g., "User.Read"). |
auth_method |
str
|
The flow used to acquire tokens. Valid values are: * "DEVICE_CODE": Prints a code to console; user visits a URL. * "INTERACTIVE": Opens a local browser window. |
Source code in teams_lib_pzsp2_z1/config.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
AuthConfigurationError
Bases: Exception
Raised when the authentication configuration is missing or invalid.
Source code in teams_lib_pzsp2_z1/config.py
16 17 18 | |
CacheConfig
dataclass
Holds configuration for the caching layer.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
CacheMode
|
The caching strategy to use. |
path |
str | None
|
The file path for the cache storage (e.g., JSON file). Required if mode is not DISABLED. Defaults to None. |
Source code in teams_lib_pzsp2_z1/config.py
78 79 80 81 82 83 84 85 86 87 88 89 | |
CacheMode
Bases: Enum
Defines the caching strategy used by the application.
Attributes:
| Name | Type | Description |
|---|---|---|
DISABLED |
Caching is turned off completely. |
|
SYNC |
Cache operations (read/write) are performed synchronously. Safe but may block the main thread. |
|
ASYNC |
Cache operations are performed asynchronously in the background.
Faster for the main thread but requires |
Source code in teams_lib_pzsp2_z1/config.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
SenderConfig
dataclass
Defines configuration for the HTTP request sender connecting to Microsoft Graph API.
Attributes:
| Name | Type | Description |
|---|---|---|
max_retries |
int
|
The maximum number of retry attempts for failed requests. Defaults to 3. |
next_retry_delay |
int
|
The delay between retry attempts in seconds. Defaults to 2. |
timeout |
int
|
The maximum time to wait for a request to complete in seconds. Defaults to 10. |
Source code in teams_lib_pzsp2_z1/config.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
Functions
get_env(key, fallback)
Retrieves an environment variable with a fallback value.
Source code in teams_lib_pzsp2_z1/config.py
126 127 128 129 | |
load_auth_config(env_path=None)
Loads authentication configuration from environment variables or a .env file.
It looks for the following environment variables:
* CLIENT_ID
* TENANT_ID
* EMAIL
* SCOPES (comma-separated, defaults to "https://graph.microsoft.com/.default")
* AUTH_METHOD (defaults to "DEVICE_CODE")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_path
|
str | None
|
Path to the .env file. If None, loads from the current directory. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AuthConfig |
AuthConfig
|
A populated and validated configuration object. |
Raises:
| Type | Description |
|---|---|
AuthConfigurationError
|
If required variables are missing or values are invalid. |
Source code in teams_lib_pzsp2_z1/config.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
validate(cfg)
Validates the authentication configuration object.
Checks for the presence of required fields and the validity of the auth method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
AuthConfig
|
The configuration object to validate. |
required |
Raises:
| Type | Description |
|---|---|
AuthConfigurationError
|
If |
Source code in teams_lib_pzsp2_z1/config.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |