types.go 3.1 KB

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