Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
MalinAhlberg committed Dec 3, 2024
1 parent 1d73ae3 commit d690e54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/integration/tests/sda/60_api_admin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ done
# get the fileId of the new file
fileid="$(curl -k -L -H "Authorization: Bearer $token" -H "Content-Type: application/json" "http://api:8080/users/[email protected]/files" | jq -r '.[] | select(.inboxPath == "test_dummy.org/NC12878.bam.c4gh") | .fileID')"

output=$(s3cmd -c s3cfg ls s3://test_dummy.org/NC12878.bam.c4gh 2>/dev/null)
if [ -z "$output" ] ; then
echo "Uploaded file not in inbox"
exit 1
fi
# delete it
resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X DELETE "http://api:8080/file/[email protected]/$fileid")"
if [ "$resp" != "200" ]; then
Expand All @@ -47,6 +52,11 @@ if [ "$last_event" != "disabled" ]; then
echo "The file $fileid does not have the expected las event 'disabled', but $last_event."
fi

output=$(s3cmd -c s3cfg ls s3://test_dummy.org/NC12878.bam.c4gh 2>/dev/null)
if [ -n "$output" ] ; then
echo "Deleted file is still in inbox"
exit 1
fi

# Try to delete an unknown file
resp="$(curl -s -k -L -o /dev/null -w "%{http_code}\n" -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X DELETE "http://api:8080/file/[email protected]/badfileid")"
Expand Down
4 changes: 2 additions & 2 deletions sda/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ func deleteFile(c *gin.Context) {
}

submissionUser := c.Param("username")
log.Warn("submission user:", submissionUser)
log.Debug("submission user:", submissionUser)

fileID := c.Param("file")
fileID = strings.TrimPrefix(fileID, "/")
log.Warn("submission file:", fileID)
log.Debug("submission file:", fileID)
if fileID == "" {
c.AbortWithStatusJSON(http.StatusBadRequest, "file ID is required")
}
Expand Down
2 changes: 1 addition & 1 deletion sda/cmd/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Admin endpoints are only available to a set of whitelisted users specified in th
- `/file/:username/*fileid`
- accepts `DELETE` requests
- marks the file as `disabled` in the database, and deletes it from the inbox.
- The file is identfied by its id, returned by `users/:username/:files`
- The file is identified by its id, returned by `users/:username/:files`

- Response codes
- `200` Query execute ok.
Expand Down

0 comments on commit d690e54

Please sign in to comment.