Skip to content

chore: refactor entry into deployment and runtime #14575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
return err
}

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

// This should be output before the logs start streaming.
cliui.Infof(inv.Stdout, "\n==> Logs will stream in below (press ctrl+c to gracefully exit):")
Expand Down
5 changes: 1 addition & 4 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
var acs dbauthz.AccessControlStore = dbauthz.AGPLTemplateAccessControlStore{}
accessControlStore.Store(&acs)

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

// Some routes expect a deployment ID, so just make sure one exists.
Expand Down
12 changes: 9 additions & 3 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,9 @@ func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt tim
}

func (q *querier) DeleteRuntimeConfig(ctx context.Context, key string) error {
// TODO: auth
if err := q.authorizeContext(ctx, policy.ActionDelete, rbac.ResourceSystem); err != nil {
return err
}
return q.db.DeleteRuntimeConfig(ctx, key)
}

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

func (q *querier) GetRuntimeConfig(ctx context.Context, key string) (string, error) {
// TODO: auth
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceSystem); err != nil {
return "", err
}
return q.db.GetRuntimeConfig(ctx, key)
}

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

func (q *querier) UpsertRuntimeConfig(ctx context.Context, arg database.UpsertRuntimeConfigParams) error {
// TODO: auth
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceSystem); err != nil {
return err
}
return q.db.UpsertRuntimeConfig(ctx, arg)
}

Expand Down
16 changes: 16 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,22 @@ func (s *MethodTestSuite) TestSystemFunctions() {
AgentID: uuid.New(),
}).Asserts(tpl, policy.ActionCreate)
}))
s.Run("DeleteRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
check.Args("test").Asserts(rbac.ResourceSystem, policy.ActionDelete)
}))
s.Run("GetRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
_ = db.UpsertRuntimeConfig(context.Background(), database.UpsertRuntimeConfigParams{
Key: "test",
Value: "value",
})
check.Args("test").Asserts(rbac.ResourceSystem, policy.ActionRead)
}))
s.Run("UpsertRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
check.Args(database.UpsertRuntimeConfigParams{
Key: "test",
Value: "value",
}).Asserts(rbac.ResourceSystem, policy.ActionCreate)
}))
}

func (s *MethodTestSuite) TestNotifications() {
Expand Down
161 changes: 0 additions & 161 deletions coderd/runtimeconfig/config.go

This file was deleted.

Loading
Loading