Password Safe API integration written in Python, Abstract complexity of managing secrets with the API.
Project description
Password Safe API integration
Password Safe API integration written in Python, Abstract complexity of managing secrets with the API
Python version compatibility
This library is compatible with Python >= v3.11.
Install Package
# PyPI
pip install beyondtrust-bips-library
Arguments
Retrieve Secrets
- api_url:
- description: BeyondTrust Password Safe API URL.
- type: string
- required: True
- api_key:
- description: The API Key configured in BeyondInsight for your application. If not set, then client credentials must be provided.
- type: string
- required: False
- client_id:
- description: API OAuth Client ID.
- type: string
- required: True
- client_secret:
- description: API OAuth Client Secret.
- type: string
- required: True
- secret_list:
- description: List of secrets ["path/title","path/title"] or managed accounts ["ms/ma","ms/ma"] to be retrieved, separated by a comma.
- type: list
- required: True
- certificate_path:
- description: Password Safe API pfx Certificate Path. For use when authenticating using a Client Certificate.
- type: string
- required: False
- certificate_password:
- description: Password Safe API pfx Certificate Password. For use when authenticating using a Client Certificate.
- type: string
- required: False
- verify_ca:
- description: Indicates whether to verify the certificate authority on the Secrets Safe instance.
- type: boolean
- default: True
- required: False
Available Methods
Access Management
AccessLevels Class
get_access_levels()- List all available access levelspost_access_levels_usergroupid_smartruleid(usergroupid, smartruleid, accesslevelid)- Assign access level to user group and smart rule
AccessPolicy Class
test_access_policy(system_id, account_id, duration_minutes)- Test access policy configuration
Permission Class
get_usergroup_permissions(usergroup_id)- Get permissions for user groupset_usergroup_permissions(usergroup_id, permissions)- Set user group permissionsdelete_usergroup_permissions(usergroup_id)- Remove user group permissions
Asset & System Management
Asset Class
list_assets(workgroup_id, workgroup_name, limit, ...)- List assets with filteringget_asset_by_id(asset_id)- Get specific asset by IDget_asset_by_workgroup_name(workgroup_name, asset_name)- Find asset by workgroup and namelist_asset_attributes(asset_id)- List attributes for an assetsearch_assets(asset_name, dns_name, domain_name, ...)- Search assets by criteriacreate_asset()- Create new assetupdate_asset(asset_id)- Update existing assetdelete_asset_by_id(asset_id)- Delete asset by ID
ManagedSystem Class
get_managed_systems(limit, offset, type, name)- List managed systems with filteringget_managed_system_by_id(managed_system_id)- Get specific managed systemget_managed_system_by_asset_id(asset_id)- Get managed system by asset IDget_managed_system_by_database_id(database_id)- Get managed system by database IDpost_managed_system_by_asset_id(**kwargs)- Create managed system for assetpost_managed_system_by_database_id(**kwargs)- Create managed system for databasepost_managed_system_by_workgroup_id(**kwargs)- Create managed system for workgroupput_managed_system_by_id(managed_system_id, **kwargs)- Update managed systemdelete_managed_system_by_id(managed_system_id)- Delete managed system
Database Class
get_databases()- List all databasesget_database_by_id(database_id)- Get specific databaseget_databases_by_asset_id(asset_id)- Get databases for an assetpost_database_by_asset_id(asset_id, platform_id, port, ...)- Create database for assetput_database_by_id(database_id, **kwargs)- Update databasedelete_database_by_id(database_id)- Delete database
Secret Management
SecretsSafe Class
get_secret(path)- Get single secret by pathget_secret_with_metadata(path)- Get secret with metadata by pathget_secrets(paths)- Get multiple secrets by pathsget_secrets_with_metadata(paths)- Get multiple secrets with metadataget_all_secrets_by_folder_path(folder_path)- Get all secrets in a folderget_file_secret_data(secret_id)- Download file secret contentlist_secrets(**filters)- List secrets with optional filteringlist_secrets_by_folder_id(folder_id)- List secrets in specific foldercreate_secret(title, folder_id, **kwargs)- Create new secret (normal/text/file)update_secret(secret_id, **kwargs)- Update existing secretdelete_secret_by_id(secret_id)- Delete secret by IDget_secret_by_id(secret_id)- Get secret details by ID
Safe Class
create_safe(name, description)- Create new safe containerupdate_safe(safe_id, name, description)- Update safe informationget_by_id(safe_id)- Get safe by ID (inherited)delete_by_id(safe_id)- Delete safe by ID (inherited)list()- List all safes (inherited)
Folder Class
list_folders(folder_name, folder_path, include_subfolders, ...)- List folders with filteringcreate_folder(name, parent_id, description, ...)- Create new folder
Managed Account Operations
ManagedAccount Class
get_secret(path)- Get managed account credential by pathget_secret_with_metadata(path)- Get credential with metadataget_secrets(paths)- Get multiple credentials by pathsget_secrets_with_metadata(paths)- Get multiple credentials with metadatacreate_request(system_id, account_id)- Request access to managed accountget_credential_by_request_id(request_id)- Get account credentialsrequest_check_in(request_id, reason)- Release managed accountget_managed_accounts(**kwargs)- Search and filter managed accountslist_by_managed_system(managed_system_id)- List accounts by systemlist_by_smart_rule_id(smart_rule_id)- List accounts by smart rulelist_by_quick_rule_id(quick_rule_id)- List accounts by quick rulecreate_managed_account(**kwargs)- Create new managed accountassign_attribute(managed_account_id, attribute_id)- Assign attribute to accountdelete_attribute(managed_account_id, attribute_id)- Remove attribute from accountdelete_all_attributes(managed_account_id)- Remove all attributes from account
Credentials Class
get_credentials_by_request_id(request_id, type)- Get credentials for a requestget_credentials_by_alias_id(alias_id, request_id, type)- Get credentials by alias
User & Group Management
User Class
get_users(username, include_inactive)- List/search usersget_user_by_id(user_id)- Get specific user detailsget_users_by_usergroup_id(usergroup_id)- Get users in grouppost_user_beyondinsight(user_name, first_name, email_address, ...)- Create BeyondInsight userpost_user_active_directory(user_name, forest_name, domain_name, ...)- Create AD user integrationpost_user_ldap(host_name, distinguished_name, ...)- Create LDAP userpost_user_application(user_name, access_policy_id)- Create application userpost_user_quarantine(user_id)- Quarantine user accountput_user_beyondinsight(user_id, **kwargs)- Update BeyondInsight userput_user_application(user_id, **kwargs)- Update application userdelete_user(user_id)- Delete user account
Usergroups Class
get_usergroups()- List all user groupsget_usergroup_by_id(usergroup_id)- Get specific user groupget_usergroups_by_name(name)- Find user groups by namepost_usergroups_beyondinsight(group_name, description, is_active, ...)- Create BeyondInsight grouppost_usergroups_entraid(description, group_name, client_id, ...)- Create Entra ID grouppost_usergroups_ad(group_name, domain_name, description, ...)- Create AD grouppost_usergroups_ldap(group_name, group_distinguished_name, ...)- Create LDAP groupdelete_usergroup_by_name(name)- Delete user group
UserGroupRoles Class
get_roles(user_group_id, smart_rule_id)- Get roles for user group and smart ruleset_roles(user_group_id, smart_rule_id, roles, ...)- Set user group rolesdelete_roles(user_group_id, smart_rule_id)- Remove user group roles
Session Management
Session Class
get_sessions(status, user_id)- List active sessionspost_sessions_request_id(request_id, session_type, node_id)- Create session from requestpost_sessions_admin(session_type, host_name, user_name, ...)- Create admin session
SessionLocking Class
post_session_lock_sessionid(session_id)- Lock specific sessionpost_session_lock_managed_account_id(managed_account_id)- Lock sessions for accountpost_session_lock_managed_system_id(managed_system_id)- Lock sessions for system
SessionTermination Class
post_session_terminate_sessionid(session_id)- Terminate specific sessionpost_session_terminate_managedaccountid(managed_account_id)- Terminate account sessionspost_session_terminate_managedsystemid(managed_system_id)- Terminate system sessions
Keystroke Class
get_keystrokes_by_session_id(session_id)- Get keystrokes for sessionsearch_keystrokes(data, type)- Search keystroke data
Replay Class
create_replay_session(session_id, record_key, protocol, ...)- Create session replayget_replay_session(replay_id, jpeg_scale, png_scale, ...)- Get replay session datacontrol_replay_session(replay_id, speed, offset, ...)- Control replay playbackget_by_id(replay_id)- Get replay by ID (inherited)delete_by_id(replay_id)- Delete replay by ID (inherited)
Request Management
Request Class
get_requests(status, queue)- List requests with filteringpost_request(system_id, account_id, duration_minutes, ...)- Create access requestpost_request_alias(alias_id, duration_minutes, access_type, ...)- Create alias requestput_request_checkin(request_id, reason)- Check in active requestput_request_approve(request_id, reason)- Approve pending requestput_request_deny(request_id, reason)- Deny pending requestput_request_rotate_on_checkin(request_id)- Set password rotation on checkin
RequestSets Class
get_request_sets(status)- Get request sets by statuspost_request_sets(access_types, system_id, account_id, ...)- Create request set
RequestTermination Class
post_request_termination_managed_account_id(managed_account_id, reason)- Terminate account requestspost_request_termination_managed_system_id(managed_system_id, reason)- Terminate system requestspost_request_termination_user_id(userid, reason)- Terminate user requests
ISARequest Class
create_isa_request(system_id, account_id, duration_minutes, ...)- Create ISA access request
Rule Management
SmartRule Class
list_assets_by_smart_rule_id(smart_rule_id, limit, offset)- List assets in smart rulecreate_filter_asset_attribute(attribute_ids, title, category, ...)- Create attribute filter rulelist_smart_rules_by_user_group_id(user_group_id)- List smart rules for user grouprun_smart_rule(smart_rule_id, queue)- Execute smart rule
QuickRule Class
get_by_org_and_title(organization_id, title)- Get quick rule by organization and titledelete_by_org_and_title(organization_id, title)- Delete quick rulecreate_quick_rule(ids, title, category, ...)- Create new quick ruleadd_accounts_to_quick_rule(quick_rule_id, account_ids)- Add accounts to quick rule
System Configuration
Authentication Class
oauth()- Perform OAuth authenticationsign_app_in()- Sign into API with credentialsget_api_access()- Get API access tokensign_app_out()- Sign out of API sessionsend_post_sign_app_in()- Send sign-in POST requestvalidate_input(parameter_name, parameter_value)- Validate authentication parameters
CertUtil Class
get_certificate()- Get certificate dataget_certificate_key()- Get certificate private keyset_certificate_data_from_pfx_file(certificate_path, certificate_password)- Load certificate from PFX fileget_certificate_and_certificate_key(certificate_path, certificate_password)- Get both certificate and key
Platform Class
list_by_entity_type(entity_type_id)- List platforms by entity typelist()- List all platforms (inherited)get_by_id(platform_id)- Get platform by ID (inherited)
Attribute Management
AttributeType Class
create_attribute_type(name)- Create new attribute type
Attributes Class
get_attributes_by_attribute_type_id(attribute_type_id)- Get attributes by typepost_attribute_by_attribute_type_id(attribute_type_id, short_name, long_name, ...)- Create attributeget_attributes_by_managed_account_id(managed_account_id)- Get account attributesget_attributes_by_managed_system_id(managed_system_id)- Get system attributespost_attribute_by_managed_account_id(managed_account_id, attribute_id)- Assign attribute to accountpost_attribute_by_managed_system_id(managed_system_id, attribute_id)- Assign attribute to systemdelete_attributes_by_managed_account_id(managed_account_id)- Remove all account attributesdelete_attributes_by_managed_system_id(managed_system_id)- Remove all system attributes
Network & Infrastructure
AddressGroup Class
get_address_group_by_id(address_group_id)- Get address group by IDget_address_group_by_name(address_group_name)- Get address group by namecreate_address_group(name)- Create new address groupupdate_address_group(address_group_id, name)- Update address group
Aliases Class
get_aliases(state)- Get aliases by state (active/inactive)
Application Management
Application Class
get_managed_account_apps(account_id)- Get applications for managed accountassign_app_to_managed_account(account_id, application_id)- Assign application to accountremove_app_from_managed_account(account_id, application_id)- Remove application from accountunassign_all_apps_from_managed_account(account_id)- Remove all applications from account
APIRegistration Class
get_key_by_id(api_registration_id)- Get API key by registration IDrotate_api_key(api_registration_id)- Rotate API keycreate_api_registration(name, registration_type, access_token_duration, ...)- Create API registrationupdate_api_registration(registration_id, name, registration_type, ...)- Update API registration
Policy Management
EPMPolicies Class
add_epm_application()- Add EPM application policy
PropagationActions Class
get_managed_account_propagation_actions(managed_account_id)- Get propagation actions for accountpost_managed_account_propagation_action_by_id(managed_account_id, propagation_action_id, smart_rule_id)- Add propagation actiondelete_managed_account_propagation_action(managed_account_id)- Remove all propagation actionsdelete_managed_account_propagation_action_by_id(managed_account_id, propagation_action_id)- Remove specific action
Organization Management
Organization Class
get_organization_by_id(organization_id)- Get organization by IDlist_organizations()- List all organizationsget_organization_by_name(organization_name)- Find organization by name
Workgroup Class
get_workgroup_by_id(workgroup_id)- Get workgroup by IDget_workgroup_by_name(workgroup_name)- Get workgroup by nameget_workgroups()- List all workgroupspost_workgroup(name, organization_id)- Create new workgroup
Additional Services
FunctionalAccount Class
create_functional_account()- Create functional account for automation
Entitlement Class
list_entitlements(group_ids)- List entitlements for groups
SubscriptionDelivery Class
download(request_id)- Download subscription delivery content
Example of usage
We strongly recommend you to use a virtual environment and install dependences from requirements.txt file.
Import secrets_safe_library
pip install -r ~/requirements.txt
By default urllib3 logs are not shown, If need to show them:
export URLLIB3_PROPAGATE=True
script example using library:
import os
import logging
from secrets_safe_library import secrets_safe, authentication, utils, managed_account
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
env = os.environ
LOGGER_NAME = "custom_logger"
logging.basicConfig(format = '%(asctime)-5s %(name)-15s %(levelname)-8s %(message)s',
level = logging.DEBUG)
# logger object is optional but is strongly recommended
logger = logging.getLogger(LOGGER_NAME)
TIMEOUT_CONNECTION_SECONDS = 30
TIMEOUT_REQUEST_SECONDS = 30
CERTIFICATE = env['CERTIFICATE']
CERTIFICATE_KEY = env['CERTIFICATE_KEY']
def main():
try:
with requests.Session() as session:
retry_strategy = Retry(
total=3,
backoff_factor=0.2,
status_forcelist=[400, 408, 500, 502, 503, 504],
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("https://", adapter)
session.mount("http://", adapter)
certificate, certificate_key = utils.prepare_certificate_info(CERTIFICATE, CERTIFICATE_KEY)
authentication_obj = authentication.Authentication(
req=session,
timeout_connection=TIMEOUT_CONNECTION_SECONDS,
timeout_request=TIMEOUT_REQUEST_SECONDS,
api_url="https://example.com:443/BeyondTrust/api/public/v3",
client_id="<client_id>",
client_secret="<client_secret>",
certificate=certificate,
certificate_key=certificate_key,
verify_ca=True,
logger=None
)
# sign app in password safe API
get_api_access_response = authentication_obj.get_api_access()
if get_api_access_response.status_code == 200:
# instantiate secrets safe object
secrets_safe_obj = secrets_safe.SecretsSafe(authentication_obj, logger)
get_secrets_response = secrets_safe_obj.get_secrets(["oagrp/text,oagrp/credential"])
utils.print_log(logger, f"=> Retrive secrets: {get_secrets_response}", logging.DEBUG)
else:
print(f"Please check credentials, error {get_api_access_response.text}")
authentication_obj.sign_app_out()
except Exception as e:
utils.print_log(logger, f"Error: {e}", logging.ERROR)
# calling main method
main()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file beyondtrust_bips_library-2.1.0.tar.gz.
File metadata
- Download URL: beyondtrust_bips_library-2.1.0.tar.gz
- Upload date:
- Size: 79.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ebfe082998aa76ef1d450f172fe38d9a782b8fee8f0e5dda27f0bd2a7d611d
|
|
| MD5 |
bed036904b5a6c82f253676e7b6d519b
|
|
| BLAKE2b-256 |
ca56562376ee6a7b2f32b436d0b57117d2aea859a37414cb9f0ec78ecc5405f9
|
Provenance
The following attestation bundles were made for beyondtrust_bips_library-2.1.0.tar.gz:
Publisher:
release.yml on BeyondTrust/ps-integration-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
beyondtrust_bips_library-2.1.0.tar.gz -
Subject digest:
79ebfe082998aa76ef1d450f172fe38d9a782b8fee8f0e5dda27f0bd2a7d611d - Sigstore transparency entry: 805020424
- Sigstore integration time:
-
Permalink:
BeyondTrust/ps-integration-library@dcbca30a590ac0125907566a7033be1a3c8643ab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BeyondTrust
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dcbca30a590ac0125907566a7033be1a3c8643ab -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file beyondtrust_bips_library-2.1.0-py3-none-any.whl.
File metadata
- Download URL: beyondtrust_bips_library-2.1.0-py3-none-any.whl
- Upload date:
- Size: 140.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0267e8d387fc1d6a45151e2592d5972428e1fcdba1d0c8cc3aa028a729d21b44
|
|
| MD5 |
31b8e89a4c5dee3b556719c76aa1a69d
|
|
| BLAKE2b-256 |
536e10dc27315bc391cd7b9546322e4ede9ba648c857d9dc53d15997c8c10570
|
Provenance
The following attestation bundles were made for beyondtrust_bips_library-2.1.0-py3-none-any.whl:
Publisher:
release.yml on BeyondTrust/ps-integration-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
beyondtrust_bips_library-2.1.0-py3-none-any.whl -
Subject digest:
0267e8d387fc1d6a45151e2592d5972428e1fcdba1d0c8cc3aa028a729d21b44 - Sigstore transparency entry: 805020429
- Sigstore integration time:
-
Permalink:
BeyondTrust/ps-integration-library@dcbca30a590ac0125907566a7033be1a3c8643ab -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BeyondTrust
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dcbca30a590ac0125907566a7033be1a3c8643ab -
Trigger Event:
workflow_dispatch
-
Statement type: