Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
enable patch endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Ilario <filario@redhat.com>
  • Loading branch information
filariow committed Oct 11, 2024
1 parent 6c0ed76 commit 6f3f6af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions server/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ func New(
listHandle workspace.ListWorkspaceQueryHandlerFunc,
createHandle workspace.CreateWorkspaceCommandHandlerFunc,
updateHandle workspace.UpdateWorkspaceCommandHandlerFunc,
patchHandle workspace.PatchWorkspaceCommandHandlerFunc,
) *http.Server {
return &http.Server{
Addr: addr,
Handler: buildServerHandler(logger, cache, readHandle, listHandle, createHandle, updateHandle),
Handler: buildServerHandler(logger, cache, readHandle, listHandle, createHandle, updateHandle, patchHandle),
ReadHeaderTimeout: 3 * time.Second,
}
}
Expand All @@ -42,10 +43,11 @@ func buildServerHandler(
listHandle workspace.ListWorkspaceQueryHandlerFunc,
createHandle workspace.CreateWorkspaceCommandHandlerFunc,
updateHandle workspace.UpdateWorkspaceCommandHandlerFunc,
patchHandle workspace.PatchWorkspaceCommandHandlerFunc,
) http.Handler {
mux := http.NewServeMux()
addHealthz(mux)
addWorkspaces(mux, cache, readHandle, listHandle, createHandle, updateHandle)
addWorkspaces(mux, cache, readHandle, listHandle, createHandle, updateHandle, patchHandle)
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
Expand All @@ -66,6 +68,7 @@ func addWorkspaces(
listHandle workspace.ListWorkspaceQueryHandlerFunc,
_ workspace.CreateWorkspaceCommandHandlerFunc,
updateHandle workspace.UpdateWorkspaceCommandHandlerFunc,
patchHandle workspace.PatchWorkspaceCommandHandlerFunc,
) {
// Read
mux.Handle(fmt.Sprintf("GET %s/{name}", NamespacedWorkspacesPrefix),
Expand Down Expand Up @@ -100,6 +103,16 @@ func addWorkspaces(
marshal.DefaultUnmarshalerProvider,
))))

// Patch
mux.Handle(fmt.Sprintf("PATCH %s/{name}", NamespacedWorkspacesPrefix),
withAuthHeaderInfo(
withUserSignupAuth(cache,
workspace.NewPatchWorkspaceHandler(
workspace.MapPatchWorkspaceHttp,
patchHandle,
marshal.DefaultMarshalerProvider,
))))

// Create
// mux.Handle(fmt.Sprintf("POST %s", NamespacedWorkspacesPrefix),
// withAuthHeaderInfo(
Expand Down
4 changes: 2 additions & 2 deletions server/rest/workspace/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func NewDefaultPatchWorkspaceHandler(
// NewPatchWorkspaceHandler creates a PatchWorkspaceHandler
func NewPatchWorkspaceHandler(
mapperFunc PatchWorkspaceMapperFunc,
queryHandler PatchWorkspaceCommandHandlerFunc,
commandHandler PatchWorkspaceCommandHandlerFunc,
marshalerProvider marshal.MarshalerProvider,
) *PatchWorkspaceHandler {
return &PatchWorkspaceHandler{
MapperFunc: mapperFunc,
CommandHandler: queryHandler,
CommandHandler: commandHandler,
MarshalerProvider: marshalerProvider,
}
}
Expand Down

0 comments on commit 6f3f6af

Please sign in to comment.