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 1 commit
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
Prev Previous commit
Next Next commit
fixups
  • Loading branch information
Emyrk committed Sep 5, 2024
commit f0ce1c4bf1efe947bdb0d5b4faa48eac12027d0d
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
9 changes: 9 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,15 @@ 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) {
check.Args("test").Asserts(rbac.ResourceSystem, policy.ActionRead)
}))
s.Run("UpsertRuntimeConfig", s.Subtest(func(db database.Store, check *expects) {
check.Args("test", "value").Asserts(rbac.ResourceSystem, policy.ActionUpdate)
}))
}

func (s *MethodTestSuite) TestNotifications() {
Expand Down
6 changes: 4 additions & 2 deletions coderd/runtimeconfig/deploymententry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
)

// Ensure serpent values satisfy the ConfigValue interface for easier usage.
var _ pflag.Value = SerpentEntry(nil)
var _ pflag.Value = &DeploymentEntry[SerpentEntry]{}
var (
_ pflag.Value = SerpentEntry(nil)
_ pflag.Value = &DeploymentEntry[SerpentEntry]{}
)

type SerpentEntry interface {
EntryValue
Expand Down
7 changes: 3 additions & 4 deletions coderd/runtimeconfig/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import (
)

// StoreManager is the shared singleton that produces resolvers for runtime configuration.
type StoreManager struct {
}
type StoreManager struct{}

func NewStoreManager() Manager {
return &StoreManager{}
}

func (m *StoreManager) DeploymentResolver(db Store) Resolver {
func (*StoreManager) DeploymentResolver(db Store) Resolver {
return NewStoreResolver(db)
}

func (m *StoreManager) OrganizationResolver(db Store, orgID uuid.UUID) Resolver {
func (*StoreManager) OrganizationResolver(db Store, orgID uuid.UUID) Resolver {
return OrganizationResolver(orgID, NewStoreResolver(db))
}

Expand Down
Loading