Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the env var when the TES dependency exists #743

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading