@@ -251,12 +251,6 @@ func (q *querier) GetProvisionerJobByID(ctx context.Context, id uuid.UUID) (data
251
251
return job ,nil
252
252
}
253
253
254
- func (q * querier )GetProvisionerJobsByIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.ProvisionerJob ,error ) {
255
- // TODO: This is missing authorization and is incorrect. This call is used by telemetry, and by 1 http route.
256
- // That http handler should find a better way to fetch these jobs with easier rbac authz.
257
- return q .db .GetProvisionerJobsByIDs (ctx ,ids )
258
- }
259
-
260
254
func (q * querier )GetProvisionerLogsByIDBetween (ctx context.Context ,arg database.GetProvisionerLogsByIDBetweenParams ) ([]database.ProvisionerJobLog ,error ) {
261
255
// Authorized read on job lets the actor also read the logs.
262
256
_ ,err := q .GetProvisionerJobByID (ctx ,arg .JobID )
@@ -725,35 +719,6 @@ func (q *querier) GetTemplateVersionVariables(ctx context.Context, templateVersi
725
719
return q .db .GetTemplateVersionVariables (ctx ,templateVersionID )
726
720
}
727
721
728
- func (q * querier )GetTemplateVersionsByIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.TemplateVersion ,error ) {
729
- // TODO: This is so inefficient
730
- versions ,err := q .db .GetTemplateVersionsByIDs (ctx ,ids )
731
- if err != nil {
732
- return nil ,err
733
- }
734
- checked := make (map [uuid.UUID ]bool )
735
- for _ ,v := range versions {
736
- if _ ,ok := checked [v .TemplateID .UUID ];ok {
737
- continue
738
- }
739
-
740
- obj := v .RBACObjectNoTemplate ()
741
- template ,err := q .db .GetTemplateByID (ctx ,v .TemplateID .UUID )
742
- if err == nil {
743
- obj = v .RBACObject (template )
744
- }
745
- if err != nil && ! xerrors .Is (err ,sql .ErrNoRows ) {
746
- return nil ,err
747
- }
748
- if err := q .authorizeContext (ctx ,rbac .ActionRead ,obj );err != nil {
749
- return nil ,err
750
- }
751
- checked [v .TemplateID .UUID ]= true
752
- }
753
-
754
- return versions ,nil
755
- }
756
-
757
722
func (q * querier )GetTemplateVersionsByTemplateID (ctx context.Context ,arg database.GetTemplateVersionsByTemplateIDParams ) ([]database.TemplateVersion ,error ) {
758
723
// An actor can read template versions if they can read the related template.
759
724
template ,err := q .db .GetTemplateByID (ctx ,arg .TemplateID )
@@ -1013,11 +978,6 @@ func (q *querier) GetUsersWithCount(ctx context.Context, arg database.GetUsersPa
1013
978
return users ,rowUsers [0 ].Count ,nil
1014
979
}
1015
980
1016
- // TODO: Remove this and use a filter on GetUsers
1017
- func (q * querier )GetUsersByIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.User ,error ) {
1018
- return fetchWithPostFilter (q .auth ,q .db .GetUsersByIDs )(ctx ,ids )
1019
- }
1020
-
1021
981
func (q * querier )InsertUser (ctx context.Context ,arg database.InsertUserParams ) (database.User ,error ) {
1022
982
// Always check if the assigned roles can actually be assigned by this actor.
1023
983
impliedRoles := append ([]string {rbac .RoleMember ()},arg .RBACRoles ... )
@@ -1219,37 +1179,6 @@ func (q *querier) GetWorkspaceAgentByInstanceID(ctx context.Context, authInstanc
1219
1179
return agent ,nil
1220
1180
}
1221
1181
1222
- // GetWorkspaceAgentsByResourceIDs is an all or nothing call. If the user cannot read
1223
- // a single agent, the entire call will fail.
1224
- func (q * querier )GetWorkspaceAgentsByResourceIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.WorkspaceAgent ,error ) {
1225
- if _ ,ok := ActorFromContext (ctx );! ok {
1226
- return nil ,NoActorError
1227
- }
1228
- // TODO: Make this more efficient. This is annoying because all these resources should be owned by the same workspace.
1229
- // So the authz check should just be 1 check, but we cannot do that easily here. We should see if all callers can
1230
- // instead do something like GetWorkspaceAgentsByWorkspaceID.
1231
- agents ,err := q .db .GetWorkspaceAgentsByResourceIDs (ctx ,ids )
1232
- if err != nil {
1233
- return nil ,err
1234
- }
1235
-
1236
- for _ ,a := range agents {
1237
- // Check if we can fetch the workspace by the agent ID.
1238
- _ ,err := q .GetWorkspaceByAgentID (ctx ,a .ID )
1239
- if err == nil {
1240
- continue
1241
- }
1242
- if errors .Is (err ,sql .ErrNoRows )&& ! errors .As (err ,& NotAuthorizedError {}) {
1243
- // The agent is not tied to a workspace, likely from an orphaned template version.
1244
- // Just return it.
1245
- continue
1246
- }
1247
- // Otherwise, we cannot read the workspace, so we cannot read the agent.
1248
- return nil ,err
1249
- }
1250
- return agents ,nil
1251
- }
1252
-
1253
1182
func (q * querier )UpdateWorkspaceAgentLifecycleStateByID (ctx context.Context ,arg database.UpdateWorkspaceAgentLifecycleStateByIDParams )error {
1254
1183
agent ,err := q .db .GetWorkspaceAgentByID (ctx ,arg .ID )
1255
1184
if err != nil {
@@ -1302,20 +1231,6 @@ func (q *querier) GetWorkspaceAppsByAgentID(ctx context.Context, agentID uuid.UU
1302
1231
return q .db .GetWorkspaceAppsByAgentID (ctx ,agentID )
1303
1232
}
1304
1233
1305
- // GetWorkspaceAppsByAgentIDs is an all or nothing call. If the user cannot read a single app, the entire call will fail.
1306
- func (q * querier )GetWorkspaceAppsByAgentIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.WorkspaceApp ,error ) {
1307
- // TODO: This should be reworked. All these apps are likely owned by the same workspace, so we should be able to
1308
- // do 1 authz call. We should refactor this to be GetWorkspaceAppsByWorkspaceID.
1309
- for _ ,id := range ids {
1310
- _ ,err := q .GetWorkspaceAgentByID (ctx ,id )
1311
- if err != nil {
1312
- return nil ,err
1313
- }
1314
- }
1315
-
1316
- return q .db .GetWorkspaceAppsByAgentIDs (ctx ,ids )
1317
- }
1318
-
1319
1234
func (q * querier )GetWorkspaceBuildByID (ctx context.Context ,buildID uuid.UUID ) (database.WorkspaceBuild ,error ) {
1320
1235
return fetch (q .log ,q .auth ,q .db .GetWorkspaceBuildByID )(ctx ,buildID )
1321
1236
}
@@ -1373,21 +1288,6 @@ func (q *querier) GetWorkspaceResourceByID(ctx context.Context, id uuid.UUID) (d
1373
1288
return resource ,nil
1374
1289
}
1375
1290
1376
- // GetWorkspaceResourceMetadataByResourceIDs is an all or nothing call. If a single resource is not authorized, then
1377
- // an error is returned.
1378
- func (q * querier )GetWorkspaceResourceMetadataByResourceIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.WorkspaceResourceMetadatum ,error ) {
1379
- // TODO: This is very inefficient. Since all these resources are likely asscoiated with the same workspace.
1380
- for _ ,id := range ids {
1381
- // If we can read the resource, we can read the metadata.
1382
- _ ,err := q .GetWorkspaceResourceByID (ctx ,id )
1383
- if err != nil {
1384
- return nil ,err
1385
- }
1386
- }
1387
-
1388
- return q .db .GetWorkspaceResourceMetadataByResourceIDs (ctx ,ids )
1389
- }
1390
-
1391
1291
func (q * querier )GetWorkspaceResourcesByJobID (ctx context.Context ,jobID uuid.UUID ) ([]database.WorkspaceResource ,error ) {
1392
1292
job ,err := q .db .GetProvisionerJobByID (ctx ,jobID )
1393
1293
if err != nil {
@@ -1433,21 +1333,6 @@ func (q *querier) GetWorkspaceResourcesByJobID(ctx context.Context, jobID uuid.U
1433
1333
return q .db .GetWorkspaceResourcesByJobID (ctx ,jobID )
1434
1334
}
1435
1335
1436
- // GetWorkspaceResourcesByJobIDs is an all or nothing call. If a single resource is not authorized, then
1437
- // an error is returned.
1438
- func (q * querier )GetWorkspaceResourcesByJobIDs (ctx context.Context ,ids []uuid.UUID ) ([]database.WorkspaceResource ,error ) {
1439
- // TODO: This is very inefficient. Since all these resources are likely asscoiated with the same workspace.
1440
- for _ ,id := range ids {
1441
- // If we can read the resource, we can read the metadata.
1442
- _ ,err := q .GetProvisionerJobByID (ctx ,id )
1443
- if err != nil {
1444
- return nil ,err
1445
- }
1446
- }
1447
-
1448
- return q .db .GetWorkspaceResourcesByJobIDs (ctx ,ids )
1449
- }
1450
-
1451
1336
func (q * querier )InsertWorkspace (ctx context.Context ,arg database.InsertWorkspaceParams ) (database.Workspace ,error ) {
1452
1337
obj := rbac .ResourceWorkspace .WithOwner (arg .OwnerID .String ()).InOrg (arg .OrganizationID )
1453
1338
return insert (q .log ,q .auth ,obj ,q .db .InsertWorkspace )(ctx ,arg )