Skip to content

Commit

Permalink
Merge pull request #756 from openziti/better-identity-detection
Browse files Browse the repository at this point in the history
attempt to suppress the WARN thatpops when loading an identity as a file
  • Loading branch information
ekoby authored Oct 17, 2024
2 parents 06d9006 + 5f0d16e commit 4539867
Showing 1 changed file with 18 additions and 4 deletions.
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

0 comments on commit 4539867

Please sign in to comment.