types.go 3.0 KB

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