Skip to content

Commit 23ef17e

Browse files
Emyrkdannykopping
andauthored
chore: refactor entry into deployment and runtime (#14575)
* chore: refactor entry into deployment and runtime RuntimeEntry has no startup value, and omits functions required to be serpent compatible. Co-authored-by: Danny Kopping <danny@coder.com> --------- Co-authored-by: Danny Kopping <danny@coder.com>
1 parent 5ccbe52 commit 23ef17e

File tree

12 files changed

+519
-472
lines changed

12 files changed

+519
-472
lines changed

cli/server.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
821821
return err
822822
}
823823

824-
// TODO: Throw a caching layer infront of the RuntimeConfig to prevent
825-
// excessive database queries.
826-
// Note: This happens before dbauthz, which is really unfortunate.
827-
// dbauthz is configured in `Coderd.New()`, but we need the manager
828-
// at this level for notifications. We might have to move some init
829-
// code around.
830-
options.RuntimeConfig = runtimeconfig.NewStoreManager(options.Database)
824+
options.RuntimeConfig = runtimeconfig.NewStoreManager()
831825

832826
// This should be output before the logs start streaming.
833827
cliui.Infof(inv.Stdout, "\n==> Logs will stream in below (press ctrl+c to gracefully exit):")

coderd/coderdtest/coderdtest.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
255255
var acs dbauthz.AccessControlStore = dbauthz.AGPLTemplateAccessControlStore{}
256256
accessControlStore.Store(&acs)
257257

258-
// runtimeManager does not use dbauthz.
259-
// TODO: It probably should, but the init code for prod happens before dbauthz
260-
// is ready.
261-
runtimeManager := runtimeconfig.NewStoreManager(options.Database)
258+
runtimeManager := runtimeconfig.NewStoreManager()
262259
options.Database = dbauthz.New(options.Database, options.Authorizer, *options.Logger, accessControlStore)
263260

264261
// Some routes expect a deployment ID, so just make sure one exists.

coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,9 @@ func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt tim
11841184
}
11851185

11861186
func (q *querier) DeleteRuntimeConfig(ctx context.Context, key string) error {
1187-
// TODO: auth
1187+
if err := q.authorizeContext(ctx, policy.ActionDelete, rbac.ResourceSystem); err != nil {
1188+
return err
1189+
}
11881190
return q.db.DeleteRuntimeConfig(ctx, key)
11891191
}
11901192

@@ -1862,7 +1864,9 @@ func (q *querier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Ti
18621864
}
18631865

18641866
func (q *querier) GetRuntimeConfig(ctx context.Context, key string) (string, error) {
1865-
// TODO: auth
1867+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
1868+
return "", err
1869+
}
18661870
return q.db.GetRuntimeConfig(ctx, key)
18671871
}
18681872

@@ -3917,7 +3921,9 @@ func (q *querier) UpsertProvisionerDaemon(ctx context.Context, arg database.Upse
39173921
}
39183922

39193923
func (q *querier) UpsertRuntimeConfig(ctx context.Context, arg database.UpsertRuntimeConfigParams) error {
3920-
// TODO: auth
3924+
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceSystem); err != nil {
3925+
return err
3926+
}
39213927
return q.db.UpsertRuntimeConfig(ctx, arg)
39223928
}
39233929

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,6 +2696,22 @@ func (s *MethodTestSuite) TestSystemFunctions() {
26962696
AgentID: uuid.New(),
26972697
}).Asserts(tpl, policy.ActionCreate)
26982698
}))
2699+
s.Run("DeleteRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
2700+
check.Args("test").Asserts(rbac.ResourceSystem, policy.ActionDelete)
2701+
}))
2702+
s.Run("GetRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
2703+
_ = db.UpsertRuntimeConfig(context.Background(), database.UpsertRuntimeConfigParams{
2704+
Key: "test",
2705+
Value: "value",
2706+
})
2707+
check.Args("test").Asserts(rbac.ResourceSystem, policy.ActionRead)
2708+
}))
2709+
s.Run("UpsertRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
2710+
check.Args(database.UpsertRuntimeConfigParams{
2711+
Key: "test",
2712+
Value: "value",
2713+
}).Asserts(rbac.ResourceSystem, policy.ActionCreate)
2714+
}))
26992715
}
27002716

27012717
func (s *MethodTestSuite) TestNotifications() {

coderd/runtimeconfig/config.go

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy