| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | package modelsimport (	"time")const (	Undefined KeyType = iota	TimeExpiration	Uses	Unlimited)// KeyType - the type of enrollment keytype KeyType int// String - returns the string representation of a KeyTypefunc (k KeyType) String() string {	return [...]string{"Undefined", "TimeExpiration", "Uses", "Unlimited"}[k]}// EnrollmentToken - the tokenized version of an enrollmentkey;// to be used for host registrationtype EnrollmentToken struct {	Server string `json:"server"`	Value  string `json:"value"`}// EnrollmentKeyLength - the length of an enrollment key - 62^16 unique possibilitiesconst EnrollmentKeyLength = 32// EnrollmentKey - the key used to register hosts and join them to specific networkstype EnrollmentKey struct {	Expiration    time.Time `json:"expiration"`	UsesRemaining int       `json:"uses_remaining"`	Value         string    `json:"value"`	Networks      []string  `json:"networks"`	Unlimited     bool      `json:"unlimited"`	Tags          []string  `json:"tags"`	Token         string    `json:"token,omitempty"` // B64 value of EnrollmentToken	Type          KeyType   `json:"type"`}// APIEnrollmentKey - used to create enrollment keys via APItype APIEnrollmentKey struct {	Expiration    int64    `json:"expiration"`	UsesRemaining int      `json:"uses_remaining"`	Networks      []string `json:"networks"`	Unlimited     bool     `json:"unlimited"`	Tags          []string `json:"tags"`	Type          KeyType  `json:"type"`}// RegisterResponse - the response to a successful enrollment registertype RegisterResponse struct {	ServerConf    ServerConfig `json:"server_config"`	RequestedHost Host         `json:"requested_host"`}// EnrollmentKey.IsValid - checks if the key is still valid to usefunc (k *EnrollmentKey) IsValid() bool {	if k == nil {		return false	}	if k.UsesRemaining > 0 {		return true	}	if !k.Expiration.IsZero() && time.Now().Before(k.Expiration) {		return true	}	if k.Type == Undefined {		return false	}	return k.Unlimited}// EnrollmentKey.Validate - validate's an EnrollmentKey// should be used during creationfunc (k *EnrollmentKey) Validate() bool {	return k.Networks != nil &&		k.Tags != nil &&		len(k.Value) == EnrollmentKeyLength &&		k.IsValid()}
 |