Skip to content

Commit

Permalink
support for proxy, in cofiguration
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 13, 2024
1 parent 4e7a432 commit c0ce0ec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion COGNAC
Submodule COGNAC updated 4 files
+4 −28 cognac_gen.sh
+28 −2 lib.c
+2 −0 lib.h
+27 −1 main_tpl.c
30 changes: 28 additions & 2 deletions osc_sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5073,7 +5073,8 @@ int osc_load_region_from_conf(const char *profile, char **region)
return 0;
}

int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
static int osc_load_cert_from_conf_(const char *profile, char **cert, char **key,
char **proxy)
{
struct json_object *cert_obj, *key_obj, *js;
const char *cfg = cfg_path;
Expand Down Expand Up @@ -5106,9 +5107,22 @@ int osc_load_cert_from_conf(const char *profile, char **cert, char **key)
ret |= OSC_ENV_FREE_SSLKEY;
}

if (proxy) {
key_obj = json_object_object_get(js, "proxy");
if (key_obj) {
*key = osc_strdup(json_object_get_string(key_obj));
ret |= OSC_ENV_FREE_PROXY;
}
}

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);
}

/* Function that will write the data inside a variable */
static size_t write_data(void *data, size_t size, size_t nmemb, void *userp)
{
Expand Down Expand Up @@ -29929,7 +29943,12 @@ 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);
f = osc_load_cert_from_conf_(profile, &e->cert, &e->sslkey,
&e->proxy);
if (e->cert)
cert = e->cert;
if (e->sslkey)
sslkey = e->sslkey;
if (f < 0)
return -1;
e->flag |= f;
Expand Down Expand Up @@ -29979,6 +29998,8 @@ int osc_init_sdk_ext(struct osc_env *e, const char *profile, unsigned int flag,
curl_easy_setopt(e->c, CURLOPT_SSLCERT, cert);
if (sslkey)
curl_easy_setopt(e->c, CURLOPT_SSLKEY, sslkey);
if (e->proxy)
curl_easy_setopt(e->c, CURLOPT_PROXY, e->proxy);
curl_easy_setopt(e->c, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(e->c, CURLOPT_USERAGENT, user_agent);

Expand Down Expand Up @@ -30046,6 +30067,11 @@ void osc_deinit_sdk(struct osc_env *e)
if (e->flag & OSC_ENV_FREE_CERT) {
free(e->cert);
}

if (e->flag & OSC_ENV_FREE_PROXY) {
free(e->proxy);
}

if (e->flag & OSC_ENV_FREE_SSLKEY) {
free(e->sslkey);
}
Expand Down
2 changes: 2 additions & 0 deletions osc_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct osc_str {
#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_AK_SK (OSC_ENV_FREE_AK | OSC_ENV_FREE_SK)

Expand All @@ -96,6 +97,7 @@ struct osc_env {
char *region;
char *cert;
char *sslkey;
char *proxy;
int flag;
enum osc_auth_method auth_method;
struct curl_slist *headers;
Expand Down

0 comments on commit c0ce0ec

Please sign in to comment.