mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
Removes the Tasks API and task orchestration from coderd and codersdk: the `/api/v2/tasks` handlers, task middleware and search filters, task name generation, autobuild pause/resume logic, task notification enqueues, telemetry, and the codersdk task types. Regenerates apidoc, the API reference docs, and `typesGenerated.ts`. **Breaking change:** the Tasks API is removed; requests to `/api/v2/tasks` fail. Tasks was deprecated in v2.34. **Stack context:** Coder Tasks removal stack (CODAGT-642): #28743 frontend → #28788 CLI → #28789 API → #28790 provisioner → #29084 notifications → #29085 build reasons → #29086 tables → #28750 permissions. The last four PRs replace the single data-drop migration that used to live in #28750; each carries one concern and its own migration number. **Why:** with the UI (#28743) and CLI (#28788) gone, this deletes the server surface. Database tables, RBAC, and notification templates stay until the top of the stack so every layer builds and migrates independently. **What to scrutinize:** - The `enable-ai-tasks` option is removed outright (review feedback): configs still carrying `enableAITasks` fail to parse until the key is deleted. - provisionerdserver now writes `HasAITask: false` on template/build flags; the column and these lines are dropped in #29085. - `codersdk.ResourceTypeTask` stays so audit logs recorded before the removal keep rendering. **Validation:** `go build ./...`, `go vet ./...`, `go test ./codersdk/...`, site biome and tsc, CLI goldens regenerated, pre-commit hooks. **Size:** +242/-10,792 over 76 files; additions are regenerated docs/goldens and test fixture updates. > Created by Xum (AI agent) on behalf of @ibetitsmike.
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
package agentapi
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
|
)
|
|
|
|
// CachedWorkspaceFields contains workspace data that is safe to cache for the
|
|
// duration of an agent connection. These fields are used to reduce database calls
|
|
// in high-frequency operations like stats reporting and metadata updates.
|
|
// Prebuild workspaces should not be cached using this struct within the API struct,
|
|
// however some of these fields for a workspace can be updated live so there is a
|
|
// routine in the API for refreshing the workspace on a timed interval.
|
|
//
|
|
// IMPORTANT: ACL fields (GroupACL, UserACL) are NOT cached because they can be
|
|
// modified in the database and we must use fresh data for authorization checks.
|
|
type CachedWorkspaceFields struct {
|
|
lock sync.RWMutex
|
|
|
|
identity database.WorkspaceIdentity
|
|
}
|
|
|
|
func (cws *CachedWorkspaceFields) Clear() {
|
|
cws.lock.Lock()
|
|
defer cws.lock.Unlock()
|
|
cws.identity = database.WorkspaceIdentity{}
|
|
}
|
|
|
|
func (cws *CachedWorkspaceFields) UpdateValues(ws database.Workspace) {
|
|
cws.lock.Lock()
|
|
defer cws.lock.Unlock()
|
|
cws.identity.ID = ws.ID
|
|
cws.identity.OwnerID = ws.OwnerID
|
|
cws.identity.OrganizationID = ws.OrganizationID
|
|
cws.identity.TemplateID = ws.TemplateID
|
|
cws.identity.Name = ws.Name
|
|
cws.identity.OwnerUsername = ws.OwnerUsername
|
|
cws.identity.TemplateName = ws.TemplateName
|
|
cws.identity.AutostartSchedule = ws.AutostartSchedule
|
|
}
|
|
|
|
// Returns the Workspace, true, unless the workspace has not been cached (nuked or was a prebuild).
|
|
func (cws *CachedWorkspaceFields) AsWorkspaceIdentity() (database.WorkspaceIdentity, bool) {
|
|
cws.lock.RLock()
|
|
defer cws.lock.RUnlock()
|
|
// Should we be more explicit about all fields being set to be valid?
|
|
if cws.identity.Equal(database.WorkspaceIdentity{}) {
|
|
return database.WorkspaceIdentity{}, false
|
|
}
|
|
return cws.identity, true
|
|
}
|
|
|
|
// ContextInject attempts to inject the rbac object for the cached workspace fields
|
|
// into the given context, either returning the wrapped context or the original.
|
|
func (cws *CachedWorkspaceFields) ContextInject(ctx context.Context) (context.Context, error) {
|
|
var err error
|
|
rbacCtx := ctx
|
|
if dbws, ok := cws.AsWorkspaceIdentity(); ok {
|
|
rbacCtx, err = dbauthz.WithWorkspaceRBAC(ctx, dbws.RBACObject())
|
|
if err != nil {
|
|
// Don't error level log here, will exit the function. We want to fall back to GetWorkspaceByAgentID.
|
|
//nolint:gocritic
|
|
return ctx, xerrors.Errorf("Cached workspace was present but RBAC object was invalid: %w", err)
|
|
}
|
|
}
|
|
return rbacCtx, nil
|
|
}
|