Skip to content

Commit fbe14fb

Browse files
committed
allow to feed change key/secret/id-file
1 parent e422818 commit fbe14fb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

kurl.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ kurl_t *kurl_open(const char *url, kurl_opt_t *opt)
157157
if (strstr(url, "s3://") == url) {
158158
s3aux_t a;
159159
struct curl_slist *slist = 0;
160-
a = s3_parse(url, 0, 0, 0);
160+
a = s3_parse(url, (opt? opt->s3keyid : 0), (opt? opt->s3secretkey : 0), (opt? opt->s3key_fn : 0));
161+
if (a.url == 0 || a.date == 0 || a.auth == 0) {
162+
kurl_close(ku);
163+
return 0;
164+
}
161165
ku->hdr = curl_slist_append(ku->hdr, a.date);
162166
ku->hdr = curl_slist_append(ku->hdr, a.auth);
163167
curl_easy_setopt(ku->curl, CURLOPT_URL, a.url);
@@ -168,8 +172,6 @@ kurl_t *kurl_open(const char *url, kurl_opt_t *opt)
168172
curl_easy_setopt(ku->curl, CURLOPT_VERBOSE, 0L);
169173
curl_easy_setopt(ku->curl, CURLOPT_NOSIGNAL, 1L);
170174
curl_easy_setopt(ku->curl, CURLOPT_WRITEFUNCTION, write_cb);
171-
if (opt && opt->usrpwd)
172-
curl_easy_setopt(ku->curl, CURLOPT_USERPWD, opt->usrpwd);
173175
}
174176
ku->m_buf = KU_DEF_BUFLEN;
175177
if (!kurl_isfile(ku) && ku->m_buf < CURL_MAX_WRITE_SIZE * 2)
@@ -421,10 +423,10 @@ int main(int argc, char *argv[])
421423
// s3_parse("s3://lh3test/44X.bam.bai", 0, 0, 0); return 0;
422424

423425
memset(&opt, 0, sizeof(kurl_opt_t));
424-
while ((c = getopt(argc, argv, "c:l:u:")) >= 0) {
426+
while ((c = getopt(argc, argv, "c:l:a:")) >= 0) {
425427
if (c == 'c') start = strtol(optarg, &p, 0);
426428
else if (c == 'l') rest = strtol(optarg, &p, 0);
427-
else if (c == 'u') opt.usrpwd = optarg;
429+
else if (c == 'a') opt.s3key_fn = optarg;
428430
}
429431
if (optind == argc) {
430432
fprintf(stderr, "Usage: kurl [-c start] [-l length] <url>\n");

kurl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#define KURL_NULL 1
77
#define KURL_INV_WHENCE 2
88
#define KURL_SEEK_OUT 3
9-
#define KURL_NO_MEM 4
9+
#define KURL_NO_AUTH 4
1010

1111
struct kurl_t;
1212
typedef struct kurl_t kurl_t;
1313

1414
typedef struct {
15-
const char *usrpwd;
15+
const char *s3keyid;
16+
const char *s3secretkey;
17+
const char *s3key_fn;
1618
} kurl_opt_t;
1719

1820
#ifdef __cplusplus

0 commit comments

Comments
 (0)