From baf3bf6b9cdb7be3d06af2274ff1de2acaf02e1c Mon Sep 17 00:00:00 2001 From: Szabolcs Fruhwald Date: Sun, 3 Dec 2023 13:41:54 -0800 Subject: [PATCH] feat: add workspace_id, owner_name to agent manifest (#10199) Co-authored-by: Kyle Carberry Co-authored-by: Atif Ali --- coderd/apidoc/docs.go | 7 +++++++ coderd/apidoc/swagger.json | 7 +++++++ coderd/workspaceagents.go | 2 ++ coderd/workspaceagents_test.go | 2 ++ codersdk/agentsdk/agentsdk.go | 5 +++++ docs/api/agents.md | 4 +++- docs/api/schemas.md | 36 +++++++++++++++++++--------------- 7 files changed, 46 insertions(+), 17 deletions(-) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index c88eb6fb2b..72003c9273 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -6917,6 +6917,10 @@ const docTemplate = `{ "motd_file": { "type": "string" }, + "owner_name": { + "description": "OwnerName and WorkspaceID are used by an open-source user to identify the workspace.\nWe do not provide insurance that this will not be removed in the future,\nbut if it's easy to persist lets keep it around.", + "type": "string" + }, "scripts": { "type": "array", "items": { @@ -6925,6 +6929,9 @@ const docTemplate = `{ }, "vscode_port_proxy_uri": { "type": "string" + }, + "workspace_id": { + "type": "string" } } }, diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index ed7fa177e6..477bb430fc 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -6103,6 +6103,10 @@ "motd_file": { "type": "string" }, + "owner_name": { + "description": "OwnerName and WorkspaceID are used by an open-source user to identify the workspace.\nWe do not provide insurance that this will not be removed in the future,\nbut if it's easy to persist lets keep it around.", + "type": "string" + }, "scripts": { "type": "array", "items": { @@ -6111,6 +6115,9 @@ }, "vscode_port_proxy_uri": { "type": "string" + }, + "workspace_id": { + "type": "string" } } }, diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index d0ee7e7090..c862706c56 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -237,6 +237,8 @@ func (api *API) workspaceAgentManifest(rw http.ResponseWriter, r *http.Request) httpapi.Write(ctx, rw, http.StatusOK, agentsdk.Manifest{ AgentID: apiAgent.ID, + OwnerName: owner.Username, + WorkspaceID: workspace.ID, Apps: convertApps(dbApps, workspaceAgent, owner.Username, workspace), Scripts: convertScripts(scripts), DERPMap: api.DERPMap(), diff --git a/coderd/workspaceagents_test.go b/coderd/workspaceagents_test.go index 0b6d6316b0..c8404b2acf 100644 --- a/coderd/workspaceagents_test.go +++ b/coderd/workspaceagents_test.go @@ -998,6 +998,8 @@ func TestWorkspaceAgent_Metadata(t *testing.T) { require.NoError(t, err) // Verify manifest API response. + require.Equal(t, workspace.ID, manifest.WorkspaceID) + require.Equal(t, workspace.OwnerName, manifest.OwnerName) require.Equal(t, "First Meta", manifest.Metadata[0].DisplayName) require.Equal(t, "foo1", manifest.Metadata[0].Key) require.Equal(t, "echo hi", manifest.Metadata[0].Script) diff --git a/codersdk/agentsdk/agentsdk.go b/codersdk/agentsdk/agentsdk.go index bba1f247b2..1ca60a09b1 100644 --- a/codersdk/agentsdk/agentsdk.go +++ b/codersdk/agentsdk/agentsdk.go @@ -98,6 +98,11 @@ func (c *Client) PostMetadata(ctx context.Context, req PostMetadataRequest) erro type Manifest struct { AgentID uuid.UUID `json:"agent_id"` + // OwnerName and WorkspaceID are used by an open-source user to identify the workspace. + // We do not provide insurance that this will not be removed in the future, + // but if it's easy to persist lets keep it around. + OwnerName string `json:"owner_name"` + WorkspaceID uuid.UUID `json:"workspace_id"` // GitAuthConfigs stores the number of Git configurations // the Coder deployment has. If this number is >0, we // set up special configuration in the workspace. diff --git a/docs/api/agents.md b/docs/api/agents.md index 91f596582f..ddd2793524 100644 --- a/docs/api/agents.md +++ b/docs/api/agents.md @@ -518,6 +518,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/me/manifest \ } ], "motd_file": "string", + "owner_name": "string", "scripts": [ { "cron": "string", @@ -530,7 +531,8 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/me/manifest \ "timeout": 0 } ], - "vscode_port_proxy_uri": "string" + "vscode_port_proxy_uri": "string", + "workspace_id": "string" } ``` diff --git a/docs/api/schemas.md b/docs/api/schemas.md index b2d344fbd9..cf05ec3ba3 100644 --- a/docs/api/schemas.md +++ b/docs/api/schemas.md @@ -283,6 +283,7 @@ } ], "motd_file": "string", + "owner_name": "string", "scripts": [ { "cron": "string", @@ -295,27 +296,30 @@ "timeout": 0 } ], - "vscode_port_proxy_uri": "string" + "vscode_port_proxy_uri": "string", + "workspace_id": "string" } ``` ### Properties -| Name | Type | Required | Restrictions | Description | -| ---------------------------- | ------------------------------------------------------------------------------------------------- | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `agent_id` | string | false | | | -| `apps` | array of [codersdk.WorkspaceApp](#codersdkworkspaceapp) | false | | | -| `derp_force_websockets` | boolean | false | | | -| `derpmap` | [tailcfg.DERPMap](#tailcfgderpmap) | false | | | -| `directory` | string | false | | | -| `disable_direct_connections` | boolean | false | | | -| `environment_variables` | object | false | | | -| » `[any property]` | string | false | | | -| `git_auth_configs` | integer | false | | Git auth configs stores the number of Git configurations the Coder deployment has. If this number is >0, we set up special configuration in the workspace. | -| `metadata` | array of [codersdk.WorkspaceAgentMetadataDescription](#codersdkworkspaceagentmetadatadescription) | false | | | -| `motd_file` | string | false | | | -| `scripts` | array of [codersdk.WorkspaceAgentScript](#codersdkworkspaceagentscript) | false | | | -| `vscode_port_proxy_uri` | string | false | | | +| Name | Type | Required | Restrictions | Description | +| ---------------------------- | ------------------------------------------------------------------------------------------------- | -------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `agent_id` | string | false | | | +| `apps` | array of [codersdk.WorkspaceApp](#codersdkworkspaceapp) | false | | | +| `derp_force_websockets` | boolean | false | | | +| `derpmap` | [tailcfg.DERPMap](#tailcfgderpmap) | false | | | +| `directory` | string | false | | | +| `disable_direct_connections` | boolean | false | | | +| `environment_variables` | object | false | | | +| » `[any property]` | string | false | | | +| `git_auth_configs` | integer | false | | Git auth configs stores the number of Git configurations the Coder deployment has. If this number is >0, we set up special configuration in the workspace. | +| `metadata` | array of [codersdk.WorkspaceAgentMetadataDescription](#codersdkworkspaceagentmetadatadescription) | false | | | +| `motd_file` | string | false | | | +| `owner_name` | string | false | | Owner name and WorkspaceID are used by an open-source user to identify the workspace. We do not provide insurance that this will not be removed in the future, but if it's easy to persist lets keep it around. | +| `scripts` | array of [codersdk.WorkspaceAgentScript](#codersdkworkspaceagentscript) | false | | | +| `vscode_port_proxy_uri` | string | false | | | +| `workspace_id` | string | false | | | ## agentsdk.Metadata