Skip to content

Commit e2356b2

Browse files
committed
Show default proxy in proxy list
1 parent 9db95ae commit e2356b2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

coderd/database/modelmethods.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ func (w WorkspaceProxy) RBACObject() rbac.Object {
186186
WithID(w.ID)
187187
}
188188

189+
func (w WorkspaceProxy) IsPrimary() bool {
190+
return w.Name == "primary"
191+
}
192+
189193
func (f File) RBACObject() rbac.Object {
190194
return rbac.ResourceFile.
191195
WithID(f.ID).

enterprise/coderd/workspaceproxy.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (api *API) patchWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
138138
// User is editing the default primary proxy.
139139
if req.Name != "" {
140140
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
141-
Message: "Cannot update name of default primary proxy",
141+
Message: "Cannot update name of default primary proxy, did you mean to update the 'display name'?",
142142
Validations: []codersdk.ValidationError{
143143
{Field: "name", Detail: "Cannot update name of default primary proxy"},
144144
},
@@ -244,7 +244,7 @@ func (api *API) deleteWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
244244
aReq.Old = proxy
245245
defer commitAudit()
246246

247-
if proxy.Name == "primary" {
247+
if proxy.IsPrimary() {
248248
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
249249
Message: "Cannot delete primary proxy",
250250
})
@@ -403,6 +403,14 @@ func (api *API) workspaceProxies(rw http.ResponseWriter, r *http.Request) {
403403
return
404404
}
405405

406+
// Add the primary as well
407+
primaryProxy, err := api.AGPL.PrimaryWorkspaceProxy(ctx)
408+
if err != nil && !xerrors.Is(err, sql.ErrNoRows) {
409+
httpapi.InternalServerError(rw, err)
410+
return
411+
}
412+
proxies = append(proxies, primaryProxy)
413+
406414
statues := api.ProxyHealth.HealthStatus()
407415
httpapi.Write(ctx, rw, http.StatusOK, convertProxies(proxies, statues))
408416
}
@@ -680,6 +688,18 @@ func convertProxies(p []database.WorkspaceProxy, statuses map[uuid.UUID]proxyhea
680688
}
681689

682690
func convertProxy(p database.WorkspaceProxy, status proxyhealth.ProxyStatus) codersdk.WorkspaceProxy {
691+
if p.IsPrimary() {
692+
// Primary is always healthy since the primary serves the api that this
693+
// is returned from.
694+
u, _ := url.Parse(p.Url)
695+
status = proxyhealth.ProxyStatus{
696+
Proxy: p,
697+
ProxyHost: u.Host,
698+
Status: proxyhealth.Healthy,
699+
Report: codersdk.ProxyHealthReport{},
700+
CheckedAt: time.Now(),
701+
}
702+
}
683703
if status.Status == "" {
684704
status.Status = proxyhealth.Unknown
685705
}

0 commit comments

Comments
 (0)