Skip to content

Commit 58b2f33

Browse files
authored
fix notifications config (#4574)
1 parent eee14a0 commit 58b2f33

File tree

8 files changed

+34
-20
lines changed

8 files changed

+34
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bugfix: Fix notifications
2+
3+
https://github.com/cs3org/reva/pull/4574

internal/http/services/owncloud/ocdav/ocdav.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type Config struct {
120120
FavoriteStorageDrivers map[string]map[string]interface{} `mapstructure:"favorite_storage_drivers"`
121121
PublicLinkDownload *ConfigPublicLinkDownload `mapstructure:"publiclink_download"`
122122
DisabledOpenInAppPaths []string `mapstructure:"disabled_open_in_app_paths"`
123-
Notifications map[string]interface{} `docs:"Settingsg for the Notification Helper" mapstructure:"notifications"`
123+
Notifications map[string]interface{} `mapstructure:"notifications" docs:"Settings for the Notification Helper"`
124124
}
125125

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

181181
// initialize handlers and set default cigs

internal/http/services/owncloud/ocs/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Config struct {
4545
AllowedLanguages []string `mapstructure:"allowed_languages"`
4646
OCMMountPoint string `mapstructure:"ocm_mount_point"`
4747
ListOCMShares bool `mapstructure:"list_ocm_shares"`
48+
Notifications map[string]interface{} `mapstructure:"notifications"`
4849
}
4950

5051
// Init sets sane defaults.

internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (h *Handler) Init(c *config.Config, l *zerolog.Logger) {
117117
h.ocmMountPoint = c.OCMMountPoint
118118
h.listOCMShares = c.ListOCMShares
119119
h.Log = l
120-
h.notificationHelper = notificationhelper.New("ocs", l)
120+
h.notificationHelper = notificationhelper.New("ocs", c.Notifications, l)
121121
h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute)
122122
h.resourceInfoCacheTTL = time.Second * time.Duration(c.ResourceInfoCacheTTL)
123123

pkg/notification/handler/emailhandler/emailhandler.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ type EmailHandler struct {
4343
}
4444

4545
type config struct {
46-
SMTPAddress string `docs:";The hostname and port of the SMTP server." mapstructure:"smtp_server"`
47-
SenderLogin string `docs:";The email to be used to send mails." mapstructure:"sender_login"`
48-
SenderPassword string `docs:";The sender's password." mapstructure:"sender_password"`
49-
DisableAuth bool `docs:"false;Whether to disable SMTP auth." mapstructure:"disable_auth"`
50-
DefaultSender string `docs:"[email protected];Default sender when not specified in the trigger." mapstructure:"default_sender"`
46+
SMTPAddress string `mapstructure:"smtp_server" docs:";The hostname and port of the SMTP server."`
47+
SenderLogin string `mapstructure:"sender_login" docs:";The email to be used to send mails."`
48+
SenderPassword string `mapstructure:"sender_password" docs:";The sender's password."`
49+
DisableAuth bool `mapstructure:"disable_auth" docs:"false;Whether to disable SMTP auth."`
50+
DefaultSender string `mapstructure:"default_sender" docs:"[email protected];Default sender when not specified in the trigger."`
5151
}
5252

5353
func (c *config) ApplyDefaults() {
0 Bytes
Binary file not shown.

pkg/notification/notificationhelper/notificationhelper.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ type NotificationHelper struct {
4444

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

5353
func defaultConfig() *Config {
@@ -57,7 +57,7 @@ func defaultConfig() *Config {
5757
}
5858

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

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

70+
if len(m) == 0 {
71+
log.Info().Msgf("no 'notifications' field in service config, notifications will be disabled")
72+
return nh
73+
}
74+
75+
if err := mapstructure.Decode(m, conf); err != nil {
76+
log.Error().Err(err).Msgf("decoding config failed, notifications will be disabled")
77+
return nh
78+
}
79+
7080
if err := nh.connect(); err != nil {
71-
log.Error().Err(err).Msg("connecting to nats failed, notifications will be disabled")
81+
log.Error().Err(err).Msgf("connecting to nats failed, notifications will be disabled")
7282
return nh
7383
}
7484

@@ -120,7 +130,7 @@ func (nh *NotificationHelper) Stop() {
120130
return
121131
}
122132
if err := nh.nc.Drain(); err != nil {
123-
nh.Log.Error().Err(err).Send()
133+
nh.Log.Error().Err(err)
124134
}
125135
}
126136

pkg/notification/template/template.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const validTemplateNameRegex = "[a-zA-Z0-9-]"
3737

3838
// RegistrationRequest represents a Template registration request.
3939
type RegistrationRequest struct {
40-
Name string `json:"name" mapstructure:"name"`
41-
Handler string `json:"handler" mapstructure:"handler"`
42-
BodyTmplPath string `json:"body_template_path" mapstructure:"body_template_path"`
43-
SubjectTmplPath string `json:"subject_template_path" mapstructure:"subject_template_path"`
44-
Persistent bool `json:"persistent" mapstructure:"persistent"`
40+
Name string `mapstructure:"name" json:"name"`
41+
Handler string `mapstructure:"handler" json:"handler"`
42+
BodyTmplPath string `mapstructure:"body_template_path" json:"body_template_path"`
43+
SubjectTmplPath string `mapstructure:"subject_template_path" json:"subject_template_path"`
44+
Persistent bool `mapstructure:"persistent" json:"persistent"`
4545
}
4646

4747
// Template represents a notification template.

0 commit comments

Comments
 (0)