types.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  56. // Usage.SetDefaults - sets the default values for usage
  57. func (l *Usage) SetDefaults() {
  58. l.Clients = 0
  59. l.Servers = 1
  60. l.Hosts = 0
  61. l.Users = 1
  62. l.Networks = 0
  63. l.Ingresses = 0
  64. l.Egresses = 0
  65. }
  66. // ValidateLicenseRequest - used for request to validate license endpoint
  67. type ValidateLicenseRequest struct {
  68. LicenseKey string `json:"license_key" binding:"required"`
  69. 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)
  70. EncryptedPart string `json:"secret" binding:"required"`
  71. }
  72. type licenseResponseCache struct {
  73. Body []byte `json:"body" binding:"required"`
  74. }