Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97080a5

Browse files
committed
make gen impl
1 parentafd0d84 commit97080a5

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
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+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceWorkspaceAgentResourceMonitor);err!=nil {
1446+
returnnil,err
1447+
}
1448+
1449+
returnq.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+
iferr:=q.authorizeContext(ctx,policy.ActionRead,rbac.ResourceWorkspaceAgentResourceMonitor);err!=nil {
1478+
returnnil,err
1479+
}
1480+
1481+
returnq.db.FetchVolumesResourceMonitorsCreatedAfter(ctx,createdAt)
14681482
}
14691483

14701484
func (q*querier)GetAPIKeyByID(ctx context.Context,idstring) (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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,19 @@ func (q *FakeQuerier) FetchMemoryResourceMonitorsByAgentID(_ context.Context, ag
23912391
return database.WorkspaceAgentMemoryResourceMonitor{},sql.ErrNoRows
23922392
}
23932393

2394+
func (q*FakeQuerier)FetchMemoryResourceMonitorsCreatedAfter(_ context.Context,createdAt time.Time) ([]database.WorkspaceAgentMemoryResourceMonitor,error) {
2395+
q.mutex.RLock()
2396+
deferq.mutex.RUnlock()
2397+
2398+
monitors:= []database.WorkspaceAgentMemoryResourceMonitor{}
2399+
for_,monitor:=rangeq.workspaceAgentMemoryResourceMonitors {
2400+
ifmonitor.CreatedAt.After(createdAt) {
2401+
monitors=append(monitors,monitor)
2402+
}
2403+
}
2404+
returnmonitors,nil
2405+
}
2406+
23942407
func (q*FakeQuerier)FetchNewMessageMetadata(_ context.Context,arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow,error) {
23952408
err:=validateDatabaseType(arg)
23962409
iferr!=nil {
@@ -2435,6 +2448,19 @@ func (q *FakeQuerier) FetchVolumesResourceMonitorsByAgentID(_ context.Context, a
24352448
returnmonitors,nil
24362449
}
24372450

2451+
func (q*FakeQuerier)FetchVolumesResourceMonitorsCreatedAfter(_ context.Context,createdAt time.Time) ([]database.WorkspaceAgentVolumeResourceMonitor,error) {
2452+
q.mutex.RLock()
2453+
deferq.mutex.RUnlock()
2454+
2455+
monitors:= []database.WorkspaceAgentVolumeResourceMonitor{}
2456+
for_,monitor:=rangeq.workspaceAgentVolumeResourceMonitors {
2457+
ifmonitor.CreatedAt.After(createdAt) {
2458+
monitors=append(monitors,monitor)
2459+
}
2460+
}
2461+
returnmonitors,nil
2462+
}
2463+
24382464
func (q*FakeQuerier)GetAPIKeyByID(_ context.Context,idstring) (database.APIKey,error) {
24392465
q.mutex.RLock()
24402466
deferq.mutex.RUnlock()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp