Skip to content

Commit 96a37bb

Browse files
committed
make gen impl
1 parent d98cbb1 commit 96a37bb

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,14 @@ func (q *querier) FetchMemoryResourceMonitorsByAgentID(ctx context.Context, agen
14391439
}
14401440

14411441
func (q *querier) FetchMemoryResourceMonitorsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.WorkspaceAgentMemoryResourceMonitor, error) {
1442-
panic("not implemented")
1442+
// Ideally, we would return a list of monitors that the user has access to. However, that check would need to
1443+
// be implemented similarly to GetWorkspaces, which is more complex than what we're doing here. Since this query
1444+
// was introduced for telemetry, we perform a simpler check.
1445+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspaceAgentResourceMonitor); err != nil {
1446+
return nil, err
1447+
}
1448+
1449+
return q.db.FetchMemoryResourceMonitorsCreatedAfter(ctx, createdAt)
14431450
}
14441451

14451452
func (q *querier) FetchNewMessageMetadata(ctx context.Context, arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow, error) {
@@ -1464,7 +1471,14 @@ func (q *querier) FetchVolumesResourceMonitorsByAgentID(ctx context.Context, age
14641471
}
14651472

14661473
func (q *querier) FetchVolumesResourceMonitorsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
1467-
panic("not implemented")
1474+
// Ideally, we would return a list of monitors that the user has access to. However, that check would need to
1475+
// be implemented similarly to GetWorkspaces, which is more complex than what we're doing here. Since this query
1476+
// was introduced for telemetry, we perform a simpler check.
1477+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspaceAgentResourceMonitor); err != nil {
1478+
return nil, err
1479+
}
1480+
1481+
return q.db.FetchVolumesResourceMonitorsCreatedAfter(ctx, createdAt)
14681482
}
14691483

14701484
func (q *querier) GetAPIKeyByID(ctx context.Context, id string) (database.APIKey, error) {

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,6 +4919,14 @@ func (s *MethodTestSuite) TestResourcesMonitor() {
49194919
}).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor, policy.ActionUpdate)
49204920
}))
49214921

4922+
s.Run("FetchMemoryResourceMonitorsCreatedAfter", s.Subtest(func(db database.Store, check *expects) {
4923+
check.Args(dbtime.Now()).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor, policy.ActionRead)
4924+
}))
4925+
4926+
s.Run("FetchVolumesResourceMonitorsCreatedAfter", s.Subtest(func(db database.Store, check *expects) {
4927+
check.Args(dbtime.Now()).Asserts(rbac.ResourceWorkspaceAgentResourceMonitor, policy.ActionRead)
4928+
}))
4929+
49224930
s.Run("FetchMemoryResourceMonitorsByAgentID", s.Subtest(func(db database.Store, check *expects) {
49234931
agt, w := createAgent(s.T(), db)
49244932

coderd/database/dbmem/dbmem.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,16 @@ func (q *FakeQuerier) FetchMemoryResourceMonitorsByAgentID(_ context.Context, ag
23922392
}
23932393

23942394
func (q *FakeQuerier) FetchMemoryResourceMonitorsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.WorkspaceAgentMemoryResourceMonitor, error) {
2395-
panic("not implemented")
2395+
q.mutex.RLock()
2396+
defer q.mutex.RUnlock()
2397+
2398+
monitors := []database.WorkspaceAgentMemoryResourceMonitor{}
2399+
for _, monitor := range q.workspaceAgentMemoryResourceMonitors {
2400+
if monitor.CreatedAt.After(createdAt) {
2401+
monitors = append(monitors, monitor)
2402+
}
2403+
}
2404+
return monitors, nil
23962405
}
23972406

23982407
func (q *FakeQuerier) FetchNewMessageMetadata(_ context.Context, arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow, error) {
@@ -2440,7 +2449,16 @@ func (q *FakeQuerier) FetchVolumesResourceMonitorsByAgentID(_ context.Context, a
24402449
}
24412450

24422451
func (q *FakeQuerier) FetchVolumesResourceMonitorsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
2443-
panic("not implemented")
2452+
q.mutex.RLock()
2453+
defer q.mutex.RUnlock()
2454+
2455+
monitors := []database.WorkspaceAgentVolumeResourceMonitor{}
2456+
for _, monitor := range q.workspaceAgentVolumeResourceMonitors {
2457+
if monitor.CreatedAt.After(createdAt) {
2458+
monitors = append(monitors, monitor)
2459+
}
2460+
}
2461+
return monitors, nil
24442462
}
24452463

24462464
func (q *FakeQuerier) GetAPIKeyByID(_ context.Context, id string) (database.APIKey, error) {

0 commit comments

Comments
 (0)