-
Notifications
You must be signed in to change notification settings - Fork 378
/
command_acl_delete.go
69 lines (55 loc) · 1.47 KB
/
command_acl_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/acl"
"github.com/kopia/kopia/repo"
)
type commandACLDelete struct {
ids []string
all bool
confirm bool
}
func (c *commandACLDelete) setup(svc appServices, parent commandParent) {
cmd := parent.Command("delete", "Delete ACL entry").Alias("remove").Alias("rm")
cmd.Arg("id", "Entry ID").StringsVar(&c.ids)
cmd.Flag("all", "Remove all ACL entries").BoolVar(&c.all)
cmd.Flag("delete", "Really delete").BoolVar(&c.confirm)
cmd.Action(svc.repositoryWriterAction(c.run))
}
func dryRunDelete(ctx context.Context, e *acl.Entry) {
log(ctx).Infof("would delete entry %v, pass --delete to actually delete", e.ManifestID)
}
func (c *commandACLDelete) shouldRemoveACLEntry(ctx context.Context, e *acl.Entry) bool {
if c.all {
if !c.confirm {
dryRunDelete(ctx, e)
return false
}
return true
}
for _, tr := range c.ids {
if tr == string(e.ManifestID) {
if !c.confirm {
dryRunDelete(ctx, e)
return false
}
return true
}
}
return false
}
func (c *commandACLDelete) run(ctx context.Context, rep repo.RepositoryWriter) error {
entries, err := acl.LoadEntries(ctx, rep, nil)
if err != nil {
return errors.Wrap(err, "unable to load entries")
}
for _, e := range entries {
if c.shouldRemoveACLEntry(ctx, e) {
if err := rep.DeleteManifest(ctx, e.ManifestID); err != nil {
return errors.Wrap(err, "unable to delete manifest")
}
}
}
return nil
}