11#pragma once
2- #include < iostream>
32#include " ../../lib/json.hpp"
4- #include " libvault/VaultClient.h"
3+ #include " VaultClient.h"
4+ #include < iostream>
55
6- Vault::Client getRootClient (const Vault::Token &rootToken) {
6+ inline Vault::Client getRootClient (const Vault::Token &rootToken) {
77 Vault::TokenStrategy tokenStrategy{rootToken};
8- Vault::Config config = Vault::ConfigBuilder ().withDebug (false ).withTlsEnabled (false ).build ();
8+ Vault::Config config =
9+ Vault::ConfigBuilder ().withDebug (false ).withTlsEnabled (false ).build ();
910 Vault::HttpErrorCallback httpErrorCallback = [&](std::string err) {
1011 std::cout << err << std::endl;
1112 };
1213 Vault::ResponseErrorCallback responseCallback = [&](Vault::HttpResponse err) {
13- std::cout << err.statusCode << " : " << err.url .value () << " : " << err.body .value () << std::endl;
14+ std::cout << err.statusCode << " : " << err.url .value () << " : "
15+ << err.body .value () << std::endl;
1416 };
15- return Vault::Client{config, tokenStrategy, httpErrorCallback, responseCallback};
17+ return Vault::Client{config, tokenStrategy, httpErrorCallback,
18+ responseCallback};
1619}
1720
18- Vault::Client getAppRoleClient (const Vault::RoleId &roleId, const Vault::SecretId &secretId) {
19- Vault::AppRoleStrategy authStrategy{roleId, secretId};
21+ inline Vault::Client getAppRoleClient (const Vault::RoleId &roleId,
22+ const Vault::SecretId &secretId,
23+ const Vault::Path &mount) {
24+ Vault::AppRoleStrategy authStrategy{roleId, secretId, mount};
2025 Vault::Config config = Vault::ConfigBuilder ().withTlsEnabled (false ).build ();
2126
2227 return Vault::Client{config, authStrategy};
2328}
2429
25- Vault::Client getJwtClient (const Vault::RoleId &role, const Vault::Jwt &jwt) {
30+ inline Vault::Client getJwtClient (const Vault::RoleId &role,
31+ const Vault::Jwt &jwt) {
2632 Vault::JwtStrategy authStrategy{role, jwt};
27- Vault::Config config = Vault::ConfigBuilder ().withDebug (false ).withTlsEnabled (false ).build ();
33+ Vault::Config config =
34+ Vault::ConfigBuilder ().withDebug (false ).withTlsEnabled (false ).build ();
2835 Vault::HttpErrorCallback httpErrorCallback = [&](std::string err) {
2936 std::cout << err << std::endl;
3037 };
3138 Vault::ResponseErrorCallback responseCallback = [&](Vault::HttpResponse err) {
32- std::cout << err.statusCode << " : " << err.url .value () << " : " << err.body .value () << std::endl;
39+ std::cout << err.statusCode << " : " << err.url .value () << " : "
40+ << err.body .value () << std::endl;
3341 };
3442
35- return Vault::Client{config, authStrategy, httpErrorCallback, responseCallback};
43+ return Vault::Client{config, authStrategy, httpErrorCallback,
44+ responseCallback};
3645}
3746
38- std::optional<std::string> createPolicy (const Vault::Sys::Policy &policyAdmin) {
39- Vault::Parameters parameters{{
40- " policy" , " path \" secret/*\" {capabilities = [\" read\" , \" update\" , \" list\" , \" delete\" , \" create\" ]}"
41- }};
47+ inline std::optional<std::string>
48+ createPolicy (const Vault::Sys::Policy &policyAdmin) {
49+ Vault::Parameters parameters{
50+ {" policy" , " path \" secret/*\" {capabilities = [\" read\" , \" update\" , "
51+ " \" list\" , \" delete\" , \" create\" ]}" }};
4252 return policyAdmin.create (Vault::Path{" example" }, parameters);
4353}
4454
45- std::optional<std::string> deletePolicy (const Vault::Sys::Policy &policyAdmin) {
55+ inline std::optional<std::string>
56+ deletePolicy (const Vault::Sys::Policy &policyAdmin) {
4657 return policyAdmin.del (Vault::Path{" example" });
4758}
4859
49- std::optional<std::string> enableAppRole (const Vault::Sys::Auth &authAdmin) {
50- return authAdmin.enable (Vault::Path{" approle" }, Vault::Parameters{{" type" , " approle" }});
60+ inline std::optional<std::string>
61+ enableAppRole (const Vault::Sys::Auth &authAdmin, const Vault::Path &mount) {
62+ return authAdmin.enable (mount, Vault::Parameters{{" type" , " approle" }});
5163}
5264
53- std::optional<std::string> disableAppRole (const Vault::Sys::Auth &authAdmin) {
54- return authAdmin.disable (Vault::Path{" approle" });
65+ inline std::optional<std::string>
66+ disableAppRole (const Vault::Sys::Auth &authAdmin, const Vault::Path &mount) {
67+ return authAdmin.disable (mount);
5568}
5669
57- std::optional<std::string> createRole (const Vault::AppRole &appRoleAdmin) {
70+ inline std::optional<std::string>
71+ createRole (const Vault::AppRole &appRoleAdmin) {
5872 Vault::Parameters parameters{{" token_policies" , " example" }};
5973 return appRoleAdmin.create (Vault::Path{" example" }, parameters);
6074}
6175
62- std::optional<std::string> createRole (const Vault::JwtOidc &jwtAdmin) {
63- Vault::Parameters parameters{
64- {" role_type" , " jwt" },
65- {" user_claim" , " example" },
66- {" bound_audiences" , " example" },
67- {" policies" , " example" }
68- };
76+ inline std::optional<std::string> createRole (const Vault::JwtOidc &jwtAdmin) {
77+ Vault::Parameters parameters{{" role_type" , " jwt" },
78+ {" user_claim" , " example" },
79+ {" bound_audiences" , " example" },
80+ {" policies" , " example" }};
6981
7082 return jwtAdmin.createRole (Vault::Path{" example" }, parameters);
7183}
7284
73- std::optional<std::string> deleteRole (const Vault::AppRole &appRoleAdmin) {
85+ inline std::optional<std::string>
86+ deleteRole (const Vault::AppRole &appRoleAdmin) {
7487 return appRoleAdmin.del (Vault::Path{" example" });
7588}
7689
77- std::optional<std::string> deleteRole (const Vault::JwtOidc &jwtAdmin) {
90+ inline std::optional<std::string> deleteRole (const Vault::JwtOidc &jwtAdmin) {
7891 return jwtAdmin.deleteRole (Vault::Path{" example" });
7992}
8093
81- Vault::RoleId getRoleId (const Vault::AppRole &appRoleAdmin) {
94+ inline Vault::RoleId getRoleId (const Vault::AppRole &appRoleAdmin) {
8295 auto response = appRoleAdmin.getRoleId (Vault::Path{" example" });
8396 if (response) {
84- return Vault::RoleId{nlohmann::json::parse (response.value ())[" data" ][" role_id" ]};
97+ return Vault::RoleId{
98+ nlohmann::json::parse (response.value ())[" data" ][" role_id" ]};
8599 } else {
86100 std::cout << " Could not get role id" << std::endl;
87101 exit (-1 );
88102 }
89103}
90104
91- Vault::SecretId getSecretId (const Vault::AppRole &appRoleAdmin) {
92- auto response = appRoleAdmin.generateSecretId (Vault::Path{" example" }, Vault::Parameters{});
105+ inline Vault::SecretId getSecretId (const Vault::AppRole &appRoleAdmin) {
106+ auto response = appRoleAdmin.generateSecretId (Vault::Path{" example" },
107+ Vault::Parameters{});
93108 if (response) {
94- return Vault::SecretId{nlohmann::json::parse (response.value ())[" data" ][" secret_id" ]};
109+ return Vault::SecretId{
110+ nlohmann::json::parse (response.value ())[" data" ][" secret_id" ]};
95111 } else {
96112 std::cout << " Could not get role id" << std::endl;
97113 exit (-1 );
98114 }
99115}
100116
101- std::optional<std::string> enableKeyValue (const Vault::Sys::Mounts &mountAdmin) {
102- return mountAdmin.enable (Vault::Path{}, Vault::Parameters{}, Vault::Parameters{}, Vault::Parameters{});
117+ inline std::optional<std::string>
118+ enableKeyValue (const Vault::Sys::Mounts &mountAdmin) {
119+ return mountAdmin.enable (Vault::Path{}, Vault::Parameters{},
120+ Vault::Parameters{}, Vault::Parameters{});
103121}
104122
105- std::optional<std::string> disableKeyValue (const Vault::Sys::Mounts &mountAdmin) {
123+ inline std::optional<std::string>
124+ disableKeyValue (const Vault::Sys::Mounts &mountAdmin) {
106125 return mountAdmin.disable (Vault::Path{});
107126}
108127
109- std::optional<std::string> enableJwtAuthentication (const Vault::Sys::Auth &authAdmin) {
110- return authAdmin.enable (Vault::Path{" jwt" }, Vault::Parameters{{" type" , " jwt" }});
128+ inline std::optional<std::string>
129+ enableJwtAuthentication (const Vault::Sys::Auth &authAdmin) {
130+ return authAdmin.enable (Vault::Path{" jwt" },
131+ Vault::Parameters{{" type" , " jwt" }});
111132}
112133
113- std::optional<std::string> disableJwtAuthentication (const Vault::Sys::Auth &authAdmin) {
134+ inline std::optional<std::string>
135+ disableJwtAuthentication (const Vault::Sys::Auth &authAdmin) {
114136 return authAdmin.disable (Vault::Path{" jwt" });
115137}
116138
117- std::optional<std::string> configureJwtAuthentication (const Vault::JwtOidc &jwtAdmin, std::string publicKeyString) {
139+ inline std::optional<std::string>
140+ configureJwtAuthentication (const Vault::JwtOidc &jwtAdmin,
141+ std::string publicKeyString) {
118142 Vault::Parameters parameters{{" jwt_validation_pubkeys" , publicKeyString}};
119143 return jwtAdmin.configure (parameters);
120- }
144+ }
0 commit comments