PrimaryRegion exposes the user facing values of a workspace proxy to be used by a user.
(ctx context.Context)
| 18 | // PrimaryRegion exposes the user facing values of a workspace proxy to |
| 19 | // be used by a user. |
| 20 | func (api *API) PrimaryRegion(ctx context.Context) (codersdk.Region, error) { |
| 21 | deploymentIDStr, err := api.Database.GetDeploymentID(ctx) |
| 22 | if xerrors.Is(err, sql.ErrNoRows) { |
| 23 | // This shouldn't happen but it's pretty easy to avoid this causing |
| 24 | // issues by falling back to a nil UUID. |
| 25 | deploymentIDStr = uuid.Nil.String() |
| 26 | } else if err != nil { |
| 27 | return codersdk.Region{}, xerrors.Errorf("get deployment ID: %w", err) |
| 28 | } |
| 29 | deploymentID, err := uuid.Parse(deploymentIDStr) |
| 30 | if err != nil { |
| 31 | // This also shouldn't happen but we fallback to nil UUID. |
| 32 | deploymentID = uuid.Nil |
| 33 | } |
| 34 | |
| 35 | proxy, err := api.Database.GetDefaultProxyConfig(ctx) |
| 36 | if err != nil { |
| 37 | return codersdk.Region{}, xerrors.Errorf("get default proxy config: %w", err) |
| 38 | } |
| 39 | |
| 40 | return codersdk.Region{ |
| 41 | ID: deploymentID, |
| 42 | Name: "primary", |
| 43 | DisplayName: proxy.DisplayName, |
| 44 | IconURL: proxy.IconURL, |
| 45 | Healthy: true, |
| 46 | PathAppURL: api.AccessURL.String(), |
| 47 | WildcardHostname: appurl.SubdomainAppHost(api.AppHostname, api.AccessURL), |
| 48 | }, nil |
| 49 | } |
| 50 | |
| 51 | // PrimaryWorkspaceProxy returns the primary workspace proxy for the site. |
| 52 | func (api *API) PrimaryWorkspaceProxy(ctx context.Context) (database.WorkspaceProxy, error) { |
no test coverage detected