-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedl.sh
More file actions
executable file
·67 lines (59 loc) · 1.34 KB
/
edl.sh
File metadata and controls
executable file
·67 lines (59 loc) · 1.34 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
#!/bin/bash
help()
{
echo "Perform basic Earthdata Login user token operations"
echo
echo "Syntax: edl.sh [-u|c|r|d|h]"
echo "options:"
echo " u EDL Userid"
echo " c Create user token"
echo " r Read user tokens"
echo " d Delete user token"
echo " h Print this help"
echo
}
operation="None"
while getopts ":crd:u:h" option; do
case $option in
c)
operation="create"
;;
r)
operation="read"
;;
d)
operation="delete"
token=$OPTARG
;;
u)
userid=$OPTARG
;;
h)
help
exit;;
\?)
echo "Error: Invalid option"
exit;;
esac
done
if [ -z "$userid" ];
then
read -p "EDL Username: " userid
fi
read -sp "EDL Password for '$userid': " pwd; echo
s=$(echo -n "$userid:$pwd"|base64)
auth_hdr="Authorization: Basic $s"
base_url="https://uat.urs.earthdata.nasa.gov"
JQ=$(command -v jq)
if [ -z "$JQ" ]; then
JQ=cat
fi
if [ "$operation" = "create" ]; then
curl -s -X POST -H "$auth_hdr" "$base_url/api/users/token" | $JQ
elif [ "$operation" = "read" ]; then
curl -s -H "$auth_hdr" "$base_url/api/users/tokens" | $JQ
elif [ "$operation" = "delete" ]; then
curl -s -X POST -H "$auth_hdr" "$base_url/api/users/revoke_token?token=$token" | $JQ
else
echo "Error: No operation specified"
fi