Debian Codegraph @

storage/accesscontrol/ace.go

raw symbols SCIP
1 package accesscontrolscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/"
5 "regexpscip-go gomod github.com/golang/go/src go1.13 regexp/"
6 "stringsscip-go gomod github.com/golang/go/src go1.13 strings/"
7
8 "github.com/google/uuidscip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/"
9 )
10
11 type TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType# string
12
13 const (
14 TagTypeUserscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeUser. TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType# = "user"
15 TagTypeGroupscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeGroup. TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType# = "group"
16 TagTypeMaskscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeMask. TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType# = "mask"
17 TagTypeOtherscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeOther. TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType# = "other"
18 )
19
20 // ACE is roughly modelled on https://linux.die.net/man/5/acl
21 // Have collapsed ACL_USER_OBJ to be TagType of user with a nil Qualifier
22
23 type ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE# struct {
24 IsDefaultscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#IsDefault. bool
25 TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagType. TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType#
26 TagQualifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagQualifier. *uuidscip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/.UUIDscip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/UUID#
27 Permissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Permissions. string // TODO break the rwx into permission flags?
28 }
29
30 var permissionsRegexscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/permissionsRegex. *regexpscip-go gomod github.com/golang/go/src go1.13 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.13 regexp/Regexp#
31
32 func initscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/init().() {
33 permissionsRegexscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/permissionsRegex. = regexpscip-go gomod github.com/golang/go/src go1.13 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.13 regexp/MustCompile().("[r-][w-][x-]")
34 }
35
36 // ValidateACEPermissions checks the format of the ACE permission string. Returns nil on success.
37 func ValidateACEPermissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ValidateACEPermissions().(permissions string) error {
38 if !permissionsRegexscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/permissionsRegex..MatchStringscip-go gomod github.com/golang/go/src go1.13 regexp/Regexp#MatchString().(permissions) {
39 return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Permissions must be of the form [r-][w-][x-]")
40 }
41 return nil
42 }
43
44 // Validate checks the formatting and combination of values in the ACE. Returns nil on success
45 func (ace *ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#) Validatescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Validate().() error {
46 switch ace.TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagType. {
47 case TagTypeMaskscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeMask., TagTypeOtherscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeOther.:
48 if ace.TagQualifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagQualifier. != nil {
49 return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("TagQualifier cannot be set for 'mask' or 'other' TagTypes")
50 }
51 }
52
53 if err := ValidateACEPermissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ValidateACEPermissions().(ace.Permissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Permissions.); err != nil {
54 return err
55 }
56
57 if err := validateTagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/validateTagType().(ace.TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagType.); err != nil {
58 return err
59 }
60
61 return nil
62 }
63
64 // ParseACE parses an ACE string and returns the ACE
65 func ParseACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ParseACE().(input string) (ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#, error) {
66 ace := ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#{}
67
68 parts := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(input, ":")
69 if len(parts) == 4 {
70 if parts[0] == "default" {
71 ace.IsDefaultscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#IsDefault. = true
72 parts = parts[1:]
73 } else {
74 return ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#{}, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("When specifying a 4-part ACE the first part must be 'default'")
75 }
76 }
77
78 if len(parts) != 3 {
79 return ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#{}, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("ACE string should have either 3 or 4 parts")
80 }
81
82 ace.TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagType. = TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType#(parts[0])
83
84 qualiferString := parts[1]
85 if qualiferString != "" {
86 qualifier, err := uuidscip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/.Parsescip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/Parse().(qualiferString)
87 if err != nil {
88 return ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#{}, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error parsing qualifer %q: %s", qualiferString, err)
89 }
90 ace.TagQualifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagQualifier. = &qualifier
91 }
92
93 ace.Permissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Permissions. = parts[2]
94
95 if err := ace.Validatescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Validate().(); err != nil {
96 return ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#{}, err
97 }
98 return ace, nil
99 }
100
101 // String returns the string form of the ACE - this does not check that it is valid
102 func (ace *ACEscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#) Stringscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#String().() string {
103 prefix := ""
104 if ace.IsDefaultscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#IsDefault. {
105 prefix = "default:"
106 }
107 qualifierString := ""
108 if ace.TagQualifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagQualifier. != nil {
109 qualifierString = ace.TagQualifierscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagQualifier..Stringscip-go gomod github.com/google/uuid v1.1.1 `github.com/google/uuid`/UUID#String().()
110 }
111 return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("%s%s:%s:%s", prefix, ace.TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#TagType., qualifierString, ace.Permissionsscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/ACE#Permissions.)
112 }
113
114 func validateTagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/validateTagType().(tagType TagTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagType#) error {
115 switch tagType {
116 case TagTypeUserscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeUser.,
117 TagTypeGroupscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeGroup.,
118 TagTypeMaskscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeMask.,
119 TagTypeOtherscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/accesscontrol`/TagTypeOther.:
120 return nil
121 }
122 return fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unrecognized TagType: %q", tagType)
123 }