goharbor / harbor

An open source trusted cloud native registry project that stores, signs, and scans content.
https://goharbor.io
Apache License 2.0
24.13k stars 4.76k forks source link

Cannot find repository if name contains slashes via rest api #12224

Closed rocenpe closed 4 years ago

rocenpe commented 4 years ago

If I push image to project whose name contains slashes, then when i do get info about repository via rest api it does not work. In some case the repository cannot be deleted. Example if you call get info about all repositories in project curl -X GET "https://vncub2056.os.kb.cz/api/v2.0/projects/it-tools/repositories?page=1&page_size=100" -H "accept: application/json" -H "X-Harbor-CSRF-Token: LXURUcMfo3bnRvzvXGZyFYdIWsewtIABWJsXhmYsXE+WQ5aa2eUXkzgfxS7QQ0O1sP5TY2oNi6UBfwh+p3C+Kw=="

then I see repositories. { "artifact_count": 1, "creation_time": "2020-06-11T15:08:50.890Z", "id": 4, "name": "it-tools/mws/tools/mw_nginx_builder", "project_id": 35, "pull_count": 1, "update_time": "2020-06-11T15:08:52.311Z" },

If I call get only for one repository curl -X GET "https://vncub2056.os.kb.cz/api/v2.0/projects/it-tools/repositories/mws%2Ftools%2Fmw_nginx_builder" -H "accept: application/json" -H "X-Harbor-CSRF-Token: 62Sp3fpHRrzp5n+pEzw8SfsV8LColsW6qKTsxQe9EwRQUi4W4L3yWTa/RmifGQ3pzKP5FHIvzh7xQPM9xuHxYA=="

then it gives error { "errors": [ { "code": "NOT_FOUND", "message": "path /api/v2.0/projects/it-tools/repositories/mws/tools/mw_nginx_builder was not found" } ] } If repository name contains project name between slashes then it even cannot be deleted and it gives error method DELETE is not allowed, but [GET] are see the picture at the attachment

screen1

Than you for your help. Blessings, Petr Rocen

reasonerjt commented 4 years ago

@ywk253100 please provide more details regarding how to encode the URI

rocenpe commented 4 years ago

Hello Daniel, This problem I can reproduce with harbor rest api browser devcenter-api-2.0. Do you need some logs? Can you clarify what information you need? Thank you. Blessings, Petr

ywk253100 commented 4 years ago

@rocenpe You need to encode the / twice: a/b -> a%252Fb: https://github.com/goharbor/harbor/blob/master/api/v2.0/swagger.yaml#L673

rocenpe commented 4 years ago

Hello Wenkai, thank you for your notes. Problem is only your rest api browser devcenter-api-2.0. I must change slash for %2F image Maybe wants to fix it, it's a little confusing Blessings, Petr

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.