MCPcopy Index your code
hub / github.com/coder/coder / StartRotator

Function StartRotator

coderd/cryptokeys/rotate.go:57–78  ·  view source on GitHub ↗

StartRotator starts a background process that rotates keys in the database. It ensures there's at least one valid key per feature prior to returning. Canceling the provided context will stop the background process.

(ctx context.Context, logger slog.Logger, db database.Store, opts ...RotatorOption)

Source from the content-addressed store, hash-verified

55// It ensures there's at least one valid key per feature prior to returning.
56// Canceling the provided context will stop the background process.
57func StartRotator(ctx context.Context, logger slog.Logger, db database.Store, opts ...RotatorOption) {
58 //nolint:gocritic // KeyRotator can only rotate crypto keys.
59 ctx = dbauthz.AsKeyRotator(ctx)
60 kr := &rotator{
61 db: db,
62 logger: logger.Named("keyrotator"),
63 clock: quartz.NewReal(),
64 keyDuration: DefaultKeyDuration,
65 features: database.AllCryptoKeyFeatureValues(),
66 }
67
68 for _, opt := range opts {
69 opt(kr)
70 }
71
72 err := kr.rotateKeys(ctx)
73 if err != nil {
74 kr.logger.Critical(ctx, "failed to rotate keys", slog.Error(err))
75 }
76
77 go kr.start(ctx)
78}
79
80// start begins the process of rotating keys.
81// Canceling the context will stop the rotation process.

Callers 2

NewFunction · 0.92
TestRotatorFunction · 0.92

Calls 6

rotateKeysMethod · 0.95
startMethod · 0.95
AsKeyRotatorFunction · 0.92
NamedMethod · 0.80
ErrorMethod · 0.45

Tested by 1

TestRotatorFunction · 0.74