mirror of
https://github.com/kopia/kopia.git
synced 2026-01-24 14:28:06 -05:00
* feat(cli): support for defining notification profiles via CLI
Profile management:
```
$ kopia notification profile configure email \
--profile-name=X \
--smtp-server=smtp.gmail.com \
--smtp-port=587 \
--smtp-username=X \
--smtp-password=X \
--mail-from=X \
--mail-to=X \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile configure pushover --profile-name=X \
--user-key=X \
--app-token=X \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile configure webhook --profile-name=X \
--endpooint=http://some-address:port/path \
--method=POST|PUT \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile test --profile-name=X
$ kopia notification profile delete --profile-name=X
$ kopia notification profile list
```
Template management:
```
$ kopia notification template show X
$ kopia notification template set X \
--from-stdin | --from-file=X | --editor
$ kopia notification template remove X
$ kopia notification template list
```
Implements #1958
* additional refactoring for testability, various naming tweaks
43 lines
1.1 KiB
Go
43 lines
1.1 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, ok, err := notifyprofile.GetProfile(ctx, rep, c.profileName)
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to get notification profile")
|
|
}
|
|
|
|
if !ok {
|
|
return errors.Errorf("notification profile %q not found", c.profileName)
|
|
}
|
|
|
|
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
|
|
}
|