netmaker/pro/initialize.go
Abhishek K 0638dcac49
NET-940: Inet Gws (#2828)
* internet gws apis

* add validate check for inet request

* add default gw changes to peer update

* update json tag

* add OS checks for inet gws

* add set defaul gw pro func

* allow disable and enable inet gw

* add inet handlers to pro

* add fields to api node

* add inet allowed ips

* add default gw to pull

* unset node inet details on deletion

* unset internet gw on network nodes

* unset inet gw fix

* unset inet gw fix

* send default gw ip

* fix inet node endpoint

* add default gw endpoint ip to pull resp

* validate after unset gws

* add inet client peer allowedips to inet node

* validate after unset gws

* fix allowed ips for inet peer and gw node

* fix allowed ips for inet peer and gw node

* fix allowed ips for inet peer and gw node

* fix allowed ips for inet peer and gw node

* fix inet gw and relayed conflict

* fix inet gw and relayed conflict

* fix update req

* fix update inet gw api

* when inet gw is peer ignore other allowedIps

* test relay

* revert test relay

* revert inet peer update changes

* channel internet traffic of relayed node to relay's inetgw

* channel internet traffic of relayed node to relay's inetgw

* channel internet traffic of relayed node to relay's inetgw

* add check for relayed node

* add inet info to peer update

* add inet info to peer update

* fix update node to persist inet info

* fix go tests

* egress ranges with inet gw fix

* egress ranges with inet gw fix

* disallow node acting using inet gw to act as inet gw

* add check to validate inet gw

* fix typos

* add firewall check

* set inetgw on ingress req on community

* set inetgw to false on community on ingress del
2024-02-28 08:46:51 +07:00

128 lines
4.5 KiB
Go

//go:build ee
// +build ee
package pro
import (
"time"
controller "github.com/gravitl/netmaker/controllers"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/mq"
proControllers "github.com/gravitl/netmaker/pro/controllers"
proLogic "github.com/gravitl/netmaker/pro/logic"
"github.com/gravitl/netmaker/servercfg"
"golang.org/x/exp/slog"
)
// InitPro - Initialize Pro Logic
func InitPro() {
servercfg.IsPro = true
models.SetLogo(retrieveProLogo())
controller.HttpMiddlewares = append(
controller.HttpMiddlewares,
proControllers.OnlyServerAPIWhenUnlicensedMiddleware,
)
controller.HttpHandlers = append(
controller.HttpHandlers,
proControllers.MetricHandlers,
proControllers.RelayHandlers,
proControllers.UserHandlers,
proControllers.FailOverHandlers,
proControllers.InetHandlers,
)
logic.EnterpriseCheckFuncs = append(logic.EnterpriseCheckFuncs, func() {
// == License Handling ==
enableLicenseHook := false
licenseKeyValue := servercfg.GetLicenseKey()
netmakerTenantID := servercfg.GetNetmakerTenantID()
if licenseKeyValue != "" && netmakerTenantID != "" {
enableLicenseHook = true
}
if !enableLicenseHook {
err := initTrial()
if err != nil {
logger.Log(0, "failed to init trial", err.Error())
enableLicenseHook = true
}
trialEndDate, err := getTrialEndDate()
if err != nil {
slog.Error("failed to get trial end date", "error", err)
enableLicenseHook = true
} else {
// check if trial ended
if time.Now().After(trialEndDate) {
// trial ended already
enableLicenseHook = true
}
}
}
if enableLicenseHook {
logger.Log(0, "starting license checker")
ClearLicenseCache()
if err := ValidateLicense(); err != nil {
slog.Error(err.Error())
return
}
logger.Log(0, "proceeding with Paid Tier license")
logic.SetFreeTierForTelemetry(false)
// == End License Handling ==
AddLicenseHooks()
} else {
logger.Log(0, "starting trial license hook")
addTrialLicenseHook()
}
if servercfg.GetServerConfig().RacAutoDisable {
AddRacHooks()
}
})
logic.ResetFailOver = proLogic.ResetFailOver
logic.ResetFailedOverPeer = proLogic.ResetFailedOverPeer
logic.CreateFailOver = proLogic.CreateFailOver
logic.GetFailOverPeerIps = proLogic.GetFailOverPeerIps
logic.DenyClientNodeAccess = proLogic.DenyClientNode
logic.IsClientNodeAllowed = proLogic.IsClientNodeAllowed
logic.AllowClientNodeAccess = proLogic.RemoveDeniedNodeFromClient
logic.SetClientDefaultACLs = proLogic.SetClientDefaultACLs
logic.SetClientACLs = proLogic.SetClientACLs
logic.UpdateProNodeACLs = proLogic.UpdateProNodeACLs
logic.GetMetrics = proLogic.GetMetrics
logic.UpdateMetrics = proLogic.UpdateMetrics
logic.DeleteMetrics = proLogic.DeleteMetrics
logic.GetRelays = proLogic.GetRelays
logic.GetAllowedIpsForRelayed = proLogic.GetAllowedIpsForRelayed
logic.RelayedAllowedIPs = proLogic.RelayedAllowedIPs
logic.UpdateRelayed = proLogic.UpdateRelayed
logic.SetRelayedNodes = proLogic.SetRelayedNodes
logic.RelayUpdates = proLogic.RelayUpdates
logic.GetTrialEndDate = getTrialEndDate
logic.SetDefaultGw = proLogic.SetDefaultGw
logic.SetDefaultGwForRelayedUpdate = proLogic.SetDefaultGwForRelayedUpdate
logic.UnsetInternetGw = proLogic.UnsetInternetGw
logic.SetInternetGw = proLogic.SetInternetGw
logic.GetAllowedIpForInetNodeClient = proLogic.GetAllowedIpForInetNodeClient
mq.UpdateMetrics = proLogic.MQUpdateMetrics
mq.UpdateMetricsFallBack = proLogic.MQUpdateMetricsFallBack
}
func retrieveProLogo() string {
return `
__ __ ______ ______ __ __ ______ __ __ ______ ______
/\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
\ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
\ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
\/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
___ ___ ____
____ ____ ____ / _ \ / _ \ / __ \ ____ ____ ____
/___/ /___/ /___/ / ___/ / , _// /_/ / /___/ /___/ /___/
/___/ /___/ /___/ /_/ /_/|_| \____/ /___/ /___/ /___/
`
}