Skip to content

Commit

Permalink
Merge pull request #5235 from jwhonce/issues/5229
Browse files Browse the repository at this point in the history
Update mux rules to allow slashes in image names
  • Loading branch information
openshift-merge-robot authored Feb 18, 2020
2 parents 5dacee9 + 024ddda commit a5d5596
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pkg/api/handlers/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func SearchImages(w http.ResponseWriter, r *http.Request) {
}
results, err := image.SearchImages(query.Term, options)
if err != nil {
utils.InternalServerError(w, err)
utils.BadRequest(w, "term", query.Term, err)
}
utils.WriteResponse(w, http.StatusOK, results)
}
6 changes: 5 additions & 1 deletion pkg/api/handlers/utils/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) {
if _, found := mux.Vars(r)["digests"]; found && query.Digests {
UnSupportedParameter("digests")
}

if len(query.Filters) > 0 {
for k, v := range query.Filters {
for _, val := range v {
filters = append(filters, fmt.Sprintf("%s=%s", k, val))
}
}
return runtime.ImageRuntime().GetImagesWithFilters(filters)
} else {
return runtime.ImageRuntime().GetImages()
}
return runtime.ImageRuntime().GetImagesWithFilters(filters)

}
70 changes: 36 additions & 34 deletions pkg/api/server/register_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,20 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// responses:
// 200:
// $ref: "#/responses/DocsSearchResponse"
// 400:
// $ref: "#/responses/BadParamError"
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/images/search"), s.APIHandler(handlers.SearchImages)).Methods(http.MethodGet)
// swagger:operation DELETE /images/{name} compat removeImage
// swagger:operation DELETE /images/{name:.*} compat removeImage
// ---
// tags:
// - images (compat)
// summary: Remove Image
// description: Delete an image from local storage
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: name or ID of image to delete
Expand All @@ -195,16 +197,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/ConflictError'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/images/{name}"), s.APIHandler(handlers.RemoveImage)).Methods(http.MethodDelete)
// swagger:operation GET /images/{name}/get compat exportImage
r.Handle(VersionedPath("/images/{name:.*}"), s.APIHandler(handlers.RemoveImage)).Methods(http.MethodDelete)
// swagger:operation GET /images/{name:.*}/get compat exportImage
// ---
// tags:
// - images (compat)
// summary: Export an image
// description: Export an image in tarball format
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -218,16 +220,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// format: binary
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/images/{name}/get"), s.APIHandler(generic.ExportImage)).Methods(http.MethodGet)
// swagger:operation GET /images/{name}/history compat imageHistory
r.Handle(VersionedPath("/images/{name:.*}/get"), s.APIHandler(generic.ExportImage)).Methods(http.MethodGet)
// swagger:operation GET /images/{name:.*}/history compat imageHistory
// ---
// tags:
// - images (compat)
// summary: History of an image
// description: Return parent layers of an image.
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -240,16 +242,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: "#/responses/NoSuchImage"
// 500:
// $ref: "#/responses/InternalError"
r.Handle(VersionedPath("/images/{name}/history"), s.APIHandler(handlers.HistoryImage)).Methods(http.MethodGet)
// swagger:operation GET /images/{name}/json compat inspectImage
r.Handle(VersionedPath("/images/{name:.*}/history"), s.APIHandler(handlers.HistoryImage)).Methods(http.MethodGet)
// swagger:operation GET /images/{name:.*}/json compat inspectImage
// ---
// tags:
// - images (compat)
// summary: Inspect an image
// description: Return low-level information about an image.
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -262,16 +264,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: "#/responses/NoSuchImage"
// 500:
// $ref: "#/responses/InternalError"
r.Handle(VersionedPath("/images/{name}/json"), s.APIHandler(generic.GetImage))
// swagger:operation POST /images/{name}/tag compat tagImage
r.Handle(VersionedPath("/images/{name:.*}/json"), s.APIHandler(generic.GetImage))
// swagger:operation POST /images/{name:.*}/tag compat tagImage
// ---
// tags:
// - images (compat)
// summary: Tag an image
// description: Tag an image so that it becomes part of a repository.
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -296,7 +298,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/ConflictError'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/images/{name}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)
r.Handle(VersionedPath("/images/{name:.*}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)
// swagger:operation POST /commit/ compat commitContainer
// ---
// tags:
Expand Down Expand Up @@ -556,15 +558,15 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
libpod endpoints
*/

// swagger:operation POST /libpod/images/{name}/exists libpod libpodImageExists
// swagger:operation POST /libpod/images/{name:.*}/exists libpod libpodImageExists
// ---
// tags:
// - images
// summary: Image exists
// description: Check if image exists in local store
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -577,16 +579,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/exists"), s.APIHandler(libpod.ImageExists))
// swagger:operation POST /libpod/images/{name}/tree libpod libpodImageTree
r.Handle(VersionedPath("/libpod/images/{name:.*}/exists"), s.APIHandler(libpod.ImageExists))
// swagger:operation POST /libpod/images/{name:.*}/tree libpod libpodImageTree
// ---
// tags:
// - images
// summary: Image tree
// description: Retrieve the image tree for the provided image name or ID
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -603,16 +605,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/tree"), s.APIHandler(libpod.ImageTree))
// swagger:operation GET /libpod/images/{name}/history libpod libpodImageHistory
r.Handle(VersionedPath("/libpod/images/{name:.*}/tree"), s.APIHandler(libpod.ImageTree))
// swagger:operation GET /libpod/images/{name:.*}/history libpod libpodImageHistory
// ---
// tags:
// - images
// summary: History of an image
// description: Return parent layers of an image.
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -625,7 +627,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/history"), s.APIHandler(handlers.HistoryImage)).Methods(http.MethodGet)
r.Handle(VersionedPath("/libpod/images/{name:.*}/history"), s.APIHandler(handlers.HistoryImage)).Methods(http.MethodGet)
// swagger:operation GET /libpod/images/json libpod libpodListImages
// ---
// tags:
Expand Down Expand Up @@ -849,16 +851,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/ConflictError'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}"), s.APIHandler(handlers.RemoveImage)).Methods(http.MethodDelete)
// swagger:operation GET /libpod/images/{name}/get libpod libpoodExportImage
r.Handle(VersionedPath("/libpod/images/{name:.*}"), s.APIHandler(handlers.RemoveImage)).Methods(http.MethodDelete)
// swagger:operation GET /libpod/images/{name:.*}/get libpod libpoodExportImage
// ---
// tags:
// - images
// summary: Export an image
// description: Export an image as a tarball
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -882,16 +884,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/get"), s.APIHandler(libpod.ExportImage)).Methods(http.MethodGet)
// swagger:operation GET /libpod/images/{name}/json libpod libpodInspectImage
r.Handle(VersionedPath("/libpod/images/{name:.*}/get"), s.APIHandler(libpod.ExportImage)).Methods(http.MethodGet)
// swagger:operation GET /libpod/images/{name:.*}/json libpod libpodInspectImage
// ---
// tags:
// - images
// summary: Inspect an image
// description: Obtain low-level information about an image
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -904,16 +906,16 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/NoSuchImage'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/json"), s.APIHandler(libpod.GetImage))
// swagger:operation POST /libpod/images/{name}/tag libpod libpodTagImage
r.Handle(VersionedPath("/libpod/images/{name:.*}/json"), s.APIHandler(libpod.GetImage))
// swagger:operation POST /libpod/images/{name:.*}/tag libpod libpodTagImage
// ---
// tags:
// - images
// summary: Tag an image
// description: Tag an image so that it becomes part of a repository.
// parameters:
// - in: path
// name: name
// name: name:.*
// type: string
// required: true
// description: the name or ID of the container
Expand All @@ -938,7 +940,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: '#/responses/ConflictError'
// 500:
// $ref: '#/responses/InternalError'
r.Handle(VersionedPath("/libpod/images/{name}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)
r.Handle(VersionedPath("/libpod/images/{name:.*}/tag"), s.APIHandler(handlers.TagImage)).Methods(http.MethodPost)

return nil
}

0 comments on commit a5d5596

Please sign in to comment.