types.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. LimitServers int `json:"limit_servers"`
  25. LimitUsers int `json:"limit_users"`
  26. LimitHosts int `json:"limit_hosts"`
  27. LimitNetworks int `json:"limit_networks"`
  28. LimitClients int `json:"limit_clients"`
  29. Metadata string `json:"metadata"`
  30. IsActive bool `json:"is_active"` // yes if active
  31. }
  32. // ValidatedLicense - the validated license struct
  33. type ValidatedLicense struct {
  34. LicenseValue string `json:"license_value" binding:"required"` // license that validation is being requested for
  35. EncryptedLicense string `json:"encrypted_license" binding:"required"` // to be decrypted by Netmaker using Netmaker server's private key
  36. }
  37. // LicenseSecret - the encrypted struct for sending user-id
  38. type LicenseSecret struct {
  39. AssociatedID string `json:"associated_id" binding:"required"` // UUID for user foreign key to User table
  40. Limits LicenseLimits `json:"limits" binding:"required"`
  41. }
  42. // LicenseLimits - struct license limits
  43. type LicenseLimits struct {
  44. Servers int `json:"servers"`
  45. Users int `json:"users"`
  46. Hosts int `json:"hosts"`
  47. Clients int `json:"clients"`
  48. Networks int `json:"networks"`
  49. }
  50. // LicenseLimits.SetDefaults - sets the default values for limits
  51. func (l *LicenseLimits) SetDefaults() {
  52. l.Clients = 0
  53. l.Servers = 1
  54. l.Hosts = 0
  55. l.Users = 1
  56. l.Networks = 0
  57. }
  58. // ValidateLicenseRequest - used for request to validate license endpoint
  59. type ValidateLicenseRequest struct {
  60. LicenseKey string `json:"license_key" binding:"required"`
  61. 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)
  62. EncryptedPart string `json:"secret" binding:"required"`
  63. }
  64. type licenseResponseCache struct {
  65. Body []byte `json:"body" binding:"required"`
  66. }