-
Notifications
You must be signed in to change notification settings - Fork 475
/
selector.go
45 lines (38 loc) · 987 Bytes
/
selector.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
// The selector package exports functions useful for manipulating and generating
// spire selectors
package selector
import (
"fmt"
"strings"
"github.com/spiffe/spire/proto/spire/common"
)
// Type and Value are delimited by a colon (:)
// e.g. "unix:uid:1000"
const Delimiter = ":"
type Selector struct {
Type string
Value string
}
func New(c *common.Selector) *Selector {
s := &Selector{
Type: c.Type,
Value: c.Value,
}
return s
}
func (s *Selector) Raw() *common.Selector {
c := &common.Selector{
Type: s.Type,
Value: s.Value,
}
return c
}
func Validate(s *common.Selector) error {
// Validate that the Type does not contain a colon (:) to prevent accidental misconfigurations
// e.g. type="unix:user" value="root" is the invalid selector
// and type="unix" value"user:root" is the valid selector
if strings.Contains(s.Type, Delimiter) {
return fmt.Errorf("selector type must not contain a colon; invalid selector type: %q", s.Type)
}
return nil
}