|
7 | 7 | "fmt"
|
8 | 8 | "net/http"
|
9 | 9 | "net/url"
|
| 10 | + "strings" |
10 | 11 | "time"
|
11 | 12 |
|
12 | 13 | "github.com/google/uuid"
|
@@ -57,26 +58,31 @@ func (api *API) regions(rw http.ResponseWriter, r *http.Request) {
|
57 | 58 | return
|
58 | 59 | }
|
59 | 60 |
|
60 |
| - proxyHealth := api.ProxyHealth.HealthStatus() |
61 |
| - for _, proxy := range proxies { |
62 |
| - if proxy.Deleted { |
63 |
| - continue |
64 |
| - } |
65 |
| - |
66 |
| - health, ok := proxyHealth[proxy.ID] |
67 |
| - if !ok { |
68 |
| - health.Status = proxyhealth.Unknown |
| 61 | + // Only add additional regions if the proxy health is enabled. |
| 62 | + // If it is nil, it is because the moons feature flag is not on. |
| 63 | + // By default, we still want to return the primary region. |
| 64 | + if api.ProxyHealth != nil { |
| 65 | + proxyHealth := api.ProxyHealth.HealthStatus() |
| 66 | + for _, proxy := range proxies { |
| 67 | + if proxy.Deleted { |
| 68 | + continue |
| 69 | + } |
| 70 | + |
| 71 | + health, ok := proxyHealth[proxy.ID] |
| 72 | + if !ok { |
| 73 | + health.Status = proxyhealth.Unknown |
| 74 | + } |
| 75 | + |
| 76 | + regions = append(regions, codersdk.Region{ |
| 77 | + ID: proxy.ID, |
| 78 | + Name: proxy.Name, |
| 79 | + DisplayName: proxy.DisplayName, |
| 80 | + IconURL: proxy.Icon, |
| 81 | + Healthy: health.Status == proxyhealth.Healthy, |
| 82 | + PathAppURL: proxy.Url, |
| 83 | + WildcardHostname: proxy.WildcardHostname, |
| 84 | + }) |
69 | 85 | }
|
70 |
| - |
71 |
| - regions = append(regions, codersdk.Region{ |
72 |
| - ID: proxy.ID, |
73 |
| - Name: proxy.Name, |
74 |
| - DisplayName: proxy.DisplayName, |
75 |
| - IconURL: proxy.Icon, |
76 |
| - Healthy: health.Status == proxyhealth.Healthy, |
77 |
| - PathAppURL: proxy.Url, |
78 |
| - WildcardHostname: proxy.WildcardHostname, |
79 |
| - }) |
80 | 86 | }
|
81 | 87 |
|
82 | 88 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.RegionsResponse{
|
@@ -156,6 +162,20 @@ func (api *API) postWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
|
156 | 162 | return
|
157 | 163 | }
|
158 | 164 |
|
| 165 | + if strings.ToLower(req.Name) == "primary" { |
| 166 | + httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 167 | + Message: `The name "primary" is reserved for the primary region.`, |
| 168 | + Detail: "Cannot name a workspace proxy 'primary'.", |
| 169 | + Validations: []codersdk.ValidationError{ |
| 170 | + { |
| 171 | + Field: "name", |
| 172 | + Detail: "Reserved name", |
| 173 | + }, |
| 174 | + }, |
| 175 | + }) |
| 176 | + return |
| 177 | + } |
| 178 | + |
159 | 179 | id := uuid.New()
|
160 | 180 | secret, err := cryptorand.HexString(64)
|
161 | 181 | if err != nil {
|
|
0 commit comments