Skip to content
Next Next commit
fix: Fix properly naming workspace agents
  • Loading branch information
Emyrk committed Aug 24, 2022
commit 433705d03fc57c3808b96f4ed167f865d96ca76c
1 change: 1 addition & 0 deletions coderd/httpmw/chiparams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package httpmw
23 changes: 20 additions & 3 deletions coderd/workspaceapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,31 @@ func (api *API) workspaceAppsProxyPath(rw http.ResponseWriter, r *http.Request)
return
}

agent := agents[0]
if len(workspaceParts) > 1 {
// If we have more than 1 workspace agent, we need to specify which one to use.
if len(agents) > 1 && len(workspaceParts) <= 1 {
httpapi.Write(rw, http.StatusBadRequest, codersdk.Response{
Message: "More than one agent exists, but no agent specified.",
})
return
}

// If we have more than 1 workspace agent, we need to specify which one to use.
var agent *database.WorkspaceAgent
if len(agents) > 1 {
for _, otherAgent := range agents {
if otherAgent.Name == workspaceParts[1] {
agent = otherAgent
agent = &otherAgent
break
}
}
if agent == nil {
httpapi.Write(rw, http.StatusBadRequest, codersdk.Response{
Message: fmt.Sprintf("No agent exists with the name %s", workspaceParts[1]),
})
return
}
} else {
agent = &agents[0]
}

app, err := api.Database.GetWorkspaceAppByAgentIDAndName(r.Context(), database.GetWorkspaceAppByAgentIDAndNameParams{
Expand Down