From 4024f3a8dea63e8b193f045858efe1bffe265aec Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Mon, 25 May 2020 18:30:37 -0500 Subject: [PATCH] Complete Database implementation --- CMakeLists.txt | 2 +- README.md | 18 ++++++------ include/VaultClient.h | 13 +++++++++ src/engines/Database.cpp | 60 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d56e3b..1335375 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.9) -project(vault VERSION 0.15.0 DESCRIPTION "Vault library for C++") +project(vault VERSION 0.16.0 DESCRIPTION "Vault library for C++") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/README.md b/README.md index 8ec7152..98dfc2d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Total alerts ![LGTM Grade](https://img.shields.io/lgtm/grade/cpp/github/abedra/libvault) -[![Version](https://img.shields.io/badge/version-0.15.0-4a8fff)](https://img.shields.io/badge/version-0.15.0-4a8fff) +[![Version](https://img.shields.io/badge/version-0.16.0-4a8fff)](https://img.shields.io/badge/version-0.16.0-4a8fff) A C++ library for [Hashicorp Vault](https://www.vaultproject.io/) @@ -77,14 +77,14 @@ The following tables show support for each of the secret backends, auth methods, | RabbitMQ | Yes | Partial | | Transit | Yes | Partial | | PKI | Yes | Partial | -| PostgreSQL | Partial | Partial | -| Cassandra | Partial | No | -| Elasticsearch | Partial | No | -| Influxdb | Partial | No | -| HanaDB | Partial | No | -| MSSQL | Partial | No | -| MySQL/MariaDB | Partial | No | -| Oracle | Partial | No | +| PostgreSQL | Yes | Partial | +| Cassandra | Yes | No | +| Elasticsearch | Yes | No | +| Influxdb | Yes | No | +| HanaDB | Yes | No | +| MSSQL | Yes | No | +| MySQL/MariaDB | Yes | No | +| Oracle | Yes | No | | Active Directory | No | No | | Ali Cloud | No | No | | AWS | No | No | diff --git a/include/VaultClient.h b/include/VaultClient.h index 31a26af..1bc817f 100644 --- a/include/VaultClient.h +++ b/include/VaultClient.h @@ -506,9 +506,22 @@ namespace Vault { explicit Database(const Client &client) : client_(client) {} std::optional configureConnection(const Path &path, const Parameters ¶meters); + std::optional readConnection(const Path &path); + std::optional listConnections(); + std::optional deleteConnection(const Path &path); + std::optional resetConnection(const Path &path); + std::optional rotateRootCredentials(const Path &path); std::optional createRole(const Path &path, const Parameters ¶meters); + std::optional readRole(const Path &path); + std::optional listRoles(); std::optional deleteRole(const Path &path); std::optional generateCredentials(const Path &path); + std::optional createStaticRole(const Path &path, const Parameters ¶meters); + std::optional readStaticRole(const Path &path); + std::optional listStaticRoles(); + std::optional deleteStaticRole(const Path &path); + std::optional getStaticCredentials(const Path &path); + std::optional rotateStaticCredentials(const Path &path); private: Url getUrl(const Path &path); diff --git a/src/engines/Database.cpp b/src/engines/Database.cpp index 975b06c..1ea760c 100644 --- a/src/engines/Database.cpp +++ b/src/engines/Database.cpp @@ -4,18 +4,70 @@ std::optional Vault::Database::configureConnection(const Path &path return HttpConsumer::post(client_, getUrl(Vault::Path{"config/" + path}), parameters); } +std::optional Vault::Database::readConnection(const Path &path) { + return HttpConsumer::get(client_, getUrl(Path{"config/" + path})); +} + +std::optional Vault::Database::listConnections() { + return HttpConsumer::list(client_, getUrl(Path{"config"})); +} + +std::optional Vault::Database::deleteConnection(const Path &path) { + return HttpConsumer::del(client_, getUrl(Path{"config/" + path})); +} + +std::optional Vault::Database::resetConnection(const Path &path) { + return HttpConsumer::post(client_, getUrl(Path{"reset/" + path}), Parameters{}); +} + +std::optional Vault::Database::rotateRootCredentials(const Path &path) { + return HttpConsumer::post(client_, getUrl(Path{"rotate-root/" + path}), Parameters{}); +} + std::optional Vault::Database::createRole(const Path &path, const Parameters ¶meters) { - return HttpConsumer::post(client_, getUrl(Vault::Path{"roles/" + path}), parameters); + return HttpConsumer::post(client_, getUrl(Vault::Path{"roles/" + path}), parameters); +} + +std::optional Vault::Database::readRole(const Path &path) { + return HttpConsumer::get(client_, getUrl(Path{"roles/" + path})); +} + +std::optional Vault::Database::listRoles() { + return HttpConsumer::list(client_, getUrl(Path{"roles"})); } std::optional Vault::Database::deleteRole(const Path &path) { - return HttpConsumer::del(client_, getUrl(Vault::Path{"roles/" + path})); + return HttpConsumer::del(client_, getUrl(Vault::Path{"roles/" + path})); } std::optional Vault::Database::generateCredentials(const Path &path) { - return HttpConsumer::get(client_, getUrl(Vault::Path{"creds/" + path})); + return HttpConsumer::get(client_, getUrl(Vault::Path{"creds/" + path})); +} + +std::optional Vault::Database::createStaticRole(const Path &path, const Parameters ¶meters) { + return HttpConsumer::post(client_, getUrl(Path{"static-roles/" + path}), parameters); +} + +std::optional Vault::Database::readStaticRole(const Path &path) { + return HttpConsumer::get(client_, getUrl(Path{"static-roles/" + path})); +} + +std::optional Vault::Database::listStaticRoles() { + return HttpConsumer::list(client_, getUrl(Path{"static-roles"})); +} + +std::optional Vault::Database::deleteStaticRole(const Path &path) { + return HttpConsumer::del(client_, getUrl(Path{"static-roles/" + path})); +} + +std::optional Vault::Database::getStaticCredentials(const Path &path) { + return HttpConsumer::get(client_, getUrl(Path{"static-creds/" + path})); +} + +std::optional Vault::Database::rotateStaticCredentials(const Path &path) { + return HttpConsumer::post(client_, getUrl(Path{"rotate-role/" + path}), Parameters{}); } Vault::Url Vault::Database::getUrl(const Path &path) { - return client_.getUrl("/v1/database/", path); + return client_.getUrl("/v1/database/", path); }