@@ -1777,6 +1777,13 @@ func (q *querier) EnqueueNotificationMessage(ctx context.Context, arg database.E
1777
1777
return q .db .EnqueueNotificationMessage (ctx ,arg )
1778
1778
}
1779
1779
1780
+ func (q * querier )ExpirePrebuildsAPIKeys (ctx context.Context ,now time.Time )error {
1781
+ if err := q .authorizeContext (ctx ,policy .ActionDelete ,rbac .ResourceApiKey );err != nil {
1782
+ return err
1783
+ }
1784
+ return q .db .ExpirePrebuildsAPIKeys (ctx ,now )
1785
+ }
1786
+
1780
1787
func (q * querier )FavoriteWorkspace (ctx context.Context ,id uuid.UUID )error {
1781
1788
fetch := func (ctx context.Context ,id uuid.UUID ) (database.Workspace ,error ) {
1782
1789
return q .db .GetWorkspaceByID (ctx ,id )
@@ -2242,14 +2249,6 @@ func (q *querier) GetLogoURL(ctx context.Context) (string, error) {
2242
2249
return q .db .GetLogoURL (ctx )
2243
2250
}
2244
2251
2245
- func (q * querier )GetManagedAgentCount (ctx context.Context ,arg database.GetManagedAgentCountParams ) (int64 ,error ) {
2246
- // Must be able to read all workspaces to check usage.
2247
- if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceWorkspace );err != nil {
2248
- return 0 ,xerrors .Errorf ("authorize read all workspaces: %w" ,err )
2249
- }
2250
- return q .db .GetManagedAgentCount (ctx ,arg )
2251
- }
2252
-
2253
2252
func (q * querier )GetNotificationMessagesByStatus (ctx context.Context ,arg database.GetNotificationMessagesByStatusParams ) ([]database.NotificationMessage ,error ) {
2254
2253
if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceNotificationMessage );err != nil {
2255
2254
return nil ,err
@@ -2689,6 +2688,13 @@ func (q *querier) GetQuotaConsumedForUser(ctx context.Context, params database.G
2689
2688
return q .db .GetQuotaConsumedForUser (ctx ,params )
2690
2689
}
2691
2690
2691
+ func (q * querier )GetRegularWorkspaceCreateMetrics (ctx context.Context ) ([]database.GetRegularWorkspaceCreateMetricsRow ,error ) {
2692
+ if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceWorkspace .All ());err != nil {
2693
+ return nil ,err
2694
+ }
2695
+ return q .db .GetRegularWorkspaceCreateMetrics (ctx )
2696
+ }
2697
+
2692
2698
func (q * querier )GetReplicaByID (ctx context.Context ,id uuid.UUID ) (database.Replica ,error ) {
2693
2699
if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceSystem );err != nil {
2694
2700
return database.Replica {},err
@@ -3041,6 +3047,13 @@ func (q *querier) GetTemplatesWithFilter(ctx context.Context, arg database.GetTe
3041
3047
return q .db .GetAuthorizedTemplates (ctx ,arg ,prep )
3042
3048
}
3043
3049
3050
+ func (q * querier )GetTotalUsageDCManagedAgentsV1 (ctx context.Context ,arg database.GetTotalUsageDCManagedAgentsV1Params ) (int64 ,error ) {
3051
+ if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceUsageEvent );err != nil {
3052
+ return 0 ,err
3053
+ }
3054
+ return q .db .GetTotalUsageDCManagedAgentsV1 (ctx ,arg )
3055
+ }
3056
+
3044
3057
func (q * querier )GetUnexpiredLicenses (ctx context.Context ) ([]database.License ,error ) {
3045
3058
if err := q .authorizeContext (ctx ,policy .ActionRead ,rbac .ResourceLicense );err != nil {
3046
3059
return nil ,err
@@ -3711,6 +3724,14 @@ func (q *querier) GetWorkspacesEligibleForTransition(ctx context.Context, now ti
3711
3724
}
3712
3725
3713
3726
func (q * querier )InsertAPIKey (ctx context.Context ,arg database.InsertAPIKeyParams ) (database.APIKey ,error ) {
3727
+ // TODO(Cian): ideally this would be encoded in the policy, but system users are just members and we
3728
+ // don't currently have a capability to conditionally deny creating resources by owner ID in a role.
3729
+ // We also need to enrich rbac.Actor with IsSystem so that we can distinguish all system users.
3730
+ // For now, there is only one system user (prebuilds).
3731
+ if act ,ok := ActorFromContext (ctx );ok && act .ID == database .PrebuildsSystemUserID .String () {
3732
+ return database.APIKey {},logNotAuthorizedError (ctx ,q .log ,NotAuthorizedError {Err :xerrors .Errorf ("prebuild user may not create api keys" )})
3733
+ }
3734
+
3714
3735
return insert (q .log ,q .auth ,
3715
3736
rbac .ResourceApiKey .WithOwner (arg .UserID .String ()),
3716
3737
q .db .InsertAPIKey )(ctx ,arg )