types.go 2.9 KB

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