Improve error message of the Schedule Deletion of Review App Environments API
Summary
I'm not able to schedule deletion of review app environments using the API.
curl \
--fail-with-body \
--request DELETE \
--header "private-token:${GITLAB_API_TOKEN}" \
--url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments/review_apps" | jq
curl: (22) The requested URL returned error: 400
{
"message": {
"scheduled_entries": [],
"unprocessable_entries": [],
"message": "Failed to authorize deletions for some or all of the environments. Ask someone with more permissions to delete the environments."
}
}
Proposal
See #364639 (comment 1109829913) for the details.
diff --git a/app/services/environments/schedule_to_delete_review_apps_service.rb b/app/services/environments/schedule_to_delete_review_apps_service.rb
index b3b86689748..21aa0c4f27d 100644
--- a/app/services/environments/schedule_to_delete_review_apps_service.rb
+++ b/app/services/environments/schedule_to_delete_review_apps_service.rb
@@ -58,7 +58,7 @@ def unsafe_mark_deletable_environments
else
result.set_status(
:bad_request,
- error_message: "Failed to authorize deletions for some or all of the environments. Ask someone with more permissions to delete the environments."
+ error_message: "No environments found for scheduled deletion. Either your query did not match any environments or you have insufficient permissions to delete matching environments."
)
result.set_unprocessable_entries(failed)
Steps to reproduce
-
Create or use an existing project on which you are maintainer/owner.
Set as variable:
PROJECT_ID=...
-
Create a personal access token scoped on API: https://gitlab.com/-/profile/personal_access_tokens.
Set as variable:
GITLAB_API_TOKEN=...
-
Create an environment named
review/testing
:Request:
curl \ --fail-with-body \ --request POST \ --header "private-token:${GITLAB_API_TOKEN}" \ --data "name=review/testing" \ --url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments" | jq
Response:
{ "id": 10727948, "name": "review/testing", "slug": "review-testing-gzd91k", "external_url": null, "created_at": "2022-06-08T10:08:04.887Z", "updated_at": "2022-06-08T10:08:04.887Z", "tier": "development", "project": {...}, "state": "available", "enable_advanced_logs_querying": false, ... }
-
Stop the environment:
Request:
ENVIRONMENT_ID=$(curl \ --fail-with-body \ --request GET \ --header "private-token:${GITLAB_API_TOKEN}" \ --url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments?name=review%2Ftesting" | jq -er '.[0].id') curl \ --fail-with-body \ --request POST \ --header "private-token:${GITLAB_API_TOKEN}" \ --url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments/${ENVIRONMENT_ID}/stop" | jq
Response:
{ "id": 10727948, "name": "review/testing", "slug": "review-testing-gzd91k", "external_url": null, "created_at": "2022-06-08T10:08:04.887Z", "updated_at": "2022-06-08T10:13:24.767Z", "tier": "development", "project": { ... }, "state": "stopped", "enable_advanced_logs_querying": false, ... }
-
Try to schedule environments for deletion
Request:
curl \ --fail-with-body \ --request DELETE \ --header "private-token:${GITLAB_API_TOKEN}" \ --url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments/review_apps" | jq
What is the current bug behavior?
Response:
curl: (22) The requested URL returned error: 400
{
"message": {
"scheduled_entries": [],
"unprocessable_entries": [],
"message": "Failed to authorize deletions for some or all of the environments. Ask someone with more permissions to delete the environments."
}
}
What is the expected correct behavior?
Response:
{
"scheduled_entries": [
{
"id": 10727948,
"name": "review/testing",
"slug": "review-testing-gzd91k",
"external_url": null,
"created_at": "2022-06-08T10:08:04.887Z",
"updated_at": "2022-06-08T10:13:24.767Z",
}
]
}
Like in gitlab-docs#1205 (comment 970105032)
Relevant logs and/or screenshots
However I'm able to delete it.
Request:
curl \
--fail-with-body \
--request DELETE \
--header "private-token:${GITLAB_API_TOKEN}" \
--url "https://gitlab.com/api/v4/projects/${PROJECT_ID}/environments/${ENVIRONMENT_ID}" | jq
Response:
interestingly there is no response from this request whatsoever
Output of checks
Happens on both GitLab.com (15.1.0-pre 4ba1f4c205b) as on self-hosted (14.10.3-ee).
Relevant issues
Edited by Shinya Maeda