Generic Python Script using KSM SDK
#!/usr/bin/env python3
import sys
import base64
import json
# Requires Keeper Secrets Manager Python SDK installed and initialized
# with device config that provides access to the vault records
# pip install keeper-secrets-manager-core
from keeper_secrets_manager_core import SecretsManager
from keeper_secrets_manager_core.storage import FileKeyValueStorage
# sys.stdin is not an array, it can not subscripted (ie sys.stdin[0])
for base64_params in sys.stdin:
params = json.loads(base64.b64decode(base64_params).decode())
print(f"providerRecordUid={params.get('providerRecordUid')}")
print(f"resourceRecordUid={params.get('resourceRecordUid')}")
print(f"userRecordUid={params.get('userRecordUid')}")
print(f"newPassword={params.get('newPassword')}")
print(f"oldPassword={params.get('oldPassword')}")
print(f"user={params.get('user')}")
records = json.loads(base64.b64decode(params.get('records')).decode())
print("Provider Title="
f"{next((x for x in records if x['uid'] == params.get('providerRecordUid')), None).get('title')}")
record_keys = ('providerRecordUid', 'resourceRecordUid', 'userRecordUid')
record_uids = [params.get(x) for x in record_keys if x in params]
ksm = SecretsManager(config=FileKeyValueStorage(r'/path/ksm-config.json'))
resource_records = ksm.get_secrets(record_uids)
for record in resource_records:
print(f"Record UID: {record.uid}, Title: {record.title}")
break
Last updated