2023-09-01 10:12:05 +08:00
//go:build ee
// +build ee
package pro
2022-09-14 03:25:56 +08:00
2023-08-08 18:29:38 +08:00
import (
"fmt"
)
// constants for accounts api hosts
const (
// accountsHostDevelopment is the accounts api host for development environment
accountsHostDevelopment = "https://api.dev.accounts.netmaker.io"
// accountsHostStaging is the accounts api host for staging environment
accountsHostStaging = "https://api.staging.accounts.netmaker.io"
// accountsHostProduction is the accounts api host for production environment
accountsHostProduction = "https://api.accounts.netmaker.io"
)
2022-09-14 03:25:56 +08:00
const (
license_cache_key = "license_response_cache"
license_validation_err_msg = "invalid license"
server_id_key = "nm-server-id"
)
var errValidation = fmt . Errorf ( license_validation_err_msg )
// LicenseKey - the license key struct representation with associated data
type LicenseKey struct {
2023-08-09 01:47:49 +08:00
LicenseValue string ` json:"license_value" ` // actual (public) key and the unique value for the key
Expiration int64 ` json:"expiration" `
2023-08-16 22:07:46 +08:00
UsageServers int ` json:"limit_servers" `
UsageUsers int ` json:"limit_users" `
UsageClients int ` json:"limit_clients" `
UsageHosts int ` json:"limit_hosts" `
UsageNetworks int ` json:"limit_networks" `
UsageIngresses int ` json:"limit_ingresses" `
UsageEgresses int ` json:"limit_egresses" `
2023-08-09 01:47:49 +08:00
Metadata string ` json:"metadata" `
IsActive bool ` json:"is_active" ` // yes if active
2022-09-14 03:25:56 +08:00
}
// ValidatedLicense - the validated license struct
type ValidatedLicense struct {
LicenseValue string ` json:"license_value" binding:"required" ` // license that validation is being requested for
EncryptedLicense string ` json:"encrypted_license" binding:"required" ` // to be decrypted by Netmaker using Netmaker server's private key
}
// LicenseSecret - the encrypted struct for sending user-id
type LicenseSecret struct {
2023-08-09 01:47:49 +08:00
AssociatedID string ` json:"associated_id" binding:"required" ` // UUID for user foreign key to User table
2023-08-16 22:07:46 +08:00
Usage Usage ` json:"limits" binding:"required" `
2022-09-14 03:25:56 +08:00
}
2023-08-09 01:47:49 +08:00
// Usage - struct for license usage
type Usage struct {
2023-10-06 14:22:58 +08:00
Servers int ` json:"servers" `
Users int ` json:"users" `
Hosts int ` json:"hosts" `
Clients int ` json:"clients" `
Networks int ` json:"networks" `
Ingresses int ` json:"ingresses" `
Egresses int ` json:"egresses" `
Relays int ` json:"relays" `
InternetGateways int ` json:"internet_gateways" `
2022-09-14 03:25:56 +08:00
}
2023-08-09 01:47:49 +08:00
// Usage.SetDefaults - sets the default values for usage
func ( l * Usage ) SetDefaults ( ) {
2022-09-14 03:25:56 +08:00
l . Clients = 0
l . Servers = 1
2023-06-28 23:03:06 +08:00
l . Hosts = 0
2022-09-14 03:25:56 +08:00
l . Users = 1
2023-06-28 23:03:06 +08:00
l . Networks = 0
2023-08-09 01:47:49 +08:00
l . Ingresses = 0
l . Egresses = 0
2023-10-06 14:22:58 +08:00
l . Relays = 0
l . InternetGateways = 0
2022-09-14 03:25:56 +08:00
}
// ValidateLicenseRequest - used for request to validate license endpoint
type ValidateLicenseRequest struct {
2023-06-28 23:03:06 +08:00
LicenseKey string ` json:"license_key" binding:"required" `
2022-09-14 03:25:56 +08:00
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)
EncryptedPart string ` json:"secret" binding:"required" `
}
type licenseResponseCache struct {
Body [ ] byte ` json:"body" binding:"required" `
}