-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvolume_mount_options_mask.go
62 lines (50 loc) · 1.36 KB
/
volume_mount_options_mask.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
package volume_mount_options
import (
"fmt"
"strconv"
"code.cloudfoundry.org/volume-mount-options/utils"
)
type MountOptsMask struct {
Allowed []string
Defaults map[string]interface{}
KeyPerms map[string]string
Ignored []string
Mandatory []string
SloppyMount bool
ValidationFunc []UserOptsValidation
}
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
//counterfeiter:generate . UserOptsValidation
type UserOptsValidation interface {
Validate(string, string) error
}
type UserOptsValidationFunc func(string, string) error
func (v UserOptsValidationFunc) Validate(a string, b string) error {
return v(a, b)
}
func NewMountOptsMask(allowed []string,
defaults map[string]interface{},
keyPerms map[string]string,
ignored, mandatory []string,
f ...UserOptsValidation) (MountOptsMask, error) {
mask := MountOptsMask{
Allowed: allowed,
Defaults: defaults,
KeyPerms: keyPerms,
Ignored: ignored,
Mandatory: mandatory,
ValidationFunc: f,
}
if defaults == nil {
mask.Defaults = make(map[string]interface{})
}
if v, ok := defaults["sloppy_mount"]; ok {
vc := utils.InterfaceToString(v)
var err error
mask.SloppyMount, err = strconv.ParseBool(vc)
if err != nil {
return MountOptsMask{}, fmt.Errorf("invalid sloppy_mount option: %w", err)
}
}
return mask, nil
}