-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsignedURL.sh
More file actions
executable file
·115 lines (103 loc) · 2.79 KB
/
signedURL.sh
File metadata and controls
executable file
·115 lines (103 loc) · 2.79 KB
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
#!/bin/bash
RED='\033[1;31m'
NC='\033[0m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
echo "Enter your UserName (Mandatory)"
read user
echo "Enter you api key (Mandatory)"
read pass
echo "Enter file name (Mandatory)"
read file
echo "Enter day to expiry (Default 1)"
read days
#echo "Enter repository name (Default: file_transfer)"
#read repo
echo "Enter package name (Default: temp)"
read package
echo "Enter version number (Default: 1.0)"
read version
declare -i time=$(date +%s%0000)
#if [ -z "$repo" ]
# then
declare repo=file_transfer
#fi
if [ -z "$package" ]
then
package=temp
fi
if [ -z "$version" ]
then
version=1.0
fi
echo ""
echo ""
echo -e ${BLUE}Checking if the $repo repository exists${NC}
echo ""
echo ""
defaultowner='jfrog-int'
temp1="$(curl -X GET -u$user:$pass "https://api.bintray.com/repos/jfrog-int/$repo" | python -c "import sys, json; print json.load(sys.stdin)['owner']")" #| jq -r '.owner')"
if [ "$temp1" = "$defaultowner" ]
then
echo ""
echo ""
echo -e ${GREEN}Repository already exists${NC}
echo ""
echo ""
else
echo -e ${BLUE}Creating the $repo generic repository${NC}
curl -X POST -u$user:$pass "https://api.bintray.com/repos/jfrog-int/$repo" -H "Content-Type:application/json" -d'{"name": "$repo","type": "generic","private": true}'
echo ""
echo ""
echo ""
fi
echo -e ${BLUE}Checking if the $package package exists${NC}
echo ""
echo ""
temp1="$(curl -X GET -u$user:$pass "https://api.bintray.com/packages/jfrog-int/$repo/$package" | python -c "import sys, json; print json.load(sys.stdin)['name']")" #| jq -r '.name')"
if [ "$temp1" = "$package" ]
then
echo ""
echo ""
echo -e ${GREEN}Package already exists${NC}
echo ""
echo ""
else
echo -e ${BLUE}Creating the $package package${NC}
echo ""
echo ""
curl -X POST -u$user:$pass "https://api.bintray.com/packages/jfrog-int/$repo" -H "Content-Type:application/json" --data-binary '{"name": "'$package'"}'
echo ""
echo ""
echo ""
fi
echo -e ${BLUE}Uploading $file${NC}
echo ""
echo ""
curl -T $file -u$user:$pass "https://api.bintray.com/content/jfrog-int/$repo/$package/$version/$file?publish=1"
echo ""
echo ""
echo ""
echo -e ${BLUE}waiting for publication${NC}
echo ""
echo ""
sleep 10
echo -e ${BLUE}Generating signed URL${NC}
echo ""
echo ""
if [ -z "$days" ]
then
echo -e ${BLUE}No expiry was given, setting to default of 24 hours${NC}
echo ""
echo ""
echo -e ${BLUE}Generating URL${GREEN}
curl -X POST -u$user:$pass "https://api.bintray.com/signed_url/jfrog-int/$repo/$file" -H "Content-Type:application/json"
echo ""
echo ""
echo ""
else
declare -i plus=$(($days * 86400000 ))
declare -i expiry=$((time + plus))
echo -e ${BLUE}Generating URL${GREEN}
curl -X POST -u$user:$pass "https://api.bintray.com/signed_url/jfrog-int/$repo/$file" -H "Content-Type:application/json" -d'{"expiry": '$expiry'}'
fi