Skip to content

Commit

Permalink
correct secrets path & add json parsing of vault secrets in tiered ap…
Browse files Browse the repository at this point in the history
…p profile
  • Loading branch information
AO-StreetArt committed Jun 23, 2018
1 parent ead3efe commit 10ca931
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
27 changes: 19 additions & 8 deletions aossl/profile/include/tiered_app_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,21 @@ class TieredApplicationProfile: public SafeApplicationProfile{
if (kv) {
AOSSL::StringBuffer buf;
kv->get_opt(key, buf);
if (buf.success) {
KeyValueStore::set_opt(key, buf.val);
if (buf.success && !(buf.val.empty())) {
// Parse out the data and compare it
std::string data;
rapidjson::Document d;
d.Parse<rapidjson::kParseStopWhenDoneFlag>(buf.val.c_str());
if (d.HasParseError()) {
throw std::invalid_argument(GetParseError_En(d.GetParseError()));
}
if (d.IsObject()) {
const rapidjson::Value& token_val = d["data"][key];
data.assign(token_val.GetString());
}
KeyValueStore::set_opt(key, data);
} else {
throw std::invalid_argument(buf.err_msg);
}
}
}
Expand Down Expand Up @@ -112,7 +125,7 @@ class TieredApplicationProfile: public SafeApplicationProfile{
if (kv->opt_exist(query_key)) {
AOSSL::StringBuffer buf;
kv->get_opt(query_key, buf);
if (!(buf.val.empty())) {
if (!(buf.val.empty()) && buf.success) {
// Parse the response
rapidjson::Document d;
d.Parse<rapidjson::kParseStopWhenDoneFlag>(buf.val.c_str());
Expand Down Expand Up @@ -140,8 +153,6 @@ class TieredApplicationProfile: public SafeApplicationProfile{
if (KeyValueStore::opt_exist(key)) {
KeyValueStore::set_opt(key, decoded_buffer.val);
}
} else {

}
}
}
Expand Down Expand Up @@ -172,7 +183,7 @@ class TieredApplicationProfile: public SafeApplicationProfile{
std::string vault_atype_key = "vault.authtype";
std::string vault_un_key = "vault.un";
std::string vault_pw_key = "vault.pw";
std::string secrets_path("/v1/secret");
std::string secrets_path("/v1/secret/");
int auth_type = BASIC_AUTH_TYPE;
StringBuffer vault_addr_buf;
StringBuffer vault_cert_buf;
Expand Down Expand Up @@ -267,7 +278,7 @@ class TieredApplicationProfile: public SafeApplicationProfile{
if (env_vault_addr && env_vault_cert && env_vault_authtype && env_vault_authun && env_vault_authpw) {
std::string vaddr(env_vault_addr);
std::string cert(env_vault_cert);
std::string secrets_path("/v1/secret");
std::string secrets_path("/v1/secret/");
std::string un(env_vault_authun);
std::string pw(env_vault_authpw);
std::string authtype_string(env_vault_authtype);
Expand All @@ -279,7 +290,7 @@ class TieredApplicationProfile: public SafeApplicationProfile{
} else if (env_vault_addr && env_vault_authtype && env_vault_authun && env_vault_authpw) {
std::string vaddr(env_vault_addr);
std::string cert(env_vault_cert);
std::string secrets_path("/v1/secret");
std::string secrets_path("/v1/secret/");
std::string un(env_vault_authun);
std::string pw(env_vault_authpw);
std::string authtype_string(env_vault_authtype);
Expand Down
11 changes: 8 additions & 3 deletions aossl/profile/profile_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(int argc, char** argv) {

// Vault tests
std::string vaddr("http://127.0.0.1:8200");
std::string secrets_path("/v1/secret");
std::string secrets_path("/v1/secret/");
std::string un("test");
std::string pw("test");
profile.set_vault_address(vaddr, secrets_path, 5, 1, un, pw);
Expand All @@ -116,6 +116,11 @@ int main(int argc, char** argv) {
profile.load_config();
AOSSL::StringBuffer buf7;
profile.get_opt(secretKey, buf7);
std::cout << buf7.val << std::endl;
assert(buf7.val == secretVal);
if (buf7.success) {
std::cout << buf7.val << std::endl;
assert(buf7.val == secretVal);
} else {
std::cout << buf7.err_msg << std::endl;
assert(false);
}
}

0 comments on commit 10ca931

Please sign in to comment.