1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
//! @file artifactory.h
#ifndef STASIS_ARTIFACTORY_H
#define STASIS_ARTIFACTORY_H
#include <stdio.h>
#include <stdlib.h>
#include "core.h"
#include "download.h"
//! JFrog Artifactory Authentication struct
struct JFRT_Auth {
bool insecure_tls; //!< Disable TLS
char *access_token; //!< Generated access token
char *password; //!< Password
char *client_cert_key_path; //!< Path to where SSL key is stored
char *client_cert_path; //!< Path to where SSL cert is stored
char *ssh_key_path; //!< Path to SSH private key
char *ssh_passphrase; //!< Passphrase for SSH private key
char *user; //!< Account to authenticate as
char *server_id; //!< Artifactory server identification (unused)
char *url; //!< Artifactory server address
};
//! JFrog Artifactory Upload struct
struct JFRT_Upload {
bool quiet; //!< Enable quiet mode
char *project; //!< Destination project name
bool ant; //!< Enable Ant style regex
bool archive; //!< Generate a ZIP archive of the uploaded file(s)
char *build_name; //!< Build name
char *build_number; //!< Build number
bool deb; //!< Is Debian package?
bool detailed_summary; //!< Enable upload summary
bool dry_run; //!< Enable dry run (no-op)
char *exclusions; //!< Exclude patterns (separated by semicolons)
bool explode; //!< If uploaded file is an archive, extract it at the destination
bool fail_no_op; //!< Exit 2 when no file are affected
bool flat; //!< Upload with exact file system structure
bool include_dirs; //!< Enable to upload empty directories
char *module; //!< Build-info module name (optional)
bool recursive; //!< Upload files recursively
bool regexp; //!< Use regular expressions instead of wildcards
int retries; //!< Number of retries before giving up
int retry_wait_time; //!< Seconds between retries
char *spec; //!< Path to JSON upload spec
char *spec_vars;
bool symlinks; //!< Preserve symbolic links
bool sync_deletes; //!< Destination is replaced by uploaded files
char *target_props; //!< Properties (separated by semicolons)
int threads; //!< Thread count
bool workaround_parent_only; //!< Change directory to local parent directory before uploading files
};
struct JFRT_Download {
char *archive_entries;
char *build;
char *build_name;
char *build_number;
char *bundle;
bool detailed_summary;
bool dry_run;
char *exclude_artifacts;
char *exclude_props;
char *exclusions;
bool explode;
bool fail_no_op;
bool flat;
char *gpg_key;
char *include_deps;
char *include_dirs;
int limit;
int min_split;
char *module;
int offset;
char *project;
char *props;
bool quiet;
bool recursive;
int retries;
int retry_wait_time;
bool skip_checksum;
char *sort_by;
char *sort_order;
char *spec;
char *spec_vars;
int split_count;
bool sync_deletes;
int threads;
bool validate_symlinks;
};
struct JFRT_Search {
char *bundle;
bool count;
char *sort_by;
char *sort_order;
int limit;
int offset;
char *spec;
char *spec_vars;
char *props;
bool recursive;
char *build;
bool fail_no_op;
char *exclusions;
char *exclude_artifacts;
char *exclude_patterns;
char *exclude_props;
char *archive_entries;
char *include;
char *include_deps;
char *include_dirs;
char *project;
char *transitive;
};
/**
* Download the JFrog CLI tool from jfrog.com
* ```c
* if (artifactory_download_cli(".",
* "https://releases.jfrog.io/artifactory",
* "jfrog-cli",
* "v2-jf",
* "[RELEASE]",
* "Linux",
* "x86_64",
* "jf") {
* remove("./jf");
* fprintf(stderr, "Failed to download JFrog CLI\n");
* exit(1);
* }
*
* ```
*
* @param dest Directory path
* @param jfrog_artifactory_base_url jfrog.com base URL
* @param jfrog_artifactory_product jfrog.com project (jfrog-cli)
* @param cli_major_ver Version series (v1, v2-jf, vX-jf)
* @param version Version to download. "[RELEASE]" will download the latest version available
* @param os Operating system name
* @param arch System CPU architecture
* @param remote_filename File to download (jf)
* @return
*/
int artifactory_download_cli(char *dest,
char *jfrog_artifactory_base_url,
char *jfrog_artifactory_product,
char *cli_major_ver,
char *version,
char *os,
char *arch,
char *remote_filename);
/**
* JFrog CLI binding. Executes the "jf" tool with arguments.
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* if (jfrog_cli(&auth_ctx, "rt", "ping", NULL) {
* fprintf(stderr, "Failed to ping artifactory server: %s\n", auth_ctx.url);
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @param subsystem "jf" tool subsystem (i.e. "rt")
* @param task "jf" tool task "upload", "download", etc
* @param args Command line arguments to pass to "jf" tool
* @return exit code from "jf"
*/
int jfrog_cli(struct JFRT_Auth *auth, const char *subsystem, const char *task, char *args);
/**
* Issue an Artifactory server ping
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* if (jfrog_cli_ping(&auth_ctx)) {
* fprintf(stderr, "Failed to ping artifactory server: %s\n", auth_ctx.url);
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @return exit code from "jf"
*/
int jfrog_cli_rt_ping(struct JFRT_Auth *auth);
/**
* Upload files to an Artifactory repository
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* struct JFRT_Upload upload_ctx;
* jfrt_upload_init(&upload_ctx);
*
* if (jfrt_cli_rt_upload(&auth_ctx, &upload_ctx,
* "local/files_*.ext", "repo_name/ext_files/")) {
* fprintf(stderr, "Upload failed\n");
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @param ctx JFRT_Upload structure
* @param src local pattern to upload
* @param repo_path remote Artifactory destination path
* @return exit code from "jf"
*/
int jfrog_cli_rt_upload(struct JFRT_Auth *auth, struct JFRT_Upload *ctx, char *src, char *repo_path);
/**
* Download a file from an Artifactory repository
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* struct JFRT_Download download_ctx;
* memset(download_ctx, 0, sizeof(download_ctx));
*
* if (jfrt_cli_rt_download(&auth_ctx, &download_ctx,
* "repo_name/ext_files/", "local/files_*.ext")) {
* fprintf(stderr, "Upload failed\n");
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @param ctx JFRT_Download structure
* @param repo_path Remote repository w/ file pattern
* @param dest Local destination path
* @return exit code from "jf"
*/
int jfrog_cli_rt_download(struct JFRT_Auth *auth, struct JFRT_Download *ctx, char *repo_path, char *dest);
/**
* Search for files in an Artifactory repository
*
* @param auth JFRT_Auth structure
* @param ctx JFRT_Search structure
* @param repo_path Remote repository w/ file pattern
* @param dest Local destination path
* @return exit code from "jf"
*/
int jfrog_cli_rt_search(struct JFRT_Auth *auth, struct JFRT_Search *ctx, char *repo_path, char *pattern);
/**
* Collect runtime data for Artifactory build object.
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* if (jfrog_cli_rt_build_collect_env(&auth_ctx, "mybuildname", "1.2.3+gabcdef")) {
* fprintf(stderr, "Failed to collect runtime data for Artifactory build object\n");
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @param build_name Artifactory build name
* @param build_number Artifactory build number
* @return exit code from "jf"
*/
int jfrog_cli_rt_build_collect_env(struct JFRT_Auth *auth, char *build_name, char *build_number);
/**
* Publish build object to Artifactory server
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
*
* if (jfrog_cli_rt_build_collect_env(&auth_ctx, "mybuildname", "1.2.3+gabcdef")) {
* fprintf(stderr, "Failed to collect runtime data for Artifactory build object\n");
* exit(1);
* }
*
* if (jfrog_cli_rt_build_publish(&auth_ctx, "mybuildname", "1.2.3+gabcdef")) {
* fprintf(stderr, "Failed to publish Artifactory build object\n");
* exit(1);
* }
* ```
*
* @param auth JFRT_Auth structure
* @param build_name Artifactory build name
* @param build_number Artifactory build number
* @return exit code from "jf"
*/
int jfrog_cli_rt_build_publish(struct JFRT_Auth *auth, char *build_name, char *build_number);
/**
* Configure JFrog CLI authentication according to STASIS specs
*
* This function will use the STASIS_JF_* environment variables to configure the authentication
* context. With this in mind, if an STASIS_JF_* environment variable is not defined, the original value of
* the structure member will be used instead.
*
* Use STASIS_JF_* variables to configure context
*
* ```c
* struct JFRT_Auth auth_ctx;
* jfrt_auth_init(&ctx);
* ```
*
* Use your own input, but let the environment take over when variables are defined
*
* ```c
* struct JFRT_Auth auth_ctx;
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* jfrt_auth_init(&auth_ctx);
* ```
*
* Use your own input without STASIS's help. Purely an illustrative example.
*
* ```c
* struct JFRT_Auth auth_ctx;
* memset(auth_ctx, 0, sizeof(auth_ctx));
* auth_ctx.user = strdup("myuser");
* auth_ctx.password = strdup("mypassword");
* auth_ctx.url = strdup("https://myserver.tld/artifactory");
* ```
*
* @param auth_ctx
* @return
*/
int jfrt_auth_init(struct JFRT_Auth *auth_ctx);
/**
* Zero-out and apply likely defaults to a JFRT_Upload structure
* @param ctx JFRT_Upload structure
*/
void jfrt_upload_init(struct JFRT_Upload *ctx);
#endif //STASIS_ARTIFACTORY_H
|