Skip to content

Commit

Permalink
fix notifications config (#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode authored Mar 13, 2024
1 parent eee14a0 commit 58b2f33
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/fix-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fix notifications

https://github.com/cs3org/reva/pull/4574
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/ocdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Config struct {
FavoriteStorageDrivers map[string]map[string]interface{} `mapstructure:"favorite_storage_drivers"`
PublicLinkDownload *ConfigPublicLinkDownload `mapstructure:"publiclink_download"`
DisabledOpenInAppPaths []string `mapstructure:"disabled_open_in_app_paths"`
Notifications map[string]interface{} `docs:"Settingsg for the Notification Helper" mapstructure:"notifications"`
Notifications map[string]interface{} `mapstructure:"notifications" docs:"Settings for the Notification Helper"`
}

func (c *Config) ApplyDefaults() {
Expand Down Expand Up @@ -175,7 +175,7 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error)
httpclient.RoundTripper(tr),
),
favoritesManager: fm,
notificationHelper: notificationhelper.New("ocdav", log),
notificationHelper: notificationhelper.New("ocdav", c.Notifications, log),
}

// initialize handlers and set default cigs
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Config struct {
AllowedLanguages []string `mapstructure:"allowed_languages"`
OCMMountPoint string `mapstructure:"ocm_mount_point"`
ListOCMShares bool `mapstructure:"list_ocm_shares"`
Notifications map[string]interface{} `mapstructure:"notifications"`
}

// Init sets sane defaults.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (h *Handler) Init(c *config.Config, l *zerolog.Logger) {
h.ocmMountPoint = c.OCMMountPoint
h.listOCMShares = c.ListOCMShares
h.Log = l
h.notificationHelper = notificationhelper.New("ocs", l)
h.notificationHelper = notificationhelper.New("ocs", c.Notifications, l)
h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute)
h.resourceInfoCacheTTL = time.Second * time.Duration(c.ResourceInfoCacheTTL)

Expand Down
10 changes: 5 additions & 5 deletions pkg/notification/handler/emailhandler/emailhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ type EmailHandler struct {
}

type config struct {
SMTPAddress string `docs:";The hostname and port of the SMTP server." mapstructure:"smtp_server"`
SenderLogin string `docs:";The email to be used to send mails." mapstructure:"sender_login"`
SenderPassword string `docs:";The sender's password." mapstructure:"sender_password"`
DisableAuth bool `docs:"false;Whether to disable SMTP auth." mapstructure:"disable_auth"`
DefaultSender string `docs:"no-reply@cernbox.cern.ch;Default sender when not specified in the trigger." mapstructure:"default_sender"`
SMTPAddress string `mapstructure:"smtp_server" docs:";The hostname and port of the SMTP server."`

Check failure on line 46 in pkg/notification/handler/emailhandler/emailhandler.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: docs:";The hostname and port of the SMTP server." mapstructure:"smtp_server" (tagalign)
SenderLogin string `mapstructure:"sender_login" docs:";The email to be used to send mails."`
SenderPassword string `mapstructure:"sender_password" docs:";The sender's password."`
DisableAuth bool `mapstructure:"disable_auth" docs:"false;Whether to disable SMTP auth."`
DefaultSender string `mapstructure:"default_sender" docs:"no-reply@cernbox.cern.ch;Default sender when not specified in the trigger."`
}

