initialize.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //go:build ee
  2. // +build ee
  3. package pro
  4. import (
  5. controller "github.com/gravitl/netmaker/controllers"
  6. "github.com/gravitl/netmaker/logic"
  7. "github.com/gravitl/netmaker/models"
  8. "github.com/gravitl/netmaker/mq"
  9. proControllers "github.com/gravitl/netmaker/pro/controllers"
  10. proLogic "github.com/gravitl/netmaker/pro/logic"
  11. "github.com/gravitl/netmaker/servercfg"
  12. "golang.org/x/exp/slog"
  13. )
  14. // InitPro - Initialize Pro Logic
  15. func InitPro() {
  16. servercfg.IsPro = true
  17. models.SetLogo(retrieveProLogo())
  18. controller.HttpMiddlewares = append(
  19. controller.HttpMiddlewares,
  20. proControllers.OnlyServerAPIWhenUnlicensedMiddleware,
  21. )
  22. controller.HttpHandlers = append(
  23. controller.HttpHandlers,
  24. proControllers.MetricHandlers,
  25. proControllers.RelayHandlers,
  26. proControllers.UserHandlers,
  27. )
  28. logic.EnterpriseCheckFuncs = append(logic.EnterpriseCheckFuncs, func() {
  29. // == License Handling ==
  30. ClearLicenseCache()
  31. if err := ValidateLicense(); err != nil {
  32. slog.Error(err.Error())
  33. return
  34. }
  35. slog.Info("proceeding with Paid Tier license")
  36. logic.SetFreeTierForTelemetry(false)
  37. // == End License Handling ==
  38. AddLicenseHooks()
  39. if servercfg.GetServerConfig().RacAutoDisable {
  40. AddRacHooks()
  41. }
  42. resetFailover()
  43. })
  44. logic.EnterpriseFailoverFunc = proLogic.SetFailover
  45. logic.EnterpriseResetFailoverFunc = proLogic.ResetFailover
  46. logic.EnterpriseResetAllPeersFailovers = proLogic.WipeAffectedFailoversOnly
  47. logic.DenyClientNodeAccess = proLogic.DenyClientNode
  48. logic.IsClientNodeAllowed = proLogic.IsClientNodeAllowed
  49. logic.AllowClientNodeAccess = proLogic.RemoveDeniedNodeFromClient
  50. logic.SetClientDefaultACLs = proLogic.SetClientDefaultACLs
  51. logic.SetClientACLs = proLogic.SetClientACLs
  52. logic.UpdateProNodeACLs = proLogic.UpdateProNodeACLs
  53. logic.GetMetrics = proLogic.GetMetrics
  54. logic.UpdateMetrics = proLogic.UpdateMetrics
  55. logic.DeleteMetrics = proLogic.DeleteMetrics
  56. logic.GetRelays = proLogic.GetRelays
  57. logic.GetAllowedIpsForRelayed = proLogic.GetAllowedIpsForRelayed
  58. logic.RelayedAllowedIPs = proLogic.RelayedAllowedIPs
  59. logic.UpdateRelayed = proLogic.UpdateRelayed
  60. logic.SetRelayedNodes = proLogic.SetRelayedNodes
  61. logic.RelayUpdates = proLogic.RelayUpdates
  62. mq.UpdateMetrics = proLogic.MQUpdateMetrics
  63. }
  64. func resetFailover() {
  65. nets, err := logic.GetNetworks()
  66. if err == nil {
  67. for _, net := range nets {
  68. err = proLogic.ResetFailover(net.NetID)
  69. if err != nil {
  70. slog.Error("failed to reset failover", "network", net.NetID, "error", err.Error())
  71. }
  72. }
  73. }
  74. }
  75. func retrieveProLogo() string {
  76. return `
  77. __ __ ______ ______ __ __ ______ __ __ ______ ______
  78. /\ "-.\ \ /\ ___\ /\__ _\ /\ "-./ \ /\ __ \ /\ \/ / /\ ___\ /\ == \
  79. \ \ \-. \ \ \ __\ \/_/\ \/ \ \ \-./\ \ \ \ __ \ \ \ _"-. \ \ __\ \ \ __<
  80. \ \_\\"\_\ \ \_____\ \ \_\ \ \_\ \ \_\ \ \_\ \_\ \ \_\ \_\ \ \_____\ \ \_\ \_\
  81. \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/ \/_/\/_/ \/_____/ \/_/ /_/
  82. ___ ___ ____
  83. ____ ____ ____ / _ \ / _ \ / __ \ ____ ____ ____
  84. /___/ /___/ /___/ / ___/ / , _// /_/ / /___/ /___/ /___/
  85. /___/ /___/ /___/ /_/ /_/|_| \____/ /___/ /___/ /___/
  86. `
  87. }