-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
44 lines (37 loc) · 1021 Bytes
/
types.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
package types
import (
"fmt"
"strings"
)
type Validation struct {
Valid bool `json:"valid"`
Error string `json:"error"`
Claims Claims `json:"claims"`
}
type Claims struct {
ID string `json:"id"`
Subject string `json:"subject"`
Groups []string `json:"groups"`
Extra interface{} `json:"extra"`
}
type Assertion struct {
IDPrefix string
SubjectPrefix string
GroupPrefix string
}
func (v *Validation) Assert(a Assertion) {
if !strings.HasPrefix(v.Claims.ID, a.IDPrefix) {
v.Valid = false
v.Error += fmt.Sprintf("Expected ID %q to have prefix %q\n", v.Claims.ID, a.IDPrefix)
}
if !strings.HasPrefix(v.Claims.Subject, a.SubjectPrefix) {
v.Valid = false
v.Error += fmt.Sprintf("Expected subject %q to have prefix %q\n", v.Claims.Subject, a.SubjectPrefix)
}
for _, group := range v.Claims.Groups {
if !strings.HasPrefix(group, a.SubjectPrefix) {
v.Valid = false
v.Error += fmt.Sprintf("Expected group %q to have prefix %q\n", group, a.GroupPrefix)
}
}
}