netmaker/ee/initialize.go

75 lines
2.6 KiB
Go
Raw Normal View History

2022-09-15 01:26:31 +08:00
//go:build ee
// +build ee
package ee
import (
controller "github.com/gravitl/netmaker/controllers"
"github.com/gravitl/netmaker/ee/ee_controllers"
2022-09-22 03:13:17 +08:00
eelogic "github.com/gravitl/netmaker/ee/logic"
2022-09-15 01:26:31 +08:00
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
2022-09-23 03:01:59 +08:00
"github.com/gravitl/netmaker/servercfg"
2022-09-15 01:26:31 +08:00
)
// InitEE - Initialize EE Logic
func InitEE() {
2022-09-15 22:23:19 +08:00
setIsEnterprise()
2022-09-15 01:26:31 +08:00
models.SetLogo(retrieveEELogo())
controller.HttpHandlers = append(controller.HttpHandlers, ee_controllers.MetricHandlers)
logic.EnterpriseCheckFuncs = append(logic.EnterpriseCheckFuncs, func() {
// == License Handling ==
ValidateLicense()
if Limits.FreeTier {
logger.Log(0, "proceeding with Free Tier license")
logic.SetFreeTierForTelemetry(true)
2022-09-15 01:26:31 +08:00
} else {
logger.Log(0, "proceeding with Paid Tier license")
logic.SetFreeTierForTelemetry(false)
2022-09-15 01:26:31 +08:00
}
// == End License Handling ==
AddLicenseHooks()
2022-09-29 04:50:57 +08:00
resetFailover()
2022-09-15 01:26:31 +08:00
})
logic.EnterpriseFailoverFunc = eelogic.SetFailover
logic.EnterpriseResetFailoverFunc = eelogic.ResetFailover
logic.EnterpriseResetAllPeersFailovers = eelogic.WipeAffectedFailoversOnly
2022-09-15 01:26:31 +08:00
}
func setControllerLimits() {
logic.Node_Limit = Limits.Nodes
logic.Users_Limit = Limits.Users
logic.Clients_Limit = Limits.Clients
logic.Free_Tier = Limits.FreeTier
2022-09-23 03:01:59 +08:00
servercfg.Is_EE = true
2022-09-15 01:26:31 +08:00
}
func resetFailover() {
nets, err := logic.GetNetworks()
if err == nil {
for _, net := range nets {
err = eelogic.ResetFailover(net.NetID)
if err != nil {
logger.Log(0, "failed to reset failover on network", net.NetID, ":", err.Error())
}
}
}
}
2022-09-28 02:42:14 +08:00
2022-09-15 01:26:31 +08:00
func retrieveEELogo() string {
return `
__ __ ______ ______ __ __ ______ __ __ ______ ______
/\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
\ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
\ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
\/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
___ ___ ____
____ ____ ____ / _ \ / _ \ / __ \ ____ ____ ____
/___/ /___/ /___/ / ___/ / , _// /_/ / /___/ /___/ /___/
/___/ /___/ /___/ /_/ /_/|_| \____/ /___/ /___/ /___/
`
}