Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions ada/ada
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ usage() {
--stat-request <request-id>
Show status of bulk request for given request-id

--delete-request <request-id>
Delete bulk request with given request-id

--events <channel-name> <path-to-follow> [--resume] [--force] [--recursive] [--timeout s]
Subscribe to changes in the given direcory,
using server-sent events (SSE).
Expand Down Expand Up @@ -301,7 +304,7 @@ set_defaults() {
# The ADA_VERSION value will be automatically updated by Github action Update-ada-version.yml
# For a release, it will contain the version number (like v3.1).
# For a branch, it will contain the branch name.
ADA_VERSION="master"
ADA_VERSION="110-delete-bulk-request"
args=
api=
debug=false
Expand Down Expand Up @@ -404,7 +407,7 @@ get_args() {
;;
--version )
echo "$ADA_VERSION"
exit 1
exit 0
;;
--tokenfile )
check_arg "tokenfile" $2
Expand Down Expand Up @@ -666,7 +669,13 @@ get_args() {
check_arg $command $2
request_id="$2"
shift ; shift
;;
;;
--delete-request )
command='delete-request'
check_arg $command $2
request_id="$2"
shift ; shift
;;
--events )
command='events'
check_arg $command $2
Expand Down Expand Up @@ -1518,13 +1527,33 @@ get_status_requestid () {
if [[ $valid == 'true' ]] ; then
echo "$result"
else
echo 1>&2 "Error: the request ID '$request_id' is not valid"
echo 1>&2 "ERROR: the request ID '$request_id' is not valid"
return 1
fi
fi
}


delete_requestid () {
local request_id="$1"
# check if request ID is valid, exit if invalid
get_status_requestid ${request_id} > /dev/null 2>&1
if [ $? == 1 ] ; then
echo 1>&2 "ERROR: cannot delete bulk request, request ID invalid"
exit 1
fi
command='$debug && set -x
curl "${curl_authorization[@]}" \
"${curl_options_common[@]}" \
-X DELETE "${api}"/bulk-requests/"${request_id}"'
if $dry_run ; then
echo "$command"
else
eval "$command"
fi
}


bulk_request() {
local activity="$1"
local pathlist="$2"
Expand Down Expand Up @@ -1555,7 +1584,7 @@ bulk_request() {
esac
else
if $recursive ; then
echo 1>&2 "Error: recursive (un)staging forbidden when using file-list."
echo 1>&2 "ERROR: recursive (un)staging forbidden when using file-list."
exit 1
else
expand=TARGETS
Expand All @@ -1571,7 +1600,7 @@ bulk_request() {
# check if request ID is valid, exit if invalid
get_status_requestid ${request_id} > /dev/null 2>&1
if [ $? == 1 ] ; then
echo 1>&2 "Error: cannot unstage, request ID invalid"
echo 1>&2 "ERROR: cannot unstage, request ID invalid"
exit 1
fi
arguments="{\"id\": \"${request_id}\"}"
Expand Down Expand Up @@ -1682,7 +1711,7 @@ with_files_in_dir_do () {
case $recursive in
true | false ) ;; # No problem
* )
echo 1>&2 "Error in with_files_in_dir_do: recursive='$recursive'; should be true or false."
echo 1>&2 "ERROR in with_files_in_dir_do: recursive='$recursive'; should be true or false."
exit 1
;;
esac
Expand Down Expand Up @@ -2375,7 +2404,7 @@ validate_input() {
exit 1
fi
;;
stat-request )
stat-request | delete-request)
if [[ -z $request_id || $request_id =~ ^-- ]] ; then
echo 1>&2 "ERROR: command $command requires a request-id."
exit 1
Expand Down Expand Up @@ -2883,6 +2912,9 @@ api_call () {
stat-request )
get_status_requestid "$request_id"
;;
delete-request )
delete_requestid "$request_id"
;;
events | report-staged )
if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
echo 1>&2 "ERROR: your bash version is too old: $BASH_VERSION." \
Expand Down
21 changes: 20 additions & 1 deletion tests/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Check if version is as expected
test_ada_version() {
result=`ada/ada --version`
assertEquals "Check ada version:" "v3.1" ${result}
assertEquals "ada returned error code" 0 $?
echo "Testing ada version ${result}"
}

# Check whoami
Expand Down Expand Up @@ -422,6 +423,24 @@ test_ada_request_id() {
uid=`cat "${stdoutF}" | jq -r '.uid'`
echo $uid
assertEquals ${uid} ${request_id}

# Test deleting of request id,
command="ada/ada --tokenfile ${token_file} --delete-request ${request_id} --api ${api}"
echo "Running command:"
echo $command
eval $command >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return

# Test if request has been deleted; request id should not exist anymore
command="ada/ada --tokenfile ${token_file} --stat-request ${request_id} --api ${api}"
echo "Running command:"
echo $command
eval $command >${stdoutF} 2>${stderrF}
result=$?
assertEquals "Request ID ${request_id} not deleted as expected" 1 ${result} || return
grep "ERROR" "${stderrF}" >/dev/null
assertTrue "ada --stat-request did not return ERROR message as expected" $?
}

# Stages files in file_list
Expand Down