types.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package ee
  2. import "fmt"
  3. const (
  4. api_endpoint = "https://api.accounts.netmaker.io/api/v1/license/validate"
  5. license_cache_key = "license_response_cache"
  6. license_validation_err_msg = "invalid license"
  7. server_id_key = "nm-server-id"
  8. )
  9. var errValidation = fmt.Errorf(license_validation_err_msg)
  10. // LicenseKey - the license key struct representation with associated data
  11. type LicenseKey struct {
  12. LicenseValue string `json:"license_value"` // actual (public) key and the unique value for the key
  13. Expiration int64 `json:"expiration"`
  14. LimitServers int `json:"limit_servers"`
  15. LimitUsers int `json:"limit_users"`
  16. LimitHosts int `json:"limit_hosts"`
  17. LimitNetworks int `json:"limit_networks"`
  18. LimitClients int `json:"limit_clients"`
  19. Metadata string `json:"metadata"`
  20. IsActive bool `json:"is_active"` // yes if active
  21. }
  22. // ValidatedLicense - the validated license struct
  23. type ValidatedLicense struct {
  24. LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
  25. EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
  26. }
  27. // LicenseSecret - the encrypted struct for sending user-id
  28. type LicenseSecret struct {
  29. AssociatedID string `json:"associated_id" binding:"required"` // UUID for user foreign key to User table
  30. Limits LicenseLimits `json:"limits" binding:"required"`
  31. }
  32. // LicenseLimits - struct license limits
  33. type LicenseLimits struct {
  34. Servers int `json:"servers"`
  35. Users int `json:"users"`
  36. Hosts int `json:"hosts"`
  37. Clients int `json:"clients"`
  38. Networks int `json:"networks"`
  39. }
  40. // LicenseLimits.SetDefaults - sets the default values for limits
  41. func (l *LicenseLimits) SetDefaults() {
  42. l.Clients = 0
  43. l.Servers = 1
  44. l.Hosts = 0
  45. l.Users = 1
  46. l.Networks = 0
  47. }
  48. // ValidateLicenseRequest - used for request to validate license endpoint
  49. type ValidateLicenseRequest struct {
  50. LicenseKey string `json:"license_key" binding:"required"`
  51. NmServerPubKey string `json:"nm_server_pub_key" binding:"required"` // Netmaker server public key used to send data back to Netmaker for the Netmaker server to decrypt (eg output from validating license)
  52. EncryptedPart string `json:"secret" binding:"required"`
  53. }
  54. type licenseResponseCache struct {
  55. Body []byte `json:"body" binding:"required"`
  56. }