forked from thecodeteam/goisilon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acls.go
50 lines (40 loc) · 1023 Bytes
/
acls.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
package goisilon
import (
"context"
api "github.com/thecodeteam/goisilon/api/v2"
)
type ACL *api.ACL
// GetVolumeACL returns the ACL for a volume.
func (c *Client) GetVolumeACL(
ctx context.Context,
volumeName string) (ACL, error) {
return api.ACLInspect(ctx, c.API, volumeName)
}
// SetVolumeOwnerToCurrentUser sets the owner for a volume to the user that
// was used to connect to the API.
func (c *Client) SetVolumeOwnerToCurrentUser(
ctx context.Context,
volumeName string) error {
return c.SetVolumeOwner(ctx, volumeName, c.API.User())
}
// SetVolumeOwner sets the owner for a volume.
func (c *Client) SetVolumeOwner(
ctx context.Context,
volumeName, userName string) error {
mode := api.FileMode(0777)
return api.ACLUpdate(
ctx,
c.API,
volumeName,
&api.ACL{
Action: &api.PActionTypeReplace,
Authoritative: &api.PAuthoritativeTypeMode,
Owner: &api.Persona{
ID: &api.PersonaID{
ID: userName,
Type: api.PersonaIDTypeUser,
},
},
Mode: &mode,
})
}