Initialize SecretsManager with proper error handling. Args: ksm_config_path (str): Path to KSM config file (optional) ksm_token (str): KSM access token (optional) Returns: SecretsManager: Initialized SecretsManager or None if failed
(ksm_config_path, ksm_token)
| 257 | |
| 258 | |
| 259 | def _initialize_secrets_manager(ksm_config_path, ksm_token): |
| 260 | """ |
| 261 | Initialize SecretsManager with proper error handling. |
| 262 | |
| 263 | Args: |
| 264 | ksm_config_path (str): Path to KSM config file (optional) |
| 265 | ksm_token (str): KSM access token (optional) |
| 266 | |
| 267 | Returns: |
| 268 | SecretsManager: Initialized SecretsManager or None if failed |
| 269 | """ |
| 270 | from keeper_secrets_manager_core import SecretsManager |
| 271 | from keeper_secrets_manager_core.storage import FileKeyValueStorage |
| 272 | |
| 273 | server_key_args = _custom_server_key_args() |
| 274 | |
| 275 | def create(**kwargs): |
| 276 | try: |
| 277 | return SecretsManager(**kwargs, **server_key_args) |
| 278 | except TypeError: |
| 279 | if not server_key_args: |
| 280 | raise |
| 281 | # keeper-secrets-manager-core before 17.3.0 has no server_public_key argument; |
| 282 | # add the key to the SDK's own key table instead. |
| 283 | from keeper_secrets_manager_core.keeper_globals import keeper_public_keys |
| 284 | keeper_public_keys[server_key_args['server_public_key_id']] = server_key_args['server_public_key'] |
| 285 | return SecretsManager(**kwargs) |
| 286 | |
| 287 | try: |
| 288 | if ksm_config_path: |
| 289 | if not os.path.exists(ksm_config_path): |
| 290 | print("ERROR: KSM config file not found") |
| 291 | return None |
| 292 | return create(config=FileKeyValueStorage(ksm_config_path)) |
| 293 | else: |
| 294 | return create(token=ksm_token) |
| 295 | except Exception as e: |
| 296 | print(f"ERROR: Failed to initialize SecretsManager: {e}") |
| 297 | return None |
| 298 | |
| 299 | |
| 300 | def _get_secret_by_uid_or_title(secrets_manager, record_identifier): |
no test coverage detected