Skip to content

Commit e2973ba

Browse files
committed
fixup! feat: add endpoint to get listening ports in agent
1 parent ea2027e commit e2973ba

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

agent/ports_supported.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package agent
55

66
import (
7-
"runtime"
87
"time"
98

109
"github.com/cakturk/go-netstat/netstat"
@@ -17,13 +16,6 @@ func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort,
1716
lp.mut.Lock()
1817
defer lp.mut.Unlock()
1918

20-
if runtime.GOOS != "linux" && runtime.GOOS != "windows" {
21-
// Can't scan for ports on non-linux or non-windows systems at the
22-
// moment. The UI will not show any "no ports found" message to the
23-
// user, so the user won't suspect a thing.
24-
return []codersdk.ListeningPort{}, nil
25-
}
26-
2719
if time.Since(lp.mtime) < time.Second {
2820
// copy
2921
ports := make([]codersdk.ListeningPort, len(lp.ports))

coderd/workspaceagents.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,21 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
227227
return
228228
}
229229

230+
apiAgent, err := convertWorkspaceAgent(api.DERPMap, api.TailnetCoordinator, workspaceAgent, nil, api.AgentInactiveDisconnectTimeout)
231+
if err != nil {
232+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
233+
Message: "Internal error reading workspace agent.",
234+
Detail: err.Error(),
235+
})
236+
return
237+
}
238+
if apiAgent.Status != codersdk.WorkspaceAgentConnected {
239+
httpapi.Write(ctx, rw, http.StatusPreconditionRequired, codersdk.Response{
240+
Message: fmt.Sprintf("Agent state is %q, it must be in the %q state.", apiAgent.Status, codersdk.WorkspaceAgentConnected),
241+
})
242+
return
243+
}
244+
230245
agentConn, release, err := api.workspaceAgentCache.Acquire(r, workspaceAgent.ID)
231246
if err != nil {
232247
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{

0 commit comments

Comments
 (0)