types.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package ee
  2. import "fmt"
  3. const (
  4. api_endpoint = "https://api.controller.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. // Limits - limits to be referenced throughout server
  11. var Limits = GlobalLimits{
  12. Servers: 0,
  13. Users: 0,
  14. Nodes: 0,
  15. Clients: 0,
  16. Networks: 0,
  17. FreeTier: false,
  18. }
  19. // GlobalLimits - struct for holding global limits on this netmaker server in memory
  20. type GlobalLimits struct {
  21. Servers int
  22. Users int
  23. Nodes int
  24. Clients int
  25. FreeTier bool
  26. Networks int
  27. }
  28. // LicenseKey - the license key struct representation with associated data
  29. type LicenseKey struct {
  30. LicenseValue string `json:"license_value"` // actual (public) key and the unique value for the key
  31. Expiration int64 `json:"expiration"`
  32. LimitServers int `json:"limit_servers"`
  33. LimitUsers int `json:"limit_users"`
  34. LimitNodes int `json:"limit_nodes"`
  35. LimitClients int `json:"limit_clients"`
  36. Metadata string `json:"metadata"`
  37. SubscriptionID string `json:"subscription_id"` // for a paid subscription (non-free-tier license)
  38. FreeTier string `json:"free_tier"` // yes if free tier
  39. IsActive string `json:"is_active"` // yes if active
  40. }
  41. // ValidatedLicense - the validated license struct
  42. type ValidatedLicense struct {
  43. LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
  44. EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
  45. }
  46. // LicenseSecret - the encrypted struct for sending user-id
  47. type LicenseSecret struct {
  48. UserID string `json:"user_id" binding:"required"` // UUID for user foreign key to User table
  49. Limits LicenseLimits `json:"limits" binding:"required"`
  50. }
  51. // LicenseLimits - struct license limits
  52. type LicenseLimits struct {
  53. Servers int `json:"servers" binding:"required"`
  54. Users int `json:"users" binding:"required"`
  55. Nodes int `json:"nodes" binding:"required"`
  56. Clients int `json:"clients" binding:"required"`
  57. }
  58. // LicenseLimits.SetDefaults - sets the default values for limits
  59. func (l *LicenseLimits) SetDefaults() {
  60. l.Clients = 0
  61. l.Servers = 1
  62. l.Nodes = 0
  63. l.Users = 1
  64. }
  65. // ValidateLicenseRequest - used for request to validate license endpoint
  66. type ValidateLicenseRequest struct {
  67. 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)
  68. EncryptedPart string `json:"secret" binding:"required"`
  69. }
  70. type licenseResponseCache struct {
  71. Body []byte `json:"body" binding:"required"`
  72. }