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
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/alecthomas/kingpin/v2"
|
|
|
|
"github.com/kopia/kopia/notification/notifyprofile"
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
type commandNotificationProfile struct {
|
|
config commandNotificationProfileConfigure
|
|
list commandNotificationProfileList
|
|
delete commandNotificationProfileDelete
|
|
test commandNotificationProfileTest
|
|
}
|
|
|
|
func (c *commandNotificationProfile) setup(svc appServices, parent commandParent) {
|
|
cmd := parent.Command("profile", "Manage notification profiles")
|
|
c.config.setup(svc, cmd)
|
|
c.delete.setup(svc, cmd)
|
|
c.test.setup(svc, cmd)
|
|
c.list.setup(svc, cmd)
|
|
}
|
|
|
|
type notificationProfileFlag struct {
|
|
profileName string
|
|
}
|
|
|
|
func (c *notificationProfileFlag) setup(svc appServices, cmd *kingpin.CmdClause) {
|
|
cmd.Flag("profile-name", "Profile name").Required().HintAction(svc.repositoryHintAction(c.listNotificationProfiles)).StringVar(&c.profileName)
|
|
}
|
|
|
|
func (c *notificationProfileFlag) listNotificationProfiles(ctx context.Context, rep repo.Repository) []string {
|
|
profiles, err := notifyprofile.ListProfiles(ctx, rep)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
var hints []string
|
|
|
|
for _, ti := range profiles {
|
|
if strings.HasPrefix(ti.ProfileName, c.profileName) {
|
|
hints = append(hints, ti.ProfileName)
|
|
}
|
|
}
|
|
|
|
return hints
|
|
}
|