@@ -251,3 +251,66 @@ func (api *API) workspaceProxyIssueSignedAppToken(rw http.ResponseWriter, r *htt
251
251
SignedTokenStr : tokenStr ,
252
252
})
253
253
}
254
+
255
+ // workspaceProxyRegister is used to register a new workspace proxy. When a proxy
256
+ // comes online, it will announce itself to this endpoint. This updates its values
257
+ // in the database and returns a signed token that can be used to authenticate
258
+ // tokens.
259
+ //
260
+ // @Summary Register workspace proxy
261
+ // @ID register-workspace-proxy
262
+ // @Security CoderSessionToken
263
+ // @Accept json
264
+ // @Produce json
265
+ // @Tags Enterprise
266
+ // @Param request body wsproxysdk.RegisterWorkspaceProxyRequest true "Issue signed app token request"
267
+ // @Success 201 {object} wsproxysdk.RegisterWorkspaceProxyResponse
268
+ // @Router /workspaceproxies/me/register [post]
269
+ // @x-apidocgen {"skip": true}
270
+ func (api * API ) workspaceProxyRegister (rw http.ResponseWriter , r * http.Request ) {
271
+ var (
272
+ ctx = r .Context ()
273
+ proxy = httpmw .WorkspaceProxy (r )
274
+ )
275
+
276
+ var req wsproxysdk.RegisterWorkspaceProxyRequest
277
+ if ! httpapi .Read (ctx , rw , r , & req ) {
278
+ return
279
+ }
280
+
281
+ if err := validateProxyURL (req .AccessURL ); err != nil {
282
+ httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
283
+ Message : "URL is invalid." ,
284
+ Detail : err .Error (),
285
+ })
286
+ return
287
+ }
288
+
289
+ if req .WildcardHostname != "" {
290
+ if _ , err := httpapi .CompileHostnamePattern (req .WildcardHostname ); err != nil {
291
+ httpapi .Write (ctx , rw , http .StatusBadRequest , codersdk.Response {
292
+ Message : "Wildcard URL is invalid." ,
293
+ Detail : err .Error (),
294
+ })
295
+ return
296
+ }
297
+ }
298
+
299
+ _ , err := api .Database .RegisterWorkspaceProxy (ctx , database.RegisterWorkspaceProxyParams {
300
+ ID : proxy .ID ,
301
+ Url : req .AccessURL ,
302
+ WildcardHostname : req .WildcardHostname ,
303
+ })
304
+ if httpapi .Is404Error (err ) {
305
+ httpapi .ResourceNotFound (rw )
306
+ return
307
+ }
308
+ if err != nil {
309
+ httpapi .InternalServerError (rw , err )
310
+ return
311
+ }
312
+
313
+ httpapi .Write (ctx , rw , http .StatusCreated , wsproxysdk.RegisterWorkspaceProxyResponse {
314
+ AppSecurityKey : api .AppSecurityKey .String (),
315
+ })
316
+ }
0 commit comments