From e58434bf9b9e056ce72822eb2acf579ccd0cf406 Mon Sep 17 00:00:00 2001 From: PortalMario <51074535+PortalMario@users.noreply.github.com> Date: Fri, 24 Oct 2025 15:25:54 +0200 Subject: [PATCH] Add cert with details listing --- .gitignore | 1 + openbaopy/bao.py | 30 +++++++++++++++++++++++++++++- pyproject.toml | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/openbaopy/bao.py b/openbaopy/bao.py index a3408b3..58b7351 100644 --- a/openbaopy/bao.py +++ b/openbaopy/bao.py @@ -4,6 +4,7 @@ import os import urllib.parse from dataclasses import dataclass +import requests import urllib3 import requests_unixsocket from hvac import Client @@ -87,11 +88,13 @@ def __init__(self, auth_params: BaoAuthParams): verify=self.__auth_params.verify ) - self.__bao_client.auth.approle.login( + self.__login_response = self.__bao_client.auth.approle.login( role_id=role_id, secret_id=secret_id ) + self.__bao_token = self.__bao_client.adapter.get_login_token(self.__login_response) + # Check for authentification if not self.__bao_client.is_authenticated(): raise hvac.exceptions.Unauthorized('Cloud not authenticate to bao server!') @@ -157,6 +160,31 @@ def revoke_certificate(self, serial_number: str, pki: str) -> dict: except Exception as ex: raise exceptions.UnexpectedError(f'Could not revoke certificate: {ex}') from ex + def list_certs_details(self, pki: str) -> dict: + """ + List all certs and thier details. + + Args: + pki (str): The CA/PKI mount which issued the certificate. + + Returns: + dict: Found certs and thier information. + + Raises: + exceptions.UnexpectedError: Error during certificate listing. + """ + + try: + certs = requests.get( + timeout=20, + url=f"https://{self.__auth_params.bao_address}:8200/v1/{pki}/certs/detailed", + headers={"X-Vault-Token": f"{self.__bao_token}"}, + params={"list": "true", "detailed": "true"}, verify=False).json() + + return certs + except Exception as ex: + raise exceptions.UnexpectedError(f'Could not list detailed certificates: {ex}') from ex + def get_secret(self, path: str, key: str, secrets_mount: str = 'secret') -> str: """ Retrieve secret value. diff --git a/pyproject.toml b/pyproject.toml index fa7a08f..bd2a2c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "openbaopy" -version = "1.0.2" +version = "1.1.0" description = "OpenBao client library" readme = "README.md" requires-python = ">=3.12"