-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnd_br.sh
132 lines (116 loc) · 3.88 KB
/
nd_br.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
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
#!/bin/bash
##################################################################
#
# About This Script:
# nd_br: nidap branch: creates a branch on a dataset if it does not exist;
#
##################################################################
#
# NOTE: options and associated input, if any, may be passed
# in any order;
#
# Usage:
# sh nd_br.sh -r (-rid) "palantir_dataset_rid"
# -b (-branch_name) "myNewBranch"
# -u (-user_token) "user_token
# -d (-domain) "domain_url"
# [default:https://nidap.nih.gov]
# ............Creates branch o
#
# sh nd_br.sh -h (-help)
# ............displays function help;
#
##################################################################
#
# Returns:
# string: SUCCESS or FAILURE
#
##################################################################
strDefaultDomain="https://nidap.nih.gov"
# execute request
strArg=`echo "$1" | awk -va="$1" '{print tolower(a)}'`
if [ "$#" -gt 1 ] && [ "$strArg" != "-h" ] && [ "$strArg" != "-help" ] && [ "$strArg" != "-t" ] && [ "$strArg" != "-test" ]
then
strRID=""
strUserToken=""
strDomain=""
strBranchName=""
while [ $# -ne 0 ]
do
strArg=`echo "$1" | awk -va="$1" '{print tolower(a)}'`
if [ "$strArg" = "-r" ] || [ "$strArg" = "-rid" ]
then
shift
strRID="$1"
elif [ "$strArg" = "-b" ] || [ "$strArg" = "-branch_name" ]
then
shift
strBranchName="$1"
elif [ "$strArg" = "-u" ] || [ "$strArg" = "-user_token" ]
then
shift
strUserToken="$1"
elif [ "$strArg" = "-d" ] || [ "$strArg" = "-domain" ]
then
shift
strDomain="$1"
fi
shift
done
if [ "$strDomain" = "" ]
then
strDomain="$strDefaultDomain"
fi
if [ "$strRID" != "" ] && [ "$strUserToken" != "" ] && [ "$strBranchName" != "" ]
then
create_branch_response=$(curl --request POST $strDomain/foundry-catalog/api/catalog/datasets/$strRID/branchesUnrestricted2/$strBranchName \
-H "Authorization: Bearer $strUserToken" \
-H "Content-Type: application/json" \
-d '{}')
if [[ "$create_branch_response" == *"errorCode"* ]]
then
if [[ "$create_branch_response" == *"BranchesAlreadyExist"* ]]
then
echo "branch $strBranchName already exists"
echo "SUCCESS\n"
else
echo "ERROR in creating branch $create_branch_response"
echo "FAILURE"
fi
else
echo "SUCCESS"
fi
else
strError="FAILURE"
strError="$strError\nInvalid Input Set:"
strError="$strError\nPalantir RID:\t$strRID"
strError="$strError\nUser Token:\t$strUserToken"
strError="$strError\nBranch Name:\t$strBranchName"
strError="$strError\n$0\n"
echo "$strError"
fi
elif [ "$#" -eq 1 ] && [ "$strArg" = "-h" ] || [ "$strArg" = "-help" ]
then
echo '
#################################################################
About This Script:
nd_br: nidap branch: creates a branch on a dataset if it does not exist;
#################################################################
NOTE: options and associated input, if any, may be passed
in any order;
Usage:
sh nd_br.sh -r (-rid) "palantir_dataset_rid"
-b (-branch_name) "myNewBranch"
-u (-user_token) "user_token
-d (-domain) "domain_url"
[default:https://nidap.nih.gov]
............Creates branch o
sh nd_br.sh -h (-help)
............displays function help;
#################################################################
Returns:
string: SUCCESS or FAILURE
'
else
echo "FAILURE\nUnrecognized Input\nUsage: sh nd_br.sh -h\n$0"
fi