Skip to main content

Password Safe API integration written in Python, Abstract complexity of managing secrets with the API.

Project description

Password Safe API integration

License

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 secrets-safe-library

Arguments

Retrieve Secrets

  • api_url:
    • description: BeyondTrust Password Safe API URL.
    • type: string
    • required: True
  • 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beyondtrust_bips_library-1.0.3.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

beyondtrust_bips_library-1.0.3-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file beyondtrust_bips_library-1.0.3.tar.gz.

File metadata

File hashes

Hashes for beyondtrust_bips_library-1.0.3.tar.gz
Algorithm Hash digest
SHA256 87f2696b1f4d7b022fdd77e9f91b741eeb8e796a7eba1ed01a1d2427ccb6327f
MD5 d2b424092c8be712345b1560c291bc43
BLAKE2b-256 bca5bce6c3d4d752cde47167cec075af64acd5c9ecb0b392f51b39dc32f5a8ee

See more details on using hashes here.

File details

Details for the file beyondtrust_bips_library-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for beyondtrust_bips_library-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70b5497ffcd4ebb826dfc94d232fc4aee8334d06d18230a1c657c248b8b1f3a1
MD5 03b04810b84083e31dd6e34af622aa02
BLAKE2b-256 110958036843262018e385db25657357863f249557ff568573861da7f0737192

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page