-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add NATS KV cache bucket for username→sub lookups #44
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,24 +168,33 @@ func NewClient(ctx context.Context, config Config) (*NATSClient, error) { | |
| timeout: config.Timeout, | ||
| } | ||
|
|
||
| var buckets []string | ||
| // Check if Authelia is enabled by checking the environment variable directly | ||
| if os.Getenv(constants.UserRepositoryTypeEnvKey) == constants.UserRepositoryTypeAuthelia { | ||
| buckets = append(buckets, constants.KVBucketNameAutheliaUsers) | ||
| buckets = append(buckets, constants.KVBucketNameAutheliaEmailOTP) | ||
| // The username→sub cache bucket is best-effort: if it doesn't exist or is | ||
| // unavailable the service still works, just without caching. | ||
| if err := client.KeyValueStore(ctx, constants.KVBucketNameUsernameSubCache); err != nil { | ||
| slog.WarnContext(ctx, "username→sub cache bucket unavailable, caching disabled", | ||
| "error", err, | ||
| "bucket", constants.KVBucketNameUsernameSubCache, | ||
| ) | ||
| } else { | ||
|
Comment on lines
+171
to
+178
|
||
| slog.InfoContext(ctx, "NATS key-value store initialized", | ||
| "bucket", constants.KVBucketNameUsernameSubCache, | ||
| ) | ||
| } | ||
|
|
||
| for _, bucketName := range buckets { | ||
| if err := client.KeyValueStore(ctx, bucketName); err != nil { | ||
| slog.ErrorContext(ctx, "failed to initialize NATS key-value store", | ||
| "error", err, | ||
| // Authelia-specific buckets are required when Authelia is the user repository. | ||
| if os.Getenv(constants.UserRepositoryTypeEnvKey) == constants.UserRepositoryTypeAuthelia { | ||
| for _, bucketName := range []string{constants.KVBucketNameAutheliaUsers, constants.KVBucketNameAutheliaEmailOTP} { | ||
| if err := client.KeyValueStore(ctx, bucketName); err != nil { | ||
| slog.ErrorContext(ctx, "failed to initialize NATS key-value store", | ||
| "error", err, | ||
| "bucket", bucketName, | ||
| ) | ||
| return nil, errors.NewServiceUnavailable("failed to initialize NATS key-value store", err) | ||
| } | ||
| slog.InfoContext(ctx, "NATS key-value store initialized", | ||
| "bucket", bucketName, | ||
| ) | ||
| return nil, errors.NewServiceUnavailable("failed to initialize NATS key-value store", err) | ||
| } | ||
| slog.InfoContext(ctx, "NATS key-value store initialized", | ||
| "bucket", bucketName, | ||
| ) | ||
| } | ||
|
|
||
| slog.InfoContext(ctx, "NATS client created successfully", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you include replicas here as well please?