diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-02 11:05:54 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-07-02 11:06:30 -0400 |
commit | 2ca6d9d944a05ff9c31d133ca44a0cc9bc892030 (patch) | |
tree | 76d4d82a5bd3890cc12960ada94e0218d3a3b519 /src | |
parent | 48fbcc4e2a47319e8f53e0dc5104dcfcfe11cc2b (diff) | |
download | stasis-2ca6d9d944a05ff9c31d133ca44a0cc9bc892030.tar.gz |
Update README to mention template function availability
* Add EnvCtl structure
* Add runtime checks to avoid running all the way to the end only to be met with a configuration error.
* Rename GITHUB to GH
Diffstat (limited to 'src')
-rw-r--r-- | src/globals.c | 16 | ||||
-rw-r--r-- | src/stasis_main.c | 32 | ||||
-rw-r--r-- | src/template_func_proto.c | 2 |
3 files changed, 48 insertions, 2 deletions
diff --git a/src/globals.c b/src/globals.c index 297598f..18a32b5 100644 --- a/src/globals.c +++ b/src/globals.c @@ -36,6 +36,22 @@ struct STASIS_GLOBAL globals = { .enable_docker = true, .enable_artifactory = true, .enable_testing = true, + .envctl = { + {.flags = STASIS_ENVCTL_PASSTHRU, .name = {"TMPDIR", NULL}}, + {.flags = STASIS_ENVCTL_PASSTHRU, .name = {"STASIS_ROOT", NULL}}, + {.flags = STASIS_ENVCTL_PASSTHRU, .name = {"STASIS_SYSCONFDIR", NULL}}, + {.flags = STASIS_ENVCTL_PASSTHRU, .name = {"STASIS_CPU_COUNT", "CPU_COUNT", NULL}}, + {.flags = STASIS_ENVCTL_REQUIRED | STASIS_ENVCTL_REDACT, .name={"STASIS_GH_TOKEN", "GITHUB_TOKEN", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_ACCESS_TOKEN", NULL}}, + {.flags = STASIS_ENVCTL_PASSTHRU, .name = {"STASIS_JF_USER", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_PASSWORD", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_SSH_KEY_PATH", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_SSH_PASSPHRASE", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_CLIENT_CERT_CERT_PATH", NULL}}, + {.flags = STASIS_ENVCTL_REDACT, .name = {"STASIS_JF_CLIENT_CERT_KEY_PATH", NULL}}, + {.flags = STASIS_ENVCTL_REQUIRED, .name = {"STASIS_JF_REPO", NULL}}, + {.flags = 0, .name = {NULL}}, + } }; void globals_free() { diff --git a/src/stasis_main.c b/src/stasis_main.c index e25681f..ce49829 100644 --- a/src/stasis_main.c +++ b/src/stasis_main.c @@ -98,7 +98,32 @@ static void usage(char *progname) { } } +static const char *has_envctl_key_(size_t i) { + for (size_t x = 0; globals.envctl[i].name[x] != NULL; x++) { + const char *name = globals.envctl[i].name[x]; + const char *data = getenv(name); + if (data) { + return name; + } + } + return NULL; +} +static void check_system_env_requirements() { + msg(STASIS_MSG_L1, "Checking environment\n"); + for (size_t i = 0; globals.envctl[i].name[0] != NULL; i++) { + unsigned int flags = globals.envctl[i].flags; + const char *key = has_envctl_key_(i); + if ((flags & STASIS_ENVCTL_REQUIRED) && !(key && strlen(getenv(key)))) { + if (!strcmp(key, "STASIS_JF_REPO") && !globals.enable_artifactory) { + continue; + } + msg(STASIS_MSG_L2 | STASIS_MSG_ERROR, "Environment variable '%s' must be configured.\n", globals.envctl[i].name[0]); + exit(1); + } + + } +} static void check_system_requirements(struct Delivery *ctx) { const char *tools_required[] = { @@ -142,6 +167,11 @@ static void check_system_requirements(struct Delivery *ctx) { } } +static void check_requirements(struct Delivery *ctx) { + check_system_requirements(ctx); + check_system_env_requirements(); +} + int main(int argc, char *argv[]) { struct Delivery ctx; struct Process proc = { @@ -336,7 +366,7 @@ int main(int argc, char *argv[]) { msg(STASIS_MSG_ERROR | STASIS_MSG_L2, "Failed to initialize delivery context\n"); exit(1); } - check_system_requirements(&ctx); + check_requirements(&ctx); msg(STASIS_MSG_L2, "Configuring JFrog CLI\n"); if (delivery_init_artifactory(&ctx)) { diff --git a/src/template_func_proto.c b/src/template_func_proto.c index 8618a2e..140a5e0 100644 --- a/src/template_func_proto.c +++ b/src/template_func_proto.c @@ -4,7 +4,7 @@ int get_github_release_notes_tplfunc_entrypoint(void *frame, void *data_out) { int result; char **output = (char **) data_out; struct tplfunc_frame *f = (struct tplfunc_frame *) frame; - char *api_token = getenv("STASIS_GITHUB_TOKEN"); + char *api_token = getenv("STASIS_GH_TOKEN"); if (!api_token) { api_token = getenv("GITHUB_TOKEN"); } |