Skip to content

Commit c94c470

Browse files
authored
fix: pass context with authorization to agentapi (#21045)
cherry pick 20959 into release branch Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 8430dd6 commit c94c470

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

coderd/agentapi/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Options struct {
6969
WorkspaceID uuid.UUID
7070
OrganizationID uuid.UUID
7171

72-
Ctx context.Context
72+
AuthenticatedCtx context.Context
7373
Log slog.Logger
7474
Clock quartz.Clock
7575
Database database.Store
@@ -220,7 +220,7 @@ func New(opts Options, workspace database.Workspace) *API {
220220

221221
// Start background cache refresh loop to handle workspace changes
222222
// like prebuild claims where owner_id and other fields may be modified in the DB.
223-
go api.startCacheRefreshLoop(opts.Ctx)
223+
go api.startCacheRefreshLoop(opts.AuthenticatedCtx)
224224

225225
return api
226226
}

coderd/agentapi/metadata_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,15 @@ func TestBatchUpdateMetadata(t *testing.T) {
671671

672672
// Create full API with cached workspace fields (initial state)
673673
api := agentapi.New(agentapi.Options{
674-
Ctx: ctxWithActor,
675-
AgentID: agentID,
676-
WorkspaceID: workspaceID,
677-
OwnerID: ownerID,
678-
OrganizationID: orgID,
679-
Database: dbauthz.New(dbM, auth, testutil.Logger(t), accessControlStore),
680-
Log: testutil.Logger(t),
681-
Clock: mClock,
682-
Pubsub: pub,
674+
AuthenticatedCtx: ctxWithActor,
675+
AgentID: agentID,
676+
WorkspaceID: workspaceID,
677+
OwnerID: ownerID,
678+
OrganizationID: orgID,
679+
Database: dbauthz.New(dbM, auth, testutil.Logger(t), accessControlStore),
680+
Log: testutil.Logger(t),
681+
Clock: mClock,
682+
Pubsub: pub,
683683
}, initialWorkspace) // Cache is initialized with 9am schedule and "my-workspace" name
684684

685685
// Wait for ticker to be set up and release it so it can fire

coderd/workspaceagentsrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (api *API) workspaceAgentRPC(rw http.ResponseWriter, r *http.Request) {
132132
WorkspaceID: workspace.ID,
133133
OrganizationID: workspace.OrganizationID,
134134

135-
Ctx: api.ctx,
135+
AuthenticatedCtx: ctx,
136136
Log: logger,
137137
Clock: api.Clock,
138138
Database: api.Database,

0 commit comments

Comments
 (0)