-
Notifications
You must be signed in to change notification settings - Fork 38
/
minio_s3_cache.sh
47 lines (36 loc) · 1.14 KB
/
minio_s3_cache.sh
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
#!/usr/bin/env bash
MINIO=${MINIO:="https://minio.fabrique.social.gouv.fr/minio"}
BUCKET=${BUCKET:="gitlab-runner"}
function tokenS3() {
curl -Ss \
-H 'Content-Type: application/json' \
--data-binary '{"id":1,"jsonrpc":"2.0","params":{"username":"'${S3KEY}'","password":"'${S3SECRET}'"},"method":"Web.Login"}'\
${MINIO}'/webrpc' \
> json
cat json | sed "s/{.*\"token\":\"\([^\"]*\).*}/\1/g" > TOKEN_S3
}
function putS3() {
local file=$1
shift;
local path=$1
shift;
tokenS3
curl -Ss \
-w '\nEstablish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' \
-H 'Authorization: Bearer '$(cat TOKEN_S3) \
-H 'User-Agent: Mozilla/5.0 (I am cURL ^^)' \
-T ${file} \
-X PUT \
"$@" \
${MINIO}'/upload/'${BUCKET}'/'${CI_PROJECT_PATH}'/'${path}
}
function getS3() {
local path=$1
shift;
tokenS3
curl -Ss \
-w '\nEstablish Connection: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n' \
-H 'User-Agent: Mozilla/5.0 (I am cURL ^^)' \
"$@" \
${MINIO}'/download/'${BUCKET}'/'${CI_PROJECT_PATH}'/'${path}'?token='$(cat TOKEN_S3)
}