types.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //go:build ee
  2. // +build ee
  3. package pro
  4. import (
  5. "errors"
  6. )
  7. const (
  8. license_cache_key = "license_response_cache"
  9. license_validation_err_msg = "invalid license"
  10. server_id_key = "nm-server-id"
  11. )
  12. var errValidation = errors.New(license_validation_err_msg)
  13. // LicenseKey - the license key struct representation with associated data
  14. type LicenseKey struct {
  15. LicenseValue string `json:"license_value"` // actual (public) key and the unique value for the key
  16. Expiration int64 `json:"expiration" swaggertype:"primitive,integer" format:"int64"`
  17. UsageServers int `json:"limit_servers"`
  18. UsageUsers int `json:"limit_users"`
  19. UsageClients int `json:"limit_clients"`
  20. UsageHosts int `json:"limit_hosts"`
  21. UsageNetworks int `json:"limit_networks"`
  22. UsageIngresses int `json:"limit_ingresses"`
  23. UsageEgresses int `json:"limit_egresses"`
  24. Metadata string `json:"metadata"`
  25. IsActive bool `json:"is_active"` // yes if active
  26. }
  27. // ValidatedLicense - the validated license struct
  28. type ValidatedLicense struct {
  29. LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
  30. EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
  31. }
  32. // LicenseSecret - the encrypted struct for sending user-id
  33. type LicenseSecret struct {
  34. AssociatedID string `json:"associated_id" binding:"required"` // UUID for user foreign key to User table
  35. Usage Usage `json:"limits" binding:"required"`
  36. }
  37. // Usage - struct for license usage
  38. type Usage struct {
  39. Servers int `json:"servers"`
  40. Users int `json:"users"`
  41. Hosts int `json:"hosts"`
  42. Clients int `json:"clients"`
  43. Networks int `json:"networks"`
  44. Ingresses int `json:"ingresses"`
  45. Egresses int `json:"egresses"`
  46. Relays int `json:"relays"`
  47. InternetGateways int `json:"internet_gateways"`
  48. FailOvers int `json:"fail_overs"`
  49. }
  50. // Usage.SetDefaults - sets the default values for usage
  51. func (l *Usage) SetDefaults() {
  52. l.Clients = 0
  53. l.Servers = 1
  54. l.Hosts = 0
  55. l.Users = 1
  56. l.Networks = 0
  57. l.Ingresses = 0
  58. l.Egresses = 0
  59. l.Relays = 0
  60. l.InternetGateways = 0
  61. }
  62. // ValidateLicenseRequest - used for request to validate license endpoint
  63. type ValidateLicenseRequest struct {
  64. LicenseKey string `json:"license_key" binding:"required"`
  65. 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)
  66. EncryptedPart string `json:"secret" binding:"required"`
  67. }
  68. type licenseResponseCache struct {
  69. Body []byte `json:"body" binding:"required"`
  70. }