secrets-safe-library


Namesecrets-safe-library JSON
Version 1.0 PyPI version JSON
download
home_pageNone
SummaryPassword Safe API integration written in Python, Abstract complexity of managing secrets with the API.
upload_time2024-08-27 21:10:24
maintainerNone
docs_urlNone
authorBeyondTrust Corporation
requires_python>=3.11
licenseMIT
keywords beyondtrust devops secrets secretssafe security
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Password Safe API integration
[![License](https://img.shields.io/badge/license-MIT%20-brightgreen.svg)](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

```sh
# 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`

```sh
pip install -r ~/requirements.txt
```

script example using library:
```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "secrets-safe-library",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "beyondtrust, devops, secrets, secretssafe, security",
    "author": "BeyondTrust Corporation",
    "author_email": "support@beyondtrust.com",
    "download_url": "https://files.pythonhosted.org/packages/bc/f0/6391963ef00f1d22a5c4db6a8e41fcfe65abbb08893c824871b3d4e65c15/secrets_safe_library-1.0.tar.gz",
    "platform": null,
    "description": "# Password Safe API integration\n[![License](https://img.shields.io/badge/license-MIT%20-brightgreen.svg)](LICENSE)\n\nPassword Safe API integration written in Python, Abstract complexity of managing secrets with the API\n\n## Python version compatibility\n  \nThis library is compatible with Python >= v3.11.\n\n## Install Package\n\n```sh\n# PyPI\npip install secrets-safe-library\n```\n## Arguments\n\n### Retrieve Secrets\n- api_url:\n    - description: BeyondTrust Password Safe API URL.\n    - type: string\n    - required: True\n- client_id:\n    - description: API OAuth Client ID.\n    - type: string\n    - required: True\n- client_secret:\n    - description: API OAuth Client Secret.\n    - type: string\n    - required: True\n- secret_list:\n    - description: List of secrets [\"path/title\",\"path/title\"] or managed accounts [\"ms/ma\",\"ms/ma\"] to be retrieved, separated by a comma.\n    - type: list\n    - required: True\n- certificate_path:\n    - description: Password Safe API pfx Certificate Path. For use when authenticating using a Client Certificate.\n    - type: string\n    - required: False\n- certificate_password:\n    - description: Password Safe API pfx Certificate Password. For use when authenticating using a Client Certificate.\n    - type: string\n    - required: False\n- verify_ca:\n    - description: Indicates whether to verify the certificate authority on the Secrets Safe instance.\n    - type: boolean \n    - default: True\n    - required: False\n\n## Methods\n- get_secrets(self, paths)\n\t- Invoked for Managed Account or Secrets Safe secrets.\n\t- Returns a list of secrets in the requested order.\n- get_secret(self, path)\n\t- Invoked for Managed Account or Secrets Safe secrets.\n\t- Returns the requested secret.\n\n## Example of usage\n\nWe strongly recommend you to use a virtual environment and install dependences from requirements.txt file.\n\nImport `secrets_safe_library`\n\n```sh\npip install -r ~/requirements.txt\n```\n\nscript example using library:\n```python\nimport  os\nimport  logging\nfrom  secrets_safe_library  import  secrets_safe, authentication, utils, managed_account\nimport requests\nfrom retry_requests import retry\n\nenv  =  os.environ\nLOGGER_NAME  =  \"custom_logger\"\n\nlogging.basicConfig(format  =  '%(asctime)-5s  %(name)-15s  %(levelname)-8s  %(message)s',\n\nlevel  =  logging.DEBUG)\n\n# logger object is optional but is strongly recommended\nlogger  =  logging.getLogger(LOGGER_NAME)\n\nTIMEOUT_CONNECTION_SECONDS = 30\nTIMEOUT_REQUEST_SECONDS = 30\n\nCERTIFICATE = env['CERTIFICATE']\nCERTIFICATE_KEY = env['CERTIFICATE_KEY']\n\ndef  main():\n    try:\n        with requests.Session() as session:\n            req = retry(session, retries=3, backoff_factor=0.2, status_to_retry=(400,408,500,502,503,504))\n            \n            certificate, certificate_key = utils.prepare_certificate_info(CERTIFICATE, CERTIFICATE_KEY)\n            \n            authentication_obj = authentication.Authentication(\n                req,\n                TIMEOUT_CONNECTION_SECONDS,\n                TIMEOUT_REQUEST_SECONDS,\n                \"https://example.com:443/BeyondTrust/api/public/v3\",\n                \"<client_id>\",\n                \"<client_secret>\",\n                certificate,\n                certificate_key,\n                True,\n                None)\n\n            # sign app in password safe API\n            get_api_access_response  =  authentication_obj.get_api_access()\n\n            if  get_api_access_response.status_code ==  200:\n                # instantiate secrets safe object\n                secrets_safe_obj  =  secrets_safe.SecretsSafe(authentication_obj, logger)\n\n                get_secrets_response  =  secrets_safe_obj.get_secrets([\"oagrp/text,oagrp/credential\"])\n                utils.print_log(logger, f\"=> Retrive secrets: {get_secrets_response}\", logging.DEBUG)\n            else:\n                print(f\"Please check credentials, error {get_api_access_response.text}\")\n            \n            authentication_obj.sign_app_out()\n\n    except  Exception  as  e:\n        utils.print_log(logger, f\"Error: {e}\", logging.ERROR)\n\n# calling main method\nmain()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Password Safe API integration written in Python, Abstract complexity of managing secrets with the API.",
    "version": "1.0",
    "project_urls": {
        "support": "https://www.beyondtrust.com/docs/index.htm#support"
    },
    "split_keywords": [
        "beyondtrust",
        " devops",
        " secrets",
        " secretssafe",
        " security"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cfcccefd9a85d08996cd802b29cb0881b2bbd4cce35479e0e286d0908efb786",
                "md5": "0b810854d636eeca9ccdc59134ba61d2",
                "sha256": "e588ebb9972a7a4da8d42c5e6cd50b8fb5ecc98e77f479e434d7d964508f54a8"
            },
            "downloads": -1,
            "filename": "secrets_safe_library-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b810854d636eeca9ccdc59134ba61d2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 14293,
            "upload_time": "2024-08-27T21:10:22",
            "upload_time_iso_8601": "2024-08-27T21:10:22.599501Z",
            "url": "https://files.pythonhosted.org/packages/4c/fc/ccefd9a85d08996cd802b29cb0881b2bbd4cce35479e0e286d0908efb786/secrets_safe_library-1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcf06391963ef00f1d22a5c4db6a8e41fcfe65abbb08893c824871b3d4e65c15",
                "md5": "a12419b1bd77201b63958c5a87784afa",
                "sha256": "7ca0a93caaa15b43938763612e3d014320a463e7bebe3ceeea10ebd97622a6d1"
            },
            "downloads": -1,
            "filename": "secrets_safe_library-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a12419b1bd77201b63958c5a87784afa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 11073,
            "upload_time": "2024-08-27T21:10:24",
            "upload_time_iso_8601": "2024-08-27T21:10:24.285235Z",
            "url": "https://files.pythonhosted.org/packages/bc/f0/6391963ef00f1d22a5c4db6a8e41fcfe65abbb08893c824871b3d4e65c15/secrets_safe_library-1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-27 21:10:24",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "secrets-safe-library"
}
        
Elapsed time: 1.31277s