From 76cb7a747693868895a158cf25fd75e6c10003a3 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Thu, 10 Apr 2025 11:26:40 +0000 Subject: [PATCH] feat: return hostname suffix on AgentConnectionInfo --- coderd/apidoc/docs.go | 3 +++ coderd/apidoc/swagger.json | 3 +++ coderd/workspaceagents.go | 2 ++ coderd/workspaceagents_test.go | 31 +++++++++++++++++++++++++++ codersdk/workspacesdk/workspacesdk.go | 1 + docs/reference/api/agents.md | 3 ++- docs/reference/api/schemas.md | 4 +++- 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index cb2f2f6c22e03..ba1cf6cc30bac 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -18615,6 +18615,9 @@ const docTemplate = `{ }, "disable_direct_connections": { "type": "boolean" + }, + "hostname_suffix": { + "type": "string" } } }, diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index 90f5729654a95..5a8d199e0a9d2 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -17050,6 +17050,9 @@ }, "disable_direct_connections": { "type": "boolean" + }, + "hostname_suffix": { + "type": "string" } } }, diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index 1744c0c6749ca..a4f8ed297b77a 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -882,6 +882,7 @@ func (api *API) workspaceAgentConnection(rw http.ResponseWriter, r *http.Request DERPMap: api.DERPMap(), DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(), DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(), + HostnameSuffix: api.DeploymentValues.WorkspaceHostnameSuffix.Value(), }) } @@ -903,6 +904,7 @@ func (api *API) workspaceAgentConnectionGeneric(rw http.ResponseWriter, r *http. DERPMap: api.DERPMap(), DERPForceWebSockets: api.DeploymentValues.DERP.Config.ForceWebSockets.Value(), DisableDirectConnections: api.DeploymentValues.DERP.Config.BlockDirect.Value(), + HostnameSuffix: api.DeploymentValues.WorkspaceHostnameSuffix.Value(), }) } diff --git a/coderd/workspaceagents_test.go b/coderd/workspaceagents_test.go index 186c66bfd6f8e..a8fe7718f4385 100644 --- a/coderd/workspaceagents_test.go +++ b/coderd/workspaceagents_test.go @@ -2560,3 +2560,34 @@ func requireEqualOrBothNil[T any](t testing.TB, a, b *T) { } require.Equal(t, a, b) } + +func TestAgentConnectionInfo(t *testing.T) { + t.Parallel() + ctx := testutil.Context(t, testutil.WaitShort) + + dv := coderdtest.DeploymentValues(t) + dv.WorkspaceHostnameSuffix = "yallah" + dv.DERP.Config.BlockDirect = true + dv.DERP.Config.ForceWebSockets = true + client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{DeploymentValues: dv}) + user := coderdtest.CreateFirstUser(t, client) + r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ + OrganizationID: user.OrganizationID, + OwnerID: user.UserID, + }).WithAgent().Do() + + info, err := workspacesdk.New(client).AgentConnectionInfoGeneric(ctx) + require.NoError(t, err) + require.Equal(t, "yallah", info.HostnameSuffix) + require.True(t, info.DisableDirectConnections) + require.True(t, info.DERPForceWebSockets) + + ws, err := client.Workspace(ctx, r.Workspace.ID) + require.NoError(t, err) + agnt := ws.LatestBuild.Resources[0].Agents[0] + info, err = workspacesdk.New(client).AgentConnectionInfo(ctx, agnt.ID) + require.NoError(t, err) + require.Equal(t, "yallah", info.HostnameSuffix) + require.True(t, info.DisableDirectConnections) + require.True(t, info.DERPForceWebSockets) +} diff --git a/codersdk/workspacesdk/workspacesdk.go b/codersdk/workspacesdk/workspacesdk.go index ca4a3d48d7ef2..82ae7904f8046 100644 --- a/codersdk/workspacesdk/workspacesdk.go +++ b/codersdk/workspacesdk/workspacesdk.go @@ -143,6 +143,7 @@ type AgentConnectionInfo struct { DERPMap *tailcfg.DERPMap `json:"derp_map"` DERPForceWebSockets bool `json:"derp_force_websockets"` DisableDirectConnections bool `json:"disable_direct_connections"` + HostnameSuffix string `json:"hostname_suffix"` } func (c *Client) AgentConnectionInfoGeneric(ctx context.Context) (AgentConnectionInfo, error) { diff --git a/docs/reference/api/agents.md b/docs/reference/api/agents.md index 8faba29cf7ba5..853cb67e38bfd 100644 --- a/docs/reference/api/agents.md +++ b/docs/reference/api/agents.md @@ -698,7 +698,8 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/{workspaceagent}/con } } }, - "disable_direct_connections": true + "disable_direct_connections": true, + "hostname_suffix": "string" } ``` diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index 6e7a2da1a3dea..fb9c3b8db782f 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -11514,7 +11514,8 @@ None } } }, - "disable_direct_connections": true + "disable_direct_connections": true, + "hostname_suffix": "string" } ``` @@ -11525,6 +11526,7 @@ None | `derp_force_websockets` | boolean | false | | | | `derp_map` | [tailcfg.DERPMap](#tailcfgderpmap) | false | | | | `disable_direct_connections` | boolean | false | | | +| `hostname_suffix` | string | false | | | ## wsproxysdk.CryptoKeysResponse