Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
30 changes: 29 additions & 1 deletion openbaopy/bao.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import urllib.parse
from dataclasses import dataclass
import requests
import urllib3
import requests_unixsocket
from hvac import Client
Expand Down Expand Up @@ -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!')
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down