Skip to main content

A reusable FastAPI vault utility service for other projects to use hashicorp vault

Project description

# Vault Service

The **Vault Service** package provides a convenient interface for interacting with HashiCorp Vault. It offers various methods to manage secrets for different tenants and connectors. This package is designed for seamless integration into your applications.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Methods](#methods)
  - [store_secret](#store_secret)
  - [get_secret](#get_secret)
  - [update_secret](#update_secret)
  - [delete_secret](#delete_secret)
  - [get_all_secrets_for_tenant](#get_all_secrets_for_tenant)
  - [delete_all_secrets_for_tenant](#delete_all_secrets_for_tenant)
- [License](#license)

## Installation

You can install the Vault Service package using pip:

```bash
pip install vault-service

Usage

To use the Vault Service, you need to initialize the VaultController and then call the utility functions. Make sure to set the required environment variables for Vault connection:

export VAULT_ADDR='https://your-vault-address'
export VAULT_TOKEN='your-vault-token'
export BASE_PATH='your-base-path'

Methods

store_secret(tenant_id: str, secret_name: str, secret_data: SecretData)

Stores a new secret in HashiCorp Vault under the specified tenant and secret name.

Parameters:

  • tenant_id: The ID of the tenant.
  • secret_name: The name of the secret to store.
  • secret_data: An instance of SecretData, containing the secret information to be stored.

Sample Payload for secret_data:

{
  "auth_key": "<auth-key>",
  "database_credentials": {
    "host": "localhost",
    "port": 5432,
    "database": "my_database",
    "user": "my_user",
    "password": "my_password"
  },
  "redis_credentials": {
    "host": "localhost",
    "port": 6379,
    "password": "my_password"
  }
}

Returns: A message indicating the success or failure of the operation.


get_secret(tenant_id: str, secret_name: str)

Retrieves a secret from HashiCorp Vault for the specified tenant and secret name.

Parameters:

  • tenant_id: The ID of the tenant.
  • secret_name: The name of the secret to retrieve.

Returns: The retrieved secret data as a dictionary, or an error message if not found.


update_secret(tenant_id: str, secret_name: str, secret_data: SecretData)

Updates an existing secret in HashiCorp Vault for the specified tenant and secret name.

Parameters:

  • tenant_id: The ID of the tenant.
  • secret_name: The name of the secret to update.
  • secret_data: An instance of SecretData, containing the updated secret information.

Sample Payload for secret_data:

{
  "auth_key": "<new-auth-key>",
  "database_credentials": {
    "host": "localhost",
    "port": 5432,
    "database": "my_database",
    "user": "my_user",
    "password": "new_password"
  },
  "redis_credentials": {
    "host": "localhost",
    "port": 6379,
    "password": "new_password"
  }
}

Returns: A message indicating the success or failure of the operation.


delete_secret(tenant_id: str, secret_name: str)

Deletes a secret from HashiCorp Vault for the specified tenant and secret name.

Parameters:

  • tenant_id: The ID of the tenant.
  • secret_name: The name of the secret to delete.

Returns: A message indicating the success or failure of the deletion.


get_all_secrets_for_tenant(tenant_id: str)

Retrieves all secrets for a specific tenant from HashiCorp Vault.

Parameters:

  • tenant_id: The ID of the tenant.

Returns: A list of all secrets associated with the tenant.


delete_all_secrets_for_tenant(tenant_id: str)

Deletes all secrets associated with a specific tenant from HashiCorp Vault.

Parameters:

  • tenant_id: The ID of the tenant.

Returns: A message indicating the success or failure of the deletion.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

vault_service-0.3.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vault_service-0.3.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file vault_service-0.3.0.tar.gz.

File metadata

  • Download URL: vault_service-0.3.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for vault_service-0.3.0.tar.gz
Algorithm Hash digest
SHA256 56997394df84315e582e80ca6dde1d2cd1b8e80af4ec305a28f2181ad7730057
MD5 7af879704c96730eeaccb9618a636504
BLAKE2b-256 ed731671a92ddc06920b812308d9115cc20527ece2b9450f2786acf1ec3fc4c9

See more details on using hashes here.

File details

Details for the file vault_service-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: vault_service-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for vault_service-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98c4b73bcf7bcab6b1bb3a08f73b346100a56c8f93eb65c033456682733bbe1c
MD5 766ffdc70852c5141e85d68bff40175d
BLAKE2b-256 e730d291db8b4368be66698db73b965876897a06a552104cd5ec9609aa452159

See more details on using hashes here.

Supported by

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