Files
kopia/cli/command_notification_profile_send.go
Jarek Kowalski c1757a0c67 feat(general): misc notifications improvements (#4319)
* feat(general): various notifications improvements

* added API to test notification profiles
* added --http-header to webhook notification configuration
* refactored configuration to always apply defaults before persisting options in the repository
* added 'notification profile show --profile-name=X' command

* more tests

* more test coverage

* report notification code coverage
2024-12-29 09:50:20 -08:00

39 lines
1.0 KiB
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/notification"
"github.com/kopia/kopia/notification/notifyprofile"
"github.com/kopia/kopia/notification/sender"
"github.com/kopia/kopia/repo"
)
type commandNotificationProfileTest struct {
notificationProfileFlag
}
func (c *commandNotificationProfileTest) setup(svc appServices, parent commandParent) {
cmd := parent.Command("test", "Send test notification").Alias("send-test-message")
c.notificationProfileFlag.setup(svc, cmd)
cmd.Action(svc.repositoryReaderAction(c.run))
}
func (c *commandNotificationProfileTest) run(ctx context.Context, rep repo.Repository) error {
p, err := notifyprofile.GetProfile(ctx, rep, c.profileName)
if err != nil {
return errors.Wrap(err, "unable to get notification profile")
}
snd, err := sender.GetSender(ctx, p.ProfileName, p.MethodConfig.Type, p.MethodConfig.Config)
if err != nil {
return errors.Wrap(err, "unable to get notification sender")
}
return notification.SendTestNotification(ctx, rep, snd) //nolint:wrapcheck
}