Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to suppress the WARN thatpops when loading an identity as a file #756

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions library/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string.h>
#include <stdlib.h>
#include <utils.h>
#include <ctype.h>
#include "zt_internal.h"

const char* APP_ID = NULL;
Expand Down Expand Up @@ -46,16 +47,29 @@ static int load_config_file(const char *filename, ziti_config *cfg) {
return ZITI_OK;
}

int ziti_load_config(ziti_config *cfg, const char* cfgstr) {
int ziti_load_config(ziti_config *cfg, const char *cfgstr) {
if (!cfgstr) {
return ZITI_INVALID_CONFIG;
}
bool seems_like_json = false;
const char *c = cfgstr;
while (*c && isspace((unsigned char)*c)) {
c++;
}
if (*c == '{') {
seems_like_json = true;
}

memset(cfg, 0, sizeof(*cfg));
int rc = parse_ziti_config(cfg, cfgstr, strlen(cfgstr));
int rc;
if (seems_like_json) {
rc = parse_ziti_config(cfg, cfgstr, strlen(cfgstr));

if (rc < 0) {
ZITI_LOG(DEBUG, "trying to load config from file[%s]", cfgstr);
if (rc < 0) {
ZITI_LOG(DEBUG, "trying to load config from file[%s]", cfgstr);
rc = load_config_file(cfgstr, cfg);
}
} else {
rc = load_config_file(cfgstr, cfg);
}

Expand Down
Loading