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/stasis_main.c | |
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/stasis_main.c')
-rw-r--r-- | src/stasis_main.c | 32 |
1 files changed, 31 insertions, 1 deletions
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)) { |