diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-04 08:48:28 -0500 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-03-04 08:48:28 -0500 | 
| commit | 239330330a8fc49c6806cccdc17a910d23d22952 (patch) | |
| tree | 0e2a3e2e852cafd718556bb31ab58ffc0968504c /src | |
| parent | 39861d1872731119795f954acc0412af64cd539d (diff) | |
| download | stasis-239330330a8fc49c6806cccdc17a910d23d22952.tar.gz | |
Prototypes documentation
Includes minor changes:
* Rename jfrt_upload_set_defaults to jfrt_upload_init
* Move jfrt_auth_init to artifactory.c
* Adds missing error handling to git_describe and git_rev_parse
Diffstat (limited to 'src')
| -rw-r--r-- | src/artifactory.c | 55 | ||||
| -rw-r--r-- | src/deliverable.c | 55 | ||||
| -rw-r--r-- | src/utils.c | 56 | 
3 files changed, 74 insertions, 92 deletions
| diff --git a/src/artifactory.c b/src/artifactory.c index 55cb7dd..39a662d 100644 --- a/src/artifactory.c +++ b/src/artifactory.c @@ -115,7 +115,7 @@ void jfrt_register_opt_long(long jfrt_val, const char *opt_name, struct StrList      strlist_append(*opt_map, data);  } -void jfrt_upload_set_defaults(struct JFRT_Upload *ctx) { +void jfrt_upload_init(struct JFRT_Upload *ctx) {      memset(ctx, 0, sizeof(*ctx));      ctx->recursive = true;      ctx->threads = 3; @@ -135,6 +135,59 @@ static int auth_required(char *cmd) {      return 0;  } +int jfrt_auth_init(struct JFRT_Auth *auth_ctx) { +    char *url = getenv("OMC_JF_ARTIFACTORY_URL"); +    char *user = getenv("OMC_JF_USER"); +    char *access_token = getenv("OMC_JF_ACCESS_TOKEN"); +    char *password = getenv("OMC_JF_PASSWORD"); +    char *ssh_key_path = getenv("OMC_JF_SSH_KEY_PATH"); +    char *ssh_passphrase = getenv("OMC_JF_SSH_PASSPHRASE"); +    char *client_cert_key_path = getenv("OMC_JF_CLIENT_CERT_KEY_PATH"); +    char *client_cert_path = getenv("OMC_JF_CLIENT_CERT_PATH"); + +    if (!url) { +        fprintf(stderr, "Artifactory URL is not configured:\n"); +        fprintf(stderr, "please set OMC_JF_ARTIFACTORY_URL\n"); +        return -1; +    } +    auth_ctx->url = url; + +    if (access_token) { +        auth_ctx->user = NULL; +        auth_ctx->access_token = access_token; +        auth_ctx->password = NULL; +        auth_ctx->ssh_key_path = NULL; +    } else if (user && password) { +        auth_ctx->user = user; +        auth_ctx->password = password; +        auth_ctx->access_token = NULL; +        auth_ctx->ssh_key_path = NULL; +    } else if (ssh_key_path) { +        auth_ctx->user = NULL; +        auth_ctx->ssh_key_path = ssh_key_path; +        if (ssh_passphrase) { +            auth_ctx->ssh_passphrase = ssh_passphrase; +        } +        auth_ctx->password = NULL; +        auth_ctx->access_token = NULL; +    } else if (client_cert_key_path && client_cert_path) { +        auth_ctx->user = NULL; +        auth_ctx->password = NULL; +        auth_ctx->access_token = NULL; +        auth_ctx->ssh_key_path = NULL; +        auth_ctx->client_cert_key_path = client_cert_key_path; +        auth_ctx->client_cert_path = client_cert_path; +    } else { +        fprintf(stderr, "Artifactory authentication is not configured:\n"); +        fprintf(stderr, "set OMC_JF_USER and OMC_JF_PASSWORD\n"); +        fprintf(stderr, "or, set OMC_JF_ACCESS_TOKEN\n"); +        fprintf(stderr, "or, set OMC_JF_SSH_KEY_PATH and OMC_JF_SSH_KEY_PASSPHRASE\n"); +        fprintf(stderr, "or, set OMC_JF_CLIENT_CERT_KEY_PATH and OMC_JF_CLIENT_CERT_PATH\n"); +        return -1; +    } +    return 0; +} +  int jfrog_cli(struct JFRT_Auth *auth, char *args) {      struct Process proc;      char cmd[OMC_BUFSIZ]; diff --git a/src/deliverable.c b/src/deliverable.c index b935b64..f9c53ba 100644 --- a/src/deliverable.c +++ b/src/deliverable.c @@ -1433,59 +1433,6 @@ int delivery_init_artifactory(struct Delivery *ctx) {      return status;  } -int jfrt_auth_init(struct JFRT_Auth *auth_ctx) { -    char *url = getenv("OMC_JF_ARTIFACTORY_URL"); -    char *user = getenv("OMC_JF_USER"); -    char *access_token = getenv("OMC_JF_ACCESS_TOKEN"); -    char *password = getenv("OMC_JF_PASSWORD"); -    char *ssh_key_path = getenv("OMC_JF_SSH_KEY_PATH"); -    char *ssh_passphrase = getenv("OMC_JF_SSH_PASSPHRASE"); -    char *client_cert_key_path = getenv("OMC_JF_CLIENT_CERT_KEY_PATH"); -    char *client_cert_path = getenv("OMC_JF_CLIENT_CERT_PATH"); - -    if (!url) { -        fprintf(stderr, "Artifactory URL is not configured:\n"); -        fprintf(stderr, "please set OMC_JF_ARTIFACTORY_URL\n"); -        return -1; -    } -    auth_ctx->url = url; - -    if (access_token) { -        auth_ctx->user = NULL; -        auth_ctx->access_token = access_token; -        auth_ctx->password = NULL; -        auth_ctx->ssh_key_path = NULL; -    } else if (user && password) { -        auth_ctx->user = user; -        auth_ctx->password = password; -        auth_ctx->access_token = NULL; -        auth_ctx->ssh_key_path = NULL; -    } else if (ssh_key_path) { -        auth_ctx->user = NULL; -        auth_ctx->ssh_key_path = ssh_key_path; -        if (ssh_passphrase) { -            auth_ctx->ssh_passphrase = ssh_passphrase; -        } -        auth_ctx->password = NULL; -        auth_ctx->access_token = NULL; -    } else if (client_cert_key_path && client_cert_path) { -        auth_ctx->user = NULL; -        auth_ctx->password = NULL; -        auth_ctx->access_token = NULL; -        auth_ctx->ssh_key_path = NULL; -        auth_ctx->client_cert_key_path = client_cert_key_path; -        auth_ctx->client_cert_path = client_cert_path; -    } else { -        fprintf(stderr, "Artifactory authentication is not configured:\n"); -        fprintf(stderr, "set OMC_JF_USER and OMC_JF_PASSWORD\n"); -        fprintf(stderr, "or, set OMC_JF_ACCESS_TOKEN\n"); -        fprintf(stderr, "or, set OMC_JF_SSH_KEY_PATH and OMC_JF_SSH_KEY_PASSPHRASE\n"); -        fprintf(stderr, "or, set OMC_JF_CLIENT_CERT_KEY_PATH and OMC_JF_CLIENT_CERT_PATH\n"); -        return -1; -    } -    return 0; -} -  int delivery_artifact_upload(struct Delivery *ctx) {      int status = 0; @@ -1493,7 +1440,7 @@ int delivery_artifact_upload(struct Delivery *ctx) {          if (!ctx->deploy[i].files || !ctx->deploy[i].dest) {              break;          } -        jfrt_upload_set_defaults(&ctx->deploy[i].upload_ctx); +        jfrt_upload_init(&ctx->deploy[i].upload_ctx);          char *repo = getenv("OMC_JF_REPO");          if (repo) { diff --git a/src/utils.c b/src/utils.c index 2b4d275..b669e1c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -69,25 +69,6 @@ int rmtree(char *_path) {      return status;  } -/** - * Expand "~" to the user's home directory - * - * Example: - * ~~~{.c} - * char *home = expandpath("~");             // == /home/username - * char *config = expandpath("~/.config");   // == /home/username/.config - * char *nope = expandpath("/tmp/test");     // == /tmp/test - * char *nada = expandpath("/~/broken");     // == /~/broken - * - * free(home); - * free(config); - * free(nope); - * free(nada); - * ~~~ - * - * @param _path (Must start with a `~`) - * @return success=expanded path or original path, failure=NULL - */  char *expandpath(const char *_path) {      if (_path == NULL) {          return NULL; @@ -146,13 +127,6 @@ char *expandpath(const char *_path) {      return strdup(result);  } -/** - * Strip directory from file name - * Note: Caller is responsible for freeing memory - * - * @param _path - * @return success=file name, failure=NULL - */  char *path_basename(char *path) {      char *result = NULL;      char *last = NULL; @@ -168,12 +142,6 @@ char *path_basename(char *path) {      return result;  } -/** - * Return parent directory of file, or the parent of a directory - * - * @param path - * @return success=directory, failure=empty string - */  char *path_dirname(char *path) {      if (!path) {          return ""; @@ -374,11 +342,18 @@ int git_clone(struct Process *proc, char *url, char *destdir, char *gitref) {  char *git_describe(const char *path) { -    pushd(path);      static char version[NAME_MAX];      FILE *pp; -    pp = popen("git describe --first-parent --always --tags", "r"); +      memset(version, 0, sizeof(version)); +    if (pushd(path)) { +        return NULL; +    } + +    pp = popen("git describe --first-parent --always --tags", "r"); +    if (!pp) { +        return NULL; +    }      fgets(version, sizeof(version) - 1, pp);      strip(version);      pclose(pp); @@ -387,18 +362,25 @@ char *git_describe(const char *path) {  }  char *git_rev_parse(const char *path, char *args) { -    pushd(path);      static char version[NAME_MAX];      char cmd[PATH_MAX];      FILE *pp; +    memset(version, 0, sizeof(version));      if (isempty(args)) { -        fprintf(stderr, "git_rev_parse args cannot be empty"); +        fprintf(stderr, "git_rev_parse args cannot be empty\n"); +        return NULL; +    } + +    if (pushd(path)) {          return NULL;      } +      sprintf(cmd, "git rev-parse %s", args);      pp = popen(cmd, "r"); -    memset(version, 0, sizeof(version)); +    if (!pp) { +        return NULL; +    }      fgets(version, sizeof(version) - 1, pp);      strip(version);      pclose(pp); | 
