Files
kopia/notification/sender/pushover/pushover_sender_options.go
Julio Lopez 8098f49c90 chore(ci): remove exclusion for unused ctx parameters (#4530)
Remove unused-parameter exclusion for `ctx` in revive linter.

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-26 23:11:36 -07:00

52 lines
1.3 KiB
Go

package pushover
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/notification/sender"
)
// Options defines Pushover notification sender options.
type Options struct {
AppToken string `json:"appToken"`
UserKey string `json:"userKey"`
Format string `json:"format"` // format of the message, must be "html" or "md"
Endpoint string `json:"endpoint,omitempty"` // override the default endpoint for testing
}
// ApplyDefaultsAndValidate applies default values and validates the configuration.
func (o *Options) ApplyDefaultsAndValidate(_ context.Context) error {
if o.AppToken == "" {
return errors.Errorf("App Token must be provided")
}
if o.UserKey == "" {
return errors.Errorf("User Key must be provided")
}
if err := sender.ValidateMessageFormatAndSetDefault(&o.Format, sender.FormatPlainText); err != nil {
return errors.Wrap(err, "invalid format")
}
return nil
}
// MergeOptions updates the destination options with the source options.
func MergeOptions(ctx context.Context, src Options, dst *Options, isUpdate bool) error {
copyOrMerge(&dst.AppToken, src.AppToken, isUpdate)
copyOrMerge(&dst.UserKey, src.UserKey, isUpdate)
return dst.ApplyDefaultsAndValidate(ctx)
}
func copyOrMerge[T comparable](dst *T, src T, isUpdate bool) {
var defaultT T
if !isUpdate || src != defaultT {
*dst = src
}
}