func (c *config) ApplyDefaults() {
Expand Down
Binary file modified pkg/notification/manager/sql/test.sqlite
Binary file not shown.
24 changes: 17 additions & 7 deletions pkg/notification/notificationhelper/notificationhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type NotificationHelper struct {

// Config contains the configuration for the Notification Helper.
type Config struct {
NatsAddress string `docs:";The NATS server address." mapstructure:"nats_address"`
NatsToken string `docs:";The token to authenticate against the NATS server" mapstructure:"nats_token"`
NatsStream string `docs:"reva-notifications;The notifications NATS stream." mapstructure:"nats_stream"`
Templates map[string]interface{} `docs:";Notification templates for the service." mapstructure:"templates"`
NatsAddress string `mapstructure:"nats_address" docs:";The NATS server address."`

Check failure on line 47 in pkg/notification/notificationhelper/notificationhelper.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: docs:";The NATS server address." mapstructure:"nats_address" (tagalign)
NatsToken string `mapstructure:"nats_token" docs:";The token to authenticate against the NATS server"`

Check failure on line 48 in pkg/notification/notificationhelper/notificationhelper.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: docs:";The token to authenticate against the NATS server" mapstructure:"nats_token" (tagalign)
NatsStream string `mapstructure:"nats_stream" docs:"reva-notifications;The notifications NATS stream."`

Check failure on line 49 in pkg/notification/notificationhelper/notificationhelper.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: docs:"reva-notifications;The notifications NATS stream." mapstructure:"nats_stream" (tagalign)
Templates map[string]interface{} `mapstructure:"templates" docs:";Notification templates for the service."`

Check failure on line 50 in pkg/notification/notificationhelper/notificationhelper.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: docs:";Notification templates for the service." mapstructure:"templates" (tagalign)
}

func defaultConfig() *Config {
Expand All @@ -57,7 +57,7 @@ func defaultConfig() *Config {
}

// New creates a new Notification Helper.
func New(name string, log *zerolog.Logger) *NotificationHelper {
func New(name string, m map[string]interface{}, log *zerolog.Logger) *NotificationHelper {
annotatedLogger := log.With().Str("service", name).Str("scope", "notifications").Logger()

conf := defaultConfig()
Expand All @@ -67,8 +67,18 @@ func New(name string, log *zerolog.Logger) *NotificationHelper {
Log: &annotatedLogger,
}

if len(m) == 0 {
log.Info().Msgf("no 'notifications' field in service config, notifications will be disabled")
return nh
}

if err := mapstructure.Decode(m, conf); err != nil {
log.Error().Err(err).Msgf("decoding config failed, notifications will be disabled")
return nh
}

if err := nh.connect(); err != nil {
log.Error().Err(err).Msg("connecting to nats failed, notifications will be disabled")
log.Error().Err(err).Msgf("connecting to nats failed, notifications will be disabled")
return nh
}

Expand Down Expand Up @@ -120,7 +130,7 @@ func (nh *NotificationHelper) Stop() {
return
}
if err := nh.nc.Drain(); err != nil {
nh.Log.Error().Err(err).Send()
nh.Log.Error().Err(err)
}
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/notification/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const validTemplateNameRegex = "[a-zA-Z0-9-]"

// RegistrationRequest represents a Template registration request.
type RegistrationRequest struct {
Name string `json:"name" mapstructure:"name"`
Handler string `json:"handler" mapstructure:"handler"`
BodyTmplPath string `json:"body_template_path" mapstructure:"body_template_path"`
SubjectTmplPath string `json:"subject_template_path" mapstructure:"subject_template_path"`
Persistent bool `json:"persistent" mapstructure:"persistent"`
Name string `mapstructure:"name" json:"name"`

Check failure on line 40 in pkg/notification/template/template.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"name" mapstructure:"name" (tagalign)
Handler string `mapstructure:"handler" json:"handler"`

Check failure on line 41 in pkg/notification/template/template.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"handler" mapstructure:"handler" (tagalign)
BodyTmplPath string `mapstructure:"body_template_path" json:"body_template_path"`

Check failure on line 42 in pkg/notification/template/template.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"body_template_path" mapstructure:"body_template_path" (tagalign)
SubjectTmplPath string `mapstructure:"subject_template_path" json:"subject_template_path"`

Check failure on line 43 in pkg/notification/template/template.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"subject_template_path" mapstructure:"subject_template_path" (tagalign)
Persistent bool `mapstructure:"persistent" json:"persistent"`

Check failure on line 44 in pkg/notification/template/template.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"persistent" mapstructure:"persistent" (tagalign)
}

// Template represents a notification template.
Expand Down

0 comments on commit 58b2f33

Please sign in to comment.