2
0

types.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. FailOvers int `json:"fail_overs"`
  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. }