forked from kopia/kopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_acl_enable.go
More file actions
50 lines (39 loc) · 1.17 KB
/
Copy pathcommand_acl_enable.go
File metadata and controls
50 lines (39 loc) · 1.17 KB
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
package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/acl"
"github.com/kopia/kopia/internal/auth"
"github.com/kopia/kopia/repo"
)
type commandACLEnable struct {
reset bool
}
func (c *commandACLEnable) setup(svc appServices, parent commandParent) {
cmd := parent.Command("enable", "Enable ACLs and install default entries")
cmd.Flag("reset", "Reset all ACLs to default").BoolVar(&c.reset)
cmd.Action(svc.repositoryWriterAction(c.run))
}
func (c *commandACLEnable) run(ctx context.Context, rep repo.RepositoryWriter) error {
entries, err := acl.LoadEntries(ctx, rep, nil)
if err != nil {
return errors.Wrap(err, "error loading ACL entries")
}
if len(entries) != 0 && !c.reset {
return errors.New("ACLs already enabled")
}
if c.reset {
for _, e := range entries {
log(ctx).Infof("deleting previous ACL entry %v", e.ManifestID)
if err := rep.DeleteManifest(ctx, e.ManifestID); err != nil {
return errors.Wrap(err, "unable to delete previous ACL")
}
}
}
for _, e := range auth.DefaultACLs {
if err := acl.AddACL(ctx, rep, e, false); err != nil {
return errors.Wrap(err, "unable to add default ACL")
}
}
return nil
}