handleResumeToken accepts a resume_token query parameter to use the same peer ID
(ctx context.Context, rw http.ResponseWriter, r *http.Request)
| 1392 | |
| 1393 | // handleResumeToken accepts a resume_token query parameter to use the same peer ID |
| 1394 | func (api *API) handleResumeToken(ctx context.Context, rw http.ResponseWriter, r *http.Request) (peerID uuid.UUID, err error) { |
| 1395 | peerID = uuid.New() |
| 1396 | resumeToken := r.URL.Query().Get("resume_token") |
| 1397 | if resumeToken != "" { |
| 1398 | peerID, err = api.Options.CoordinatorResumeTokenProvider.VerifyResumeToken(ctx, resumeToken) |
| 1399 | // If the token is missing the key ID, it's probably an old token in which |
| 1400 | // case we just want to generate a new peer ID. |
| 1401 | switch { |
| 1402 | case xerrors.Is(err, jwtutils.ErrMissingKeyID): |
| 1403 | peerID = uuid.New() |
| 1404 | err = nil |
| 1405 | case err != nil: |
| 1406 | httpapi.Write(ctx, rw, http.StatusUnauthorized, codersdk.Response{ |
| 1407 | Message: workspacesdk.CoordinateAPIInvalidResumeToken, |
| 1408 | Detail: err.Error(), |
| 1409 | Validations: []codersdk.ValidationError{ |
| 1410 | {Field: "resume_token", Detail: workspacesdk.CoordinateAPIInvalidResumeToken}, |
| 1411 | }, |
| 1412 | }) |
| 1413 | return peerID, err |
| 1414 | default: |
| 1415 | api.Logger.Debug(ctx, "accepted coordinate resume token for peer", |
| 1416 | slog.F("peer_id", peerID.String())) |
| 1417 | } |
| 1418 | } |
| 1419 | return peerID, err |
| 1420 | } |
| 1421 | |
| 1422 | // @Summary Post workspace agent log source |
| 1423 | // @ID post-workspace-agent-log-source |