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
Methods
- get_secrets(self, paths)
- Invoked for Managed Account or Secrets Safe secrets.
- Returns a list of secrets in the requested order.
- get_secret(self, path)
- Invoked for Managed Account or Secrets Safe secrets.
- Returns the requested secret.
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 retry_requests 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:
req = retry(session, retries=3, backoff_factor=0.2, status_to_retry=(400,408,500,502,503,504))
certificate, certificate_key = utils.prepare_certificate_info(CERTIFICATE, CERTIFICATE_KEY)
authentication_obj = authentication.Authentication(
req,
TIMEOUT_CONNECTION_SECONDS,
TIMEOUT_REQUEST_SECONDS,
"https://example.com:443/BeyondTrust/api/public/v3",
"<client_id>",
"<client_secret>",
certificate,
certificate_key,
True,
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-1.10.0.tar.gz.
File metadata
- Download URL: beyondtrust_bips_library-1.10.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcbd1b82c166c74571651e4ab321b7531c6de88cbef8355de856ef06fff0d84f
|
|
| MD5 |
bd960ebf51f28a0126df1120a483d0c7
|
|
| BLAKE2b-256 |
05d805187d1f651a29b85e0fec42ed28ed54a4dba834176247840f6f20be44f1
|
Provenance
The following attestation bundles were made for beyondtrust_bips_library-1.10.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-1.10.0.tar.gz -
Subject digest:
dcbd1b82c166c74571651e4ab321b7531c6de88cbef8355de856ef06fff0d84f - Sigstore transparency entry: 195607739
- Sigstore integration time:
-
Permalink:
BeyondTrust/ps-integration-library@02273b6b357b1cf8c9573c51b35f28b3fb068cad -
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@02273b6b357b1cf8c9573c51b35f28b3fb068cad -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file beyondtrust_bips_library-1.10.0-py3-none-any.whl.
File metadata
- Download URL: beyondtrust_bips_library-1.10.0-py3-none-any.whl
- Upload date:
- Size: 41.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5d5cc47db2d53acfff2cefc370a22c92af38421287669d376ef2fc99a1ce289
|
|
| MD5 |
b42b98aaac6c37e7640c14a48d31f796
|
|
| BLAKE2b-256 |
66082a1d198fac2a316945233c45754e6992c83ad78c1e2d050dfc5fa498bac9
|
Provenance
The following attestation bundles were made for beyondtrust_bips_library-1.10.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-1.10.0-py3-none-any.whl -
Subject digest:
a5d5cc47db2d53acfff2cefc370a22c92af38421287669d376ef2fc99a1ce289 - Sigstore transparency entry: 195607743
- Sigstore integration time:
-
Permalink:
BeyondTrust/ps-integration-library@02273b6b357b1cf8c9573c51b35f28b3fb068cad -
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@02273b6b357b1cf8c9573c51b35f28b3fb068cad -
Trigger Event:
workflow_dispatch
-
Statement type: