Skip to content

Commit b5499a6

Browse files
committed
Catch 403 with (un)stage and explain possible causes
Fixes #23
1 parent 777e280 commit b5499a6

1 file changed

Lines changed: 45 additions & 11 deletions

File tree

ada/ada

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,9 @@ pathtype () {
11001100
# REGULAR = file
11011101
# LINK = symbolic link
11021102
# <empty> = something went wrong... no permission?
1103+
local path="$1"
1104+
encoded_path=$(urlencode "$path")
11031105
local result
1104-
encoded_path=$(urlencode "$1")
11051106
command='$debug && set -x
11061107
curl "${curl_authorization[@]}" \
11071108
-H "accept: application/json" \
@@ -1491,16 +1492,49 @@ bulk_request() {
14911492
target=${target%?}]
14921493
data="{\"activity\": \"${activity}\", \"arguments\": ${arguments}, \"target\": ${target}, \"expand_directories\": \"${expand}\"}"
14931494
$debug || echo "$target "
1494-
(
1495-
$debug && set -x # If --debug is specified, show curl command
1496-
curl "${curl_authorization[@]}" \
1497-
"${curl_options_common[@]}" \
1498-
"${curl_options_post[@]}" \
1499-
-X POST "$api/bulk-requests" \
1500-
-d "${data}" \
1501-
--dump-header - \
1502-
| grep -e request-url -e Date | tee -a "${requests_log}"
1503-
)
1495+
# Elsewhere, we do 'set -x' in a subshell, but here we need to catch the return headers.
1496+
$debug && set -x # If --debug is specified, show curl command
1497+
response=$(curl "${curl_authorization[@]}" \
1498+
"${curl_options_common[@]}" \
1499+
"${curl_options_post[@]}" \
1500+
-X POST "$api/bulk-requests" \
1501+
-d "${data}" \
1502+
--write-out "\nHTTP_CODE_%{http_code}" \
1503+
--dump-header -
1504+
)
1505+
# Stop showing commands
1506+
$debug && set +x
1507+
# Process the result based on the HTTP return code
1508+
status=$(echo "$response" | grep '^HTTP_CODE_') # HTTP return code
1509+
$debug && echo 1>&2 "Returned HTTP status: $status"
1510+
# 403 could mean recursion is not allowed in dCache. Might become 422 in future.
1511+
# See also https://github.com/dCache/dcache/issues/7892
1512+
case $status in
1513+
HTTP_CODE_403 | HTTP_CODE_422 )
1514+
if $recursive ; then
1515+
echo -e 1>&2 "Operation failed. Possible causes:\n" \
1516+
"* You may not have permission to access the directory\n" \
1517+
"* Recursive staging may be prohibited.\n" \
1518+
"\nTry the same command without --recursive. If that works," \
1519+
"the dCache system does not allow you to stage recursively." \
1520+
"If you need recursion, ask your dCache admins to set" \
1521+
"'bulk.allowed-directory-expansion=ALL'."
1522+
else
1523+
echo -e 1>&2 "Operation failed. Possible causes:\n" \
1524+
"* You may not have permission to access the directory\n" \
1525+
"* Your authentication token may not permit staging."
1526+
fi
1527+
exit 1
1528+
;;
1529+
HTTP_CODE_2* )
1530+
echo "$response" | grep -e request-url -e Date | tee -a "${requests_log}"
1531+
# ToDo: explain to user what to do with the request-url, see issue #86
1532+
;;
1533+
* )
1534+
echo 1>&2 -e "ERROR: operation failed. See details below:\n\n$response"
1535+
exit 1
1536+
;;
1537+
esac
15041538
$debug && echo "Information about bulk request is logged in $requests_log."
15051539
{
15061540
echo "activity: $activity"

0 commit comments

Comments
 (0)