-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add NATS publisher support to reminder #4829
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,22 @@ | ||||||||||||||||
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors | ||||||||||||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||
|
||||||||||||||||
package reminder | ||||||||||||||||
|
||||||||||||||||
import ( | ||||||||||||||||
"context" | ||||||||||||||||
"fmt" | ||||||||||||||||
|
||||||||||||||||
"github.com/ThreeDotsLabs/watermill/message" | ||||||||||||||||
|
||||||||||||||||
"github.com/mindersec/minder/pkg/eventer" | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
func (r *reminder) getMessagePublisher(ctx context.Context) (message.Publisher, error) { | ||||||||||||||||
pub, err := eventer.New(ctx, nil, &r.cfg.EventConfig) | ||||||||||||||||
if err != nil { | ||||||||||||||||
return nil, fmt.Errorf("failed to create publisher: %w", err) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return pub, nil | ||||||||||||||||
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a slight preference for just leaving this code in-line, given that it could generally be reduced to:
Suggested change
I don't feel very strongly, however. (Leaving it in-line reduces the need to "peek" into the implementation to see if there's anything fancy going on when tracing the code. This is admittedly less of an issue for one-time initialization code.) |
||||||||||||||||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,23 @@ | |
package reminder | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/mindersec/minder/pkg/config" | ||
serverconfig "github.com/mindersec/minder/pkg/config/server" | ||
"github.com/mindersec/minder/pkg/eventer/constants" | ||
) | ||
|
||
// Config contains the configuration for the reminder service | ||
type Config struct { | ||
Database config.DatabaseConfig `mapstructure:"database"` | ||
RecurrenceConfig RecurrenceConfig `mapstructure:"recurrence"` | ||
EventConfig EventConfig `mapstructure:"events"` | ||
LoggingConfig LoggingConfig `mapstructure:"logging"` | ||
Database config.DatabaseConfig `mapstructure:"database"` | ||
RecurrenceConfig RecurrenceConfig `mapstructure:"recurrence"` | ||
EventConfig serverconfig.EventConfig `mapstructure:"events"` | ||
LoggingConfig LoggingConfig `mapstructure:"logging"` | ||
} | ||
|
||
// Validate validates the configuration | ||
|
@@ -28,6 +31,11 @@ func (c Config) Validate() error { | |
return err | ||
} | ||
|
||
err = validateEventConfig(c.EventConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -52,3 +60,14 @@ func RegisterReminderFlags(v *viper.Viper, flags *pflag.FlagSet) error { | |
|
||
return registerRecurrenceFlags(v, flags) | ||
} | ||
|
||
func validateEventConfig(cfg serverconfig.EventConfig) error { | ||
switch cfg.Driver { | ||
case constants.NATSDriver: | ||
case constants.SQLDriver: | ||
default: | ||
return fmt.Errorf("events.driver %s is not supported", cfg.Driver) | ||
} | ||
|
||
return nil | ||
} | ||
Comment on lines
+64
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents using e.g. the flag driver. I think that's okay, but I'd tend to write this as a deny-list of configuration that we know won't work rather than an allow-list (because we'll need to go back and expand the allow-list as we add new messaging configurations). |
This file was deleted.
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.
Newer jetstream API, cleaner code, context support. https://github.com/nats-io/nats.go/blob/main/jetstream/README.md
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.
👍 if this works; I think when I started looking, this wasn't cleaned up / operable with CloudEvents yet.