Skip to content

Commit

Permalink
profile test updates to use correct config options prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
AO-StreetArt committed Jul 19, 2018
1 parent 8b40d1d commit ab91bb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
15 changes: 5 additions & 10 deletions aossl/profile/include/tiered_app_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class TieredApplicationProfile: public SafeApplicationProfile{
kv->get_opt(key, buf);
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()) {
Expand All @@ -99,11 +98,10 @@ class TieredApplicationProfile: public SafeApplicationProfile{
} else {
if (d.IsObject()) {
const rapidjson::Value& token_val = d["data"]["data"][key.c_str()];
data.assign(token_val.GetString());
return_buf.val.assign(token_val.GetString());
config_record.push_back(std::string("Retrieved Record for key: ") \
+ key + std::string(" from Vault"));
}
return_buf.val.assign(data);
}
} else {
return_buf.success = false;
Expand All @@ -123,6 +121,9 @@ class TieredApplicationProfile: public SafeApplicationProfile{
get_vault_secret(kv, vault_key, buf);
if (buf.success) {
KeyValueStore::set_opt(key, buf.val);
} else {
config_record.push_back(std::string("Failed to retrieve Vault Secret: ") \
+ buf.err_msg);
}
}
}
Expand Down Expand Up @@ -641,15 +642,9 @@ class TieredApplicationProfile: public SafeApplicationProfile{
load_config_value(ApplicationProfile::get_cli(), element.first);
}
// Get secure opts
for (std::string secure_opt : secure_opt_keys) {
// Load Properties File values, if present
load_config_value(ApplicationProfile::get_props(), secure_opt);
for (auto& secure_opt : secure_opt_keys) {
// Load Vault Secret, if present
load_vault_secret(ApplicationProfile::get_vault(), secure_opt);
// Load environment variables, if present
load_environment_variable(secure_opt);
// Load Commandline Values, if present
load_config_value(ApplicationProfile::get_cli(), secure_opt);
}
}

Expand Down
19 changes: 10 additions & 9 deletions aossl/profile/profile_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ int main(int argc, char** argv) {

// Initialization logic tests
std::vector<std::string> cli_args;
cli_args.push_back(std::string("test=1"));
cli_args.push_back(std::string("vault=http://127.0.0.1:8200"));
cli_args.push_back(std::string("vault.authtype=BASIC"));
cli_args.push_back(std::string("vault.un=test"));
cli_args.push_back(std::string("vault.pw=test"));
cli_args.push_back(std::string("consul=http://127.0.0.1:8500"));
cli_args.push_back(std::string("props=test/test.properties"));
cli_args.push_back(std::string("test.prof.test=1"));
cli_args.push_back(std::string("test.prof.vault=http://127.0.0.1:8200"));
cli_args.push_back(std::string("test.prof.vault.authtype=BASIC"));
cli_args.push_back(std::string("test.prof.vault.un=test"));
cli_args.push_back(std::string("test.prof.vault.pw=test"));
cli_args.push_back(std::string("test.prof.consul=http://127.0.0.1:8500"));
cli_args.push_back(std::string("test.prof.props=test/test.properties"));
AOSSL::NetworkApplicationProfile startup_profile(cli_args, \
std::string("test"), std::string("prof"));
startup_profile.add_opt(akey, avalue);
Expand All @@ -155,11 +155,12 @@ int main(int argc, char** argv) {
startup_profile.add_opt(key3, val1);
startup_profile.add_opt(key4, val2);
startup_profile.add_secure_opt(secretKey);
startup_profile.load_config();
std::vector<std::string> init_test_log = startup_profile.get_config_record();
std::cout << "Startup Log" << std::endl;
for (auto& elt : startup_log) {
for (auto& elt : init_test_log) {
std::cout << elt << std::endl;
}
startup_profile.load_config();
// Make sure all the correct keys are still present
assert(startup_profile.opt_exist(secretKey));
assert(startup_profile.opt_exist(akey));
Expand Down

0 comments on commit ab91bb8

Please sign in to comment.