| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | package modelsimport (	"time")// 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}// 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"`}// 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	}	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()}
 |