Skip to content

Commit fffb45a

Browse files
committed
Change config_set_blah() family of functions to call scitokens_config_set_blah()
To cut down on code duplication, the config_set_blah() family of APIs have been changed to immediately call the scitokens-prefixed family of APIs under the hood.
1 parent 37e2445 commit fffb45a

File tree

1 file changed

+4
-102
lines changed

1 file changed

+4
-102
lines changed

src/scitokens.cpp

Lines changed: 4 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -956,42 +956,7 @@ int keycache_set_jwks(const char *issuer, const char *jwks, char **err_msg) {
956956
}
957957

958958
int config_set_int(const char *key, int value, char **err_msg) {
959-
if (!key) {
960-
if (err_msg) {
961-
*err_msg = strdup("A key must be provided.");
962-
}
963-
return -1;
964-
}
965-
966-
std::string _key = key;
967-
if (_key == "keycache.update_interval_s") {
968-
if (value < 0) {
969-
if (err_msg) {
970-
*err_msg = strdup("Update interval must be positive.");
971-
}
972-
return -1;
973-
}
974-
configurer::Configuration::set_next_update_delta(value);
975-
return 0;
976-
}
977-
978-
else if (_key == "keycache.expiration_interval_s") {
979-
if (value < 0) {
980-
if (err_msg) {
981-
*err_msg = strdup("Expiry interval must be positive.");
982-
}
983-
return -1;
984-
}
985-
configurer::Configuration::set_expiry_delta(value);
986-
return 0;
987-
}
988-
989-
else {
990-
if (err_msg) {
991-
*err_msg = strdup("Key not recognized.");
992-
}
993-
return -1;
994-
}
959+
return scitokens_config_set_int(key, value, err_msg);
995960
}
996961

997962
int scitokens_config_set_int(const char *key, int value, char **err_msg) {
@@ -1034,28 +999,7 @@ int scitokens_config_set_int(const char *key, int value, char **err_msg) {
1034999
}
10351000

10361001
int config_get_int(const char *key, char **err_msg) {
1037-
if (!key) {
1038-
if (err_msg) {
1039-
*err_msg = strdup("A key must be provided.");
1040-
}
1041-
return -1;
1042-
}
1043-
1044-
std::string _key = key;
1045-
if (_key == "keycache.update_interval_s") {
1046-
return configurer::Configuration::get_next_update_delta();
1047-
}
1048-
1049-
else if (_key == "keycache.expiration_interval_s") {
1050-
return configurer::Configuration::get_expiry_delta();
1051-
}
1052-
1053-
else {
1054-
if (err_msg) {
1055-
*err_msg = strdup("Key not recognized.");
1056-
}
1057-
return -1;
1058-
}
1002+
return scitokens_config_get_int(key, err_msg);
10591003
}
10601004

10611005
int scitokens_config_get_int(const char *key, char **err_msg) {
@@ -1084,31 +1028,7 @@ int scitokens_config_get_int(const char *key, char **err_msg) {
10841028
}
10851029

10861030
int config_set_str(const char *key, const char *value, char **err_msg) {
1087-
if (!key) {
1088-
if (err_msg) {
1089-
*err_msg = strdup("A key must be provided.");
1090-
}
1091-
return -1;
1092-
}
1093-
1094-
std::string _key = key;
1095-
if (_key == "keycache.cache_home") {
1096-
auto rp = configurer::Configuration::set_cache_home(value);
1097-
if (!rp.first) { // There was an error, pass rp.second to err_msg
1098-
if (err_msg) {
1099-
*err_msg = strdup(rp.second.c_str());
1100-
}
1101-
return -1;
1102-
}
1103-
}
1104-
1105-
else {
1106-
if (err_msg) {
1107-
*err_msg = strdup("Key not recognized.");
1108-
}
1109-
return -1;
1110-
}
1111-
return 0;
1031+
return scitokens_config_set_str(key, value, err_msg);
11121032
}
11131033

11141034
int scitokens_config_set_str(const char *key, const char *value,
@@ -1141,25 +1061,7 @@ int scitokens_config_set_str(const char *key, const char *value,
11411061
}
11421062

11431063
int config_get_str(const char *key, char **output, char **err_msg) {
1144-
if (!key) {
1145-
if (err_msg) {
1146-
*err_msg = strdup("A key must be provided.");
1147-
}
1148-
return -1;
1149-
}
1150-
1151-
std::string _key = key;
1152-
if (_key == "keycache.cache_home") {
1153-
*output = strdup(configurer::Configuration::get_cache_home().c_str());
1154-
}
1155-
1156-
else {
1157-
if (err_msg) {
1158-
*err_msg = strdup("Key not recognized.");
1159-
}
1160-
return -1;
1161-
}
1162-
return 0;
1064+
return scitokens_config_get_str(key, output, err_msg);
11631065
}
11641066

11651067
int scitokens_config_get_str(const char *key, char **output, char **err_msg) {

0 commit comments

Comments
 (0)