Skip to content

Commit

Permalink
Set the env var when the TES dependency exists (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
felicityzhao9 authored Dec 13, 2024
1 parent 3bfa209 commit 45ea91a
Showing 1 changed file with 55 additions and 40 deletions.
95 changes: 55 additions & 40 deletions recipe-runner/src/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,46 +590,6 @@ GglError runner(const RecipeRunnerArgs *args) {
GGL_LOGE("setenv failed: %d.", errno);
}

// TODO: Check if TES is dependency within the recipe
GglByteVec resp_vec = GGL_BYTE_VEC(resp_mem);
ret = ggl_byte_vec_append(&resp_vec, GGL_STR("http://localhost:"));
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to append http://localhost:");
return ret;
}
GglBuffer rest = ggl_byte_vec_remaining_capacity(resp_vec);

ret = ggipc_get_config_str(
conn,
GGL_BUF_LIST(GGL_STR("port")),
&GGL_STR("aws.greengrass.TokenExchangeService"),
&rest
);
if (ret != GGL_ERR_OK) {
GGL_LOGW("Failed to get port from config. errono: %d", ret);
} else {
// Only set the env var if port number is valid
resp_vec.buf.len += rest.len;
ret = ggl_byte_vec_append(
&resp_vec, GGL_STR("/2016-11-01/credentialprovider/\0")
);
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to append /2016-11-01/credentialprovider/");
return ret;
}

sys_ret = setenv(
"AWS_CONTAINER_CREDENTIALS_FULL_URI",
(char *) resp_vec.buf.data,
true
);
if (sys_ret != 0) {
GGL_LOGE(
"setenv AWS_CONTAINER_CREDENTIALS_FULL_URI failed: %d.", errno
);
}
}

sys_ret = setenv("GGC_VERSION", GGL_VERSION, true);
if (sys_ret != 0) {
GGL_LOGE("setenv failed: %d.", errno);
Expand Down Expand Up @@ -689,6 +649,61 @@ GglError runner(const RecipeRunnerArgs *args) {
return ret;
}

// Check if TES is the dependency within the recipe
GglObject *val;
if (ggl_map_get(recipe.map, GGL_STR("ComponentDependencies"), &val)) {
if (val->type != GGL_TYPE_MAP) {
return GGL_ERR_PARSE;
}
GglObject *inner_val;
GglMap inner_map = val->map;
if (ggl_map_get(
inner_map,
GGL_STR("aws.greengrass.TokenExchangeService"),
&inner_val
)) {
static uint8_t resp_mem2[PATH_MAX];
GglByteVec resp_vec = GGL_BYTE_VEC(resp_mem2);
ret = ggl_byte_vec_append(&resp_vec, GGL_STR("http://localhost:"));
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to append http://localhost:");
return ret;
}
GglBuffer rest = ggl_byte_vec_remaining_capacity(resp_vec);

ret = ggipc_get_config_str(
conn,
GGL_BUF_LIST(GGL_STR("port")),
&GGL_STR("aws.greengrass.TokenExchangeService"),
&rest
);
if (ret != GGL_ERR_OK) {
GGL_LOGW("Failed to get port from config. errono: %d", ret);
} else {
resp_vec.buf.len += rest.len;
ret = ggl_byte_vec_append(
&resp_vec, GGL_STR("/2016-11-01/credentialprovider/\0")
);
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to append /2016-11-01/credentialprovider/"
);
return ret;
}

sys_ret = setenv(
"AWS_CONTAINER_CREDENTIALS_FULL_URI",
(char *) resp_vec.buf.data,
true
);
if (sys_ret != 0) {
GGL_LOGE(
"setenv AWS_CONTAINER_CREDENTIALS_FULL_URI failed: %d.",
errno
);
}
}
}
}
int dir_fd;
ret = ggl_dir_open(root_path, O_PATH, false, &dir_fd);
if (ret != GGL_ERR_OK) {
Expand Down

0 comments on commit 45ea91a

Please sign in to comment.