@@ -83,6 +83,46 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
83
83
})
84
84
return
85
85
}
86
+ resource , err := api .Database .GetWorkspaceResourceByID (r .Context (), workspaceAgent .ResourceID )
87
+ if err != nil {
88
+ httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
89
+ Message : "Internal error fetching workspace resource." ,
90
+ Detail : err .Error (),
91
+ })
92
+ return
93
+ }
94
+ build , err := api .Database .GetWorkspaceBuildByJobID (r .Context (), resource .JobID )
95
+ if err != nil {
96
+ httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
97
+ Message : "Internal error fetching workspace build." ,
98
+ Detail : err .Error (),
99
+ })
100
+ return
101
+ }
102
+ workspace , err := api .Database .GetWorkspaceByID (r .Context (), build .WorkspaceID )
103
+ if err != nil {
104
+ httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
105
+ Message : "Internal error fetching workspace." ,
106
+ Detail : err .Error (),
107
+ })
108
+ return
109
+ }
110
+ owner , err := api .Database .GetUserByID (r .Context (), workspace .OwnerID )
111
+ if err != nil {
112
+ httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
113
+ Message : "Internal error fetching workspace owner." ,
114
+ Detail : err .Error (),
115
+ })
116
+ return
117
+ }
118
+
119
+ vscodeProxyURI := strings .ReplaceAll (api .AppHostname , "*" ,
120
+ fmt .Sprintf ("%s://{{port}}--%s--%s--%s" ,
121
+ api .AccessURL .Scheme ,
122
+ workspaceAgent .Name ,
123
+ workspace .Name ,
124
+ owner .Username ,
125
+ ))
86
126
87
127
httpapi .Write (ctx , rw , http .StatusOK , codersdk.WorkspaceAgentMetadata {
88
128
Apps : convertApps (dbApps ),
@@ -91,6 +131,7 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
91
131
EnvironmentVariables : apiAgent .EnvironmentVariables ,
92
132
StartupScript : apiAgent .StartupScript ,
93
133
Directory : apiAgent .Directory ,
134
+ VSCodePortProxyURI : vscodeProxyURI ,
94
135
})
95
136
}
96
137
0 commit comments