Skip to content

Commit 433705d

Browse files
committed
fix: Fix properly naming workspace agents
1 parent da54874 commit 433705d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

coderd/httpmw/chiparams.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package httpmw

coderd/workspaceapps.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,31 @@ func (api *API) workspaceAppsProxyPath(rw http.ResponseWriter, r *http.Request)
8585
return
8686
}
8787

88-
agent := agents[0]
89-
if len(workspaceParts) > 1 {
88+
// If we have more than 1 workspace agent, we need to specify which one to use.
89+
if len(agents) > 1 && len(workspaceParts) <= 1 {
90+
httpapi.Write(rw, http.StatusBadRequest, codersdk.Response{
91+
Message: "More than one agent exists, but no agent specified.",
92+
})
93+
return
94+
}
95+
96+
// If we have more than 1 workspace agent, we need to specify which one to use.
97+
var agent *database.WorkspaceAgent
98+
if len(agents) > 1 {
9099
for _, otherAgent := range agents {
91100
if otherAgent.Name == workspaceParts[1] {
92-
agent = otherAgent
101+
agent = &otherAgent
93102
break
94103
}
95104
}
105+
if agent == nil {
106+
httpapi.Write(rw, http.StatusBadRequest, codersdk.Response{
107+
Message: fmt.Sprintf("No agent exists with the name %s", workspaceParts[1]),
108+
})
109+
return
110+
}
111+
} else {
112+
agent = &agents[0]
96113
}
97114

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

0 commit comments

Comments
 (0)