-
Notifications
You must be signed in to change notification settings - Fork 1
/
kubeuser.go
60 lines (48 loc) · 1.1 KB
/
kubeuser.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
package kubeutil
import (
"fmt"
"reflect"
)
type Label struct {
Key string `json:"key"`
Value string `json:"value"`
}
// KubeUser
// Is used to label manifests and authenticate requests
type KubeUser struct {
// CustomerID - required
CustomerID int
// UserID requesting sync
UserID string
// Kind being synced
Kind string
// AuthorizationToken - Optional
AuthorizationToken string
// ReferenceID - user assigned ID for debugging
ReferenceID string
}
func (ku *KubeUser) New(customer int, user, id string) bool {
ku.CustomerID = customer
ku.UserID = user
ku.Kind = "KubeUser"
ku.AuthorizationToken = ""
ku.ReferenceID = id
return ku.IsValid()
}
func (ku *KubeUser) IsValid() bool {
return ku.CustomerID != 0 && ku.Kind != ""
}
func (ku *KubeUser) GenerateLables() []Label {
var labels []Label
v := reflect.ValueOf(*ku)
for i := 0; i < v.NumField(); i++ {
l := Label{}
fieldValue := v.Field(i)
fieldType := v.Type().Field(i)
fieldName := fieldType.Name
l.Value = fmt.Sprintf("%v", fieldValue.Interface())
l.Key = string(fieldName)
labels = append(labels, l)
}
return labels
}