types.go 3.1 KB

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