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

DNM: example runtime config usage#14561

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
ad9e515
Implementation
dannykoppingAug 28, 2024
f95572b
Support zero values
dannykoppingSep 3, 2024
d92ba9c
Add database queries against site_configs
dannykoppingSep 3, 2024
6e8751b
Document usage in test
dannykoppingSep 3, 2024
d832a49
Touchups
dannykoppingSep 3, 2024
ceb7ae7
make gen to generate dbmock functions
EmyrkSep 3, 2024
8b5942c
make lint/fmt
dannykoppingSep 4, 2024
355afdc
Initializer interface, rename "key" to "name"
dannykoppingSep 4, 2024
87e8d61
Manager interface
dannykoppingSep 4, 2024
12e798f
Manager, with scoping
dannykoppingSep 4, 2024
549e4fb
linting errors
EmyrkSep 4, 2024
17603f5
chore: add runtimeconfig manager to options for plumbing (#14562)
EmyrkSep 4, 2024
056d1a5
Example usage
dannykoppingSep 4, 2024
f0ca466
make lint/fmt
dannykoppingSep 4, 2024
9069a48
Refactor
dannykoppingSep 4, 2024
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
9 changes: 9 additions & 0 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,7 @@ import (
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"github.com/coder/coder/v2/coderd/entitlements"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/pretty"
"github.com/coder/quartz"
"github.com/coder/retry"
Expand DownExpand Up@@ -820,6 +821,14 @@ 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)

// 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
2 changes: 2 additions & 0 deletionscoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@ import (
"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/entitlements"
"github.com/coder/coder/v2/coderd/idpsync"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/quartz"
"github.com/coder/serpent"

Expand DownExpand Up@@ -135,6 +136,7 @@ type Options struct {
Logger slog.Logger
Database database.Store
Pubsub pubsub.Pubsub
RuntimeConfig runtimeconfig.Manager

// CacheDir is used for caching files served by the API.
CacheDir string
Expand Down
6 changes: 6 additions & 0 deletionscoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,7 @@ import (
"github.com/coder/coder/v2/coderd/notifications"
"github.com/coder/coder/v2/coderd/rbac"
"github.com/coder/coder/v2/coderd/rbac/policy"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/coder/v2/coderd/schedule"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/coderd/unhanger"
Expand DownExpand Up@@ -254,6 +255,10 @@ 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)
options.Database = dbauthz.New(options.Database, options.Authorizer, *options.Logger, accessControlStore)

// Some routes expect a deployment ID, so just make sure one exists.
Expand DownExpand Up@@ -482,6 +487,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
AppHostnameRegex: appHostnameRegex,
Logger: *options.Logger,
CacheDir: t.TempDir(),
RuntimeConfig: runtimeManager,
Database: options.Database,
Pubsub: options.Pubsub,
ExternalAuthConfigs: options.ExternalAuthConfigs,
Expand Down
15 changes: 15 additions & 0 deletionscoderd/database/dbauthz/dbauthz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1183,6 +1183,11 @@ func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt tim
return q.db.DeleteReplicasUpdatedBefore(ctx, updatedAt)
}

func (q *querier) DeleteRuntimeConfig(ctx context.Context, key string) error {
// TODO: auth
return q.db.DeleteRuntimeConfig(ctx, key)
}

func (q *querier) DeleteTailnetAgent(ctx context.Context, arg database.DeleteTailnetAgentParams) (database.DeleteTailnetAgentRow, error) {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceTailnetCoordinator); err != nil {
return database.DeleteTailnetAgentRow{}, err
Expand DownExpand Up@@ -1856,6 +1861,11 @@ func (q *querier) GetReplicasUpdatedAfter(ctx context.Context, updatedAt time.Ti
return q.db.GetReplicasUpdatedAfter(ctx, updatedAt)
}

func (q *querier) GetRuntimeConfig(ctx context.Context, key string) (string, error) {
// TODO: auth
return q.db.GetRuntimeConfig(ctx, key)
}

func (q *querier) GetTailnetAgents(ctx context.Context, id uuid.UUID) ([]database.TailnetAgent, error) {
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTailnetCoordinator); err != nil {
return nil, err
Expand DownExpand Up@@ -3906,6 +3916,11 @@ func (q *querier) UpsertProvisionerDaemon(ctx context.Context, arg database.Upse
return q.db.UpsertProvisionerDaemon(ctx, arg)
}

func (q *querier) UpsertRuntimeConfig(ctx context.Context, arg database.UpsertRuntimeConfigParams) error {
// TODO: auth
return q.db.UpsertRuntimeConfig(ctx, arg)
}

func (q *querier) UpsertTailnetAgent(ctx context.Context, arg database.UpsertTailnetAgentParams) (database.TailnetAgent, error) {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceTailnetCoordinator); err != nil {
return database.TailnetAgent{}, err
Expand Down
36 changes: 36 additions & 0 deletionscoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@
"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/notifications/types"
"github.com/coder/coder/v2/coderd/runtimeconfig"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbtime"
Expand DownExpand Up@@ -84,6 +85,7 @@
workspaceProxies: make([]database.WorkspaceProxy, 0),
customRoles: make([]database.CustomRole, 0),
locks: map[int64]struct{}{},
runtimeConfig: map[string]string{},
},
}
// Always start with a default org. Matching migration 198.
Expand DownExpand Up@@ -194,6 +196,7 @@
workspaces []database.Workspace
workspaceProxies []database.WorkspaceProxy
customRoles []database.CustomRole
runtimeConfig map[string]string
// Locks is a map of lock names. Any keys within the map are currently
// locked.
locks map[int64]struct{}
Expand DownExpand Up@@ -1928,6 +1931,14 @@
return nil
}

func (q *FakeQuerier) DeleteRuntimeConfig(_ context.Context, key string) error {
q.mutex.Lock()
defer q.mutex.Unlock()

delete(q.runtimeConfig, key)
return nil
}

func (*FakeQuerier) DeleteTailnetAgent(context.Context, database.DeleteTailnetAgentParams) (database.DeleteTailnetAgentRow, error) {
return database.DeleteTailnetAgentRow{}, ErrUnimplemented
}
Expand DownExpand Up@@ -3505,6 +3516,18 @@
return replicas, nil
}

func (q *FakeQuerier) GetRuntimeConfig(_ context.Context, key string) (string, error) {
q.mutex.Lock()
defer q.mutex.Unlock()

val, ok := q.runtimeConfig[key]
if !ok {
return "", runtimeconfig.EntryNotFound
}

return val, nil
}

func (*FakeQuerier) GetTailnetAgents(context.Context, uuid.UUID) ([]database.TailnetAgent, error) {
return nil, ErrUnimplemented
}
Expand DownExpand Up@@ -9186,6 +9209,19 @@
return d, nil
}

func (q *FakeQuerier) UpsertRuntimeConfig(ctx context.Context, arg database.UpsertRuntimeConfigParams) error {

Check failure on line 9212 in coderd/database/dbmem/dbmem.go

View workflow job for this annotation

GitHub Actions/ lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
err := validateDatabaseType(arg)
if err != nil {
return err
}

q.mutex.Lock()
defer q.mutex.Unlock()

q.runtimeConfig[arg.Key] = arg.Value
return nil
}

func (*FakeQuerier) UpsertTailnetAgent(context.Context, database.UpsertTailnetAgentParams) (database.TailnetAgent, error) {
return database.TailnetAgent{}, ErrUnimplemented
}
Expand Down
21 changes: 21 additions & 0 deletionscoderd/database/dbmetrics/dbmetrics.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

43 changes: 43 additions & 0 deletionscoderd/database/dbmock/dbmock.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 3 additions & 0 deletionscoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

36 changes: 36 additions & 0 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

11 changes: 11 additions & 0 deletionscoderd/database/queries/siteconfig.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,3 +96,14 @@ SELECT
INSERT INTO site_configs (key, value) VALUES ('notifications_settings', $1)
ON CONFLICT (key) DO UPDATE SET value = $1 WHERE site_configs.key = 'notifications_settings';

-- name: GetRuntimeConfig :one
SELECT value FROM site_configs WHERE site_configs.key = $1;

-- name: UpsertRuntimeConfig :exec
INSERT INTO site_configs (key, value) VALUES ($1, $2)
ON CONFLICT (key) DO UPDATE SET value = $2 WHERE site_configs.key = $1;

-- name: DeleteRuntimeConfig :exec
DELETE FROM site_configs
WHERE site_configs.key = $1;

3 changes: 2 additions & 1 deletioncoderd/notifications/dispatch/smtp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,7 @@
"github.com/coder/coder/v2/coderd/notifications/render"
"github.com/coder/coder/v2/coderd/notifications/types"
markdown "github.com/coder/coder/v2/coderd/render"
"github.com/coder/coder/v2/coderd/runtimeconfig"
"github.com/coder/coder/v2/codersdk"
)

Expand DownExpand Up@@ -63,7 +64,7 @@
return &SMTPHandler{cfg: cfg, helpers: helpers, log: log}
}

func (s *SMTPHandler) Dispatcher(payload types.MessagePayload, titleTmpl, bodyTmpl string) (DeliveryFunc, error) {
func (s *SMTPHandler) Dispatcher(cfg runtimeconfig.Manager,payload types.MessagePayload, titleTmpl, bodyTmpl string) (DeliveryFunc, error) {

Check failure on line 67 in coderd/notifications/dispatch/smtp.go

View workflow job for this annotation

GitHub Actions/ lint

unused-parameter: parameter 'cfg' seems to be unused, consider removing or renaming it as _ (revive)
// First render the subject & body into their own discrete strings.
subject, err := markdown.PlaintextFromMarkdown(titleTmpl)
if err != nil {
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp