|
@@ -4,6 +4,21 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const (
|
|
|
|
+ Undefined KeyType = iota
|
|
|
|
+ TimeExpiration
|
|
|
|
+ Uses
|
|
|
|
+ Unlimited
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// KeyType - the type of enrollment key
|
|
|
|
+type KeyType int
|
|
|
|
+
|
|
|
|
+// String - returns the string representation of a KeyType
|
|
|
|
+func (k KeyType) String() string {
|
|
|
|
+ return [...]string{"Undefined", "TimeExpiration", "Uses", "Unlimited"}[k]
|
|
|
|
+}
|
|
|
|
+
|
|
// EnrollmentToken - the tokenized version of an enrollmentkey;
|
|
// EnrollmentToken - the tokenized version of an enrollmentkey;
|
|
// to be used for host registration
|
|
// to be used for host registration
|
|
type EnrollmentToken struct {
|
|
type EnrollmentToken struct {
|
|
@@ -23,6 +38,7 @@ type EnrollmentKey struct {
|
|
Unlimited bool `json:"unlimited"`
|
|
Unlimited bool `json:"unlimited"`
|
|
Tags []string `json:"tags"`
|
|
Tags []string `json:"tags"`
|
|
Token string `json:"token,omitempty"` // B64 value of EnrollmentToken
|
|
Token string `json:"token,omitempty"` // B64 value of EnrollmentToken
|
|
|
|
+ Type KeyType `json:"type"`
|
|
}
|
|
}
|
|
|
|
|
|
// APIEnrollmentKey - used to create enrollment keys via API
|
|
// APIEnrollmentKey - used to create enrollment keys via API
|
|
@@ -32,6 +48,7 @@ type APIEnrollmentKey struct {
|
|
Networks []string `json:"networks"`
|
|
Networks []string `json:"networks"`
|
|
Unlimited bool `json:"unlimited"`
|
|
Unlimited bool `json:"unlimited"`
|
|
Tags []string `json:"tags"`
|
|
Tags []string `json:"tags"`
|
|
|
|
+ Type KeyType `json:"type"`
|
|
}
|
|
}
|
|
|
|
|
|
// RegisterResponse - the response to a successful enrollment register
|
|
// RegisterResponse - the response to a successful enrollment register
|
|
@@ -51,6 +68,9 @@ func (k *EnrollmentKey) IsValid() bool {
|
|
if !k.Expiration.IsZero() && time.Now().Before(k.Expiration) {
|
|
if !k.Expiration.IsZero() && time.Now().Before(k.Expiration) {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
+ if k.Type == Undefined {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
|
|
return k.Unlimited
|
|
return k.Unlimited
|
|
}
|
|
}
|