Skip to content

Commit

Permalink
support ssl_verify in config.json
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
outscale-mgo committed Dec 13, 2024
1 parent ee0e81a commit de0a053
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
40 changes: 40 additions & 0 deletions lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,45 @@ static char *osc_strdup(const char *str) {
} while (0)


int osc_set_extra_flag_from_conf(const char *profile, unsigned int *flag)
{
char buf[1024];
const char *cfg = cfg_path;
auto_osc_json_c struct json_object *to_free = NULL;
struct json_object *json_tmp, *js = NULL;

if (!cfg) {
LOAD_CFG_GET_HOME(buf);
cfg = buf;
}
TRY(access(cfg, R_OK), "can't open/read %s\n", cfg);
js = json_object_from_file(cfg);
TRY(!js, "can't load json-file %s (json might have incorect syntaxe)\n", cfg);
to_free = js;
js = json_object_object_get(js, profile);
TRY(!js, "can't find profile %s\n", profile);

json_tmp = json_object_object_get(js, "ssl_verify");
if (json_tmp) {
if (!json_object_get_boolean(json_tmp) ||
!json_object_get_int(json_tmp)) {
*flag = *flag | OSC_INSECURE_MODE;
} else {
*flag = *flag & (~OSC_INSECURE_MODE);
}
}
json_tmp = json_object_object_get(js, "verbose");
if (json_tmp) {
if (json_object_get_boolean(json_tmp) ||
json_object_get_int(json_tmp)) {
*flag = *flag | OSC_VERBOSE_MODE;
} else {
*flag = *flag & (~OSC_VERBOSE_MODE);
}
}
return 0;
}

int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk)
{
char buf[1024];
Expand Down Expand Up @@ -585,6 +624,7 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
if (f < 0)
return -1;
e->flag |= f;
osc_set_extra_flag_from_conf(profile, &flag);
}

if (!e->region)
Expand Down
19 changes: 10 additions & 9 deletions lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ struct osc_str {
char *buf;
};

#define OSC_ENV_FREE_AK 1 << 0
#define OSC_ENV_FREE_REGION 1 << 1
#define OSC_VERBOSE_MODE 1 << 2 /* curl verbose mode + print request content */
#define OSC_INSECURE_MODE 1 << 3 /* see --insecure option of curl */
#define OSC_ENV_FREE_CERT 1 << 4
#define OSC_ENV_FREE_SSLKEY 1 << 5
#define OSC_ENV_FREE_SK 1 << 6
#define OSC_ENV_FREE_PROXY 1 << 7
#define OSC_ENV_FREE_ENDPOINT 1 << 8
#define OSC_ENV_FREE_AK (1 << 0)
#define OSC_ENV_FREE_REGION (1 << 1)
#define OSC_VERBOSE_MODE (1 << 2) /* curl verbose mode + print request content */
#define OSC_INSECURE_MODE (1 << 3) /* see --insecure option of curl */
#define OSC_ENV_FREE_CERT (1 << 4)
#define OSC_ENV_FREE_SSLKEY (1 << 5)
#define OSC_ENV_FREE_SK (1 << 6)
#define OSC_ENV_FREE_PROXY (1 << 7)
#define OSC_ENV_FREE_ENDPOINT (1 << 8)

#define OSC_ENV_FREE_AK_SK (OSC_ENV_FREE_AK | OSC_ENV_FREE_SK)

Expand Down Expand Up @@ -134,6 +134,7 @@ struct osc_additional_strings {

____args____

int osc_set_extra_flag_from_conf(const char *profile, unsigned int *flag);
int osc_load_ak_sk_from_conf(const char *profile, char **ak, char **sk);
int osc_load_region_from_conf(const char *profile, char **region);
int osc_load_loging_password_from_conf(const char *profile,
Expand Down

0 comments on commit de0a053

Please sign in to comment.