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 | |
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
-rw-r--r-- | README.md | 39 | ||||
-rw-r--r-- | include/core.h | 10 | ||||
-rw-r--r-- | src/globals.c | 16 | ||||
-rw-r--r-- | src/stasis_main.c | 32 | ||||
-rw-r--r-- | src/template_func_proto.c | 2 |
5 files changed, 82 insertions, 17 deletions
@@ -143,21 +143,22 @@ stasis mydelivery.ini ## Environment variables -| Name | Purpose | -|-------------------------------------|-------------------------------------------------------| -| TMPDIR | Change default path to store temporary data | -| STASIS_ROOT | Change default path to write STASIS's data | -| STASIS_SYSCONFDIR | Change default path to search for configuration files | -| STASIS_CPU_COUNT (alias: CPU_COUNT) | Number of available CPUS | -| STASIS_JF_ARTIFACTORY_URL | Artifactory service URL (ending in `/artifactory`) | -| STASIS_JF_ACCESS_TOKEN | Artifactory Access Token | -| STASIS_JF_USER | Artifactory username | -| STASIS_JF_PASSWORD | Artifactory password | -| STASIS_JF_SSH_KEY_PATH | Path to SSH public key file | -| STASIS_JF_SSH_PASSPHRASE | Password associated with SSH public key file | -| STASIS_JF_CLIENT_CERT_CERT_PATH | Path to OpenSSL cert files | -| STASIS_JF_CLIENT_CERT_KEY_PATH | OpenSSL key file (in cert path) | -| STASIS_JF_REPO | Artifactory "generic" repository to write to | +| Name | Purpose | +|-------------------------------------------|-------------------------------------------------------------------------| +| TMPDIR | Change default path to store temporary data | +| STASIS_ROOT | Change default path to write STASIS's data | +| STASIS_SYSCONFDIR | Change default path to search for configuration files | +| STASIS_CPU_COUNT<br/>(alias: CPU_COUNT) | Number of available CPUs | +| STASIS_GH_TOKEN<br/>(alias: GITHUB_TOKEN) | GitHub API token<br/>(Scope: "Contents" repository permissions (write)) | +| STASIS_JF_ARTIFACTORY_URL | Artifactory service URL (ending in `/artifactory`) | +| STASIS_JF_ACCESS_TOKEN | Artifactory Access Token | +| STASIS_JF_USER | Artifactory username | +| STASIS_JF_PASSWORD | Artifactory password | +| STASIS_JF_SSH_KEY_PATH | Path to SSH public key file | +| STASIS_JF_SSH_PASSPHRASE | Password associated with SSH public key file | +| STASIS_JF_CLIENT_CERT_CERT_PATH | Path to OpenSSL cert files | +| STASIS_JF_CLIENT_CERT_KEY_PATH | OpenSSL key file (in cert path) | +| STASIS_JF_REPO | Artifactory "generic" repository to write to | # Variable expansion @@ -205,6 +206,14 @@ version = {{ env:MY_DYNAMIC_DELIVERY_VERSION }} python = {{ env:MY_DYNAMIC_PYTHON_VERSION }} ``` +## Template Functions + +Template functions can be accessed using the `{{ func:NAME(ARG,...) }}` notation. + +| Name | Purpose | +|-------------------------------|----------------------------------------------| +| get_github_release_notes_auto | Generate release notes for all test contexts | + # Delivery files ## Sections diff --git a/include/core.h b/include/core.h index cea7a16..d065096 100644 --- a/include/core.h +++ b/include/core.h @@ -59,6 +59,11 @@ } \ } while (0) +struct EnvCtl { + unsigned flags; + const char *name[10]; +}; + struct STASIS_GLOBAL { bool verbose; //!< Enable verbose output bool always_update_base_environment; //!< Update base environment immediately after activation @@ -88,8 +93,13 @@ struct STASIS_GLOBAL { char *repo; char *url; } jfrog; + struct EnvCtl envctl[]; }; extern struct STASIS_GLOBAL globals; + +#define STASIS_ENVCTL_PASSTHRU 0 << 1 +#define STASIS_ENVCTL_REQUIRED 1 << 1 +#define STASIS_ENVCTL_REDACT 2 << 1 extern const char *VERSION; extern const char *AUTHOR; extern const char *BANNER; 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"); } |