Handle invalid repository names gracefully

What does this MR do and why?

Handle invalid repository names gracefully

for the POST /container_registry_event/events endpoint.

Before this fix, the endpoint would return a 500 status code.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Save the following event payload into a file locally, e.g. bad-event.json. Note the "repository":"unknown-repository" is the problem here.
{
   "events": [
      {
         "id": "1aa3d563-84f0-4c24-a4d7-069700f9f73f",
         "timestamp": "2022-01-18T12:53:32.093331+11:00",
         "action": "push",
         "target": {
            "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
            "size": 528,
            "digest": "sha256:5e604d3358ab7b6b734402ce2e19ddd822a354dc14843f34d36c603521dbb4f9",
            "length": 528,
            "repository": "unknown-repository",
            "url": "http://registry.test:5000/v2/unknown-repository/manifests/sha256:5e604d3358ab7b6b734402ce2e19ddd822a354dc14843f34d36c603521dbb4f9",
            "tag": "alpine"
         },
         "request": {
            "id": "a0f4d5a5-424a-4dca-86d1-99e6477f7b37",
            "addr": "172.16.123.1:57699",
            "host": "registry.test:5000",
            "method": "PUT",
            "useragent": "docker/20.10.11 go/go1.16.9 git-commit/847da18 kernel/5.10.76-linuxkit os/linux arch/amd64 UpstreamClient(Docker-Client/20.10.11 \\(darwin\\))"
         },
         "actor": {},
         "source": {
            "addr": "Jaimes-MacBook-Pro.local:5000",
            "instanceID": "9c9280d4-4e0d-4c4b-b25a-af1b22b67b1a"
         }
      }
   ]
}
  1. Call the /container_registry_event/events endpoint via curl
export ns='notifications_secret'
curl -XPOST --header "Authorization: $ns" --header "Content-Type: application/vnd.docker.distribution.events.v1+json" "http://gdk.test:3000/api/v4/container_registry_event/events" --upload-file bad-event.json
{"message":"Invalid repository path"}%
Edited by Jaime Martinez

Merge request reports

Loading