forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
26 lines (24 loc) · 783 Bytes
/
client.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
package serviceaccounts
import (
kapi "k8s.io/kubernetes/pkg/api"
)
// IsValidServiceAccountToken returns true if the given secret contains a service account token valid for the given service account
// TODO, these should collapse onto the upstream method
func IsValidServiceAccountToken(serviceAccount *kapi.ServiceAccount, secret *kapi.Secret) bool {
if secret.Type != kapi.SecretTypeServiceAccountToken {
return false
}
if secret.Namespace != serviceAccount.Namespace {
return false
}
if secret.Annotations[kapi.ServiceAccountNameKey] != serviceAccount.Name {
return false
}
if secret.Annotations[kapi.ServiceAccountUIDKey] != string(serviceAccount.UID) {
return false
}
if len(secret.Data[kapi.ServiceAccountTokenKey]) == 0 {
return false
}
return true
}