Skip to content

Commit

Permalink
fix proxy, and add endpoints from conf support
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
outscale-mgo committed Jun 14, 2024
1 parent c0ce0ec commit c92e2e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion COGNAC
Submodule COGNAC updated 2 files
+30 −6 lib.c
+2 −0 lib.h
36 changes: 30 additions & 6 deletions osc_sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5074,7 +5074,7 @@ int osc_load_region_from_conf(const char *profile, char **region)
}

static int osc_load_cert_from_conf_(const char *profile, char **cert, char **key,
char **proxy)
char **proxy, char **endpoint)
{
struct json_object *cert_obj, *key_obj, *js;
const char *cfg = cfg_path;
Expand Down Expand Up @@ -5110,17 +5110,30 @@ static int osc_load_cert_from_conf_(const char *profile, char **cert, char **key
if (proxy) {
key_obj = json_object_object_get(js, "proxy");
if (key_obj) {
*key = osc_strdup(json_object_get_string(key_obj));
*proxy = osc_strdup(json_object_get_string(key_obj));
ret |= OSC_ENV_FREE_PROXY;
}
}

if (endpoint) {
struct json_object *e = json_object_object_get(js, "endpoints");

if (e)
e = json_object_object_get(e, "api");
else
e = json_object_object_get(js, "endpoint");
if (e) {
*endpoint = osc_strdup(json_object_get_string(e));
ret |= OSC_ENV_FREE_ENDPOINT;
}
}

return 0;
}

int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
{
return osc_load_cert_from_conf_(profile, cert, key, NULL);
return osc_load_cert_from_conf_(profile, cert, key, NULL, NULL);
}

/* Function that will write the data inside a variable */
Expand Down Expand Up @@ -29884,6 +29897,8 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
e->region = getenv("OSC_REGION");
e->flag = flag;
e->auth_method = cfg ? cfg->auth_method : OSC_AKSK_METHOD;
e->proxy = NULL;
e->endpoint_allocated_ = NULL;
endpoint = getenv("OSC_ENDPOINT_API");
osc_init_str(&e->endpoint);

Expand Down Expand Up @@ -29944,7 +29959,7 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
if (!osc_load_region_from_conf(profile, &e->region))
e->flag |= OSC_ENV_FREE_REGION;
f = osc_load_cert_from_conf_(profile, &e->cert, &e->sslkey,
&e->proxy);
&e->proxy, &e->endpoint_allocated_);
if (e->cert)
cert = e->cert;
if (e->sslkey)
Expand All @@ -29957,12 +29972,17 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
if (!e->region)
e->region = "eu-west-2";

if (!endpoint) {
if (!endpoint && !e->endpoint_allocated_) {
osc_str_append_string(&e->endpoint, "https://api.");
osc_str_append_string(&e->endpoint, e->region);
osc_str_append_string(&e->endpoint, ".outscale.com");
} else {
osc_str_append_string(&e->endpoint, endpoint);
if (e->endpoint_allocated_) {
osc_str_append_string(&e->endpoint,
e->endpoint_allocated_);
} else {
osc_str_append_string(&e->endpoint, endpoint);
}
}

if (e->auth_method == OSC_AKSK_METHOD) {
Expand Down Expand Up @@ -30076,6 +30096,10 @@ void osc_deinit_sdk(struct osc_env *e)
free(e->sslkey);
}

if (e->flag & OSC_ENV_FREE_ENDPOINT) {
free(e->endpoint_allocated_);
}

e->c = NULL;
e->flag = 0;
}
2 changes: 2 additions & 0 deletions osc_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct osc_str {
#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 All @@ -98,6 +99,7 @@ struct osc_env {
char *cert;
char *sslkey;
char *proxy;
char *endpoint_allocated_;
int flag;
enum osc_auth_method auth_method;
struct curl_slist *headers;
Expand Down

0 comments on commit c92e2e6

Please sign in to comment.