From 482036182bc59ba39e3e0a52a34bcdac64c1f025 Mon Sep 17 00:00:00 2001 From: RoyUP9 <87927115+RoyUP9@users.noreply.github.com> Date: Thu, 30 Dec 2021 14:58:53 +0200 Subject: [PATCH] Added setting ui mode - enterprise or normal (#575) --- agent/main.go | 24 ++++++++++++++++++++++++ cli/cmd/installRunner.go | 1 + shared/models.go | 1 + 3 files changed, 26 insertions(+) diff --git a/agent/main.go b/agent/main.go index 38c7e569d..e9609c586 100644 --- a/agent/main.go +++ b/agent/main.go @@ -24,6 +24,8 @@ import ( "plugin" "regexp" "sort" + "strconv" + "strings" "syscall" "time" @@ -59,6 +61,7 @@ const ( socketConnectionRetries = 30 socketConnectionRetryDelay = time.Second * 2 socketHandshakeTimeout = time.Second * 2 + uiIndexPath = "./site/index.html" ) func main() { @@ -251,7 +254,12 @@ func hostApi(socketHarOutputChannel chan<- *tapApi.OutputChannelItem) { } app.Use(DisableRootStaticCache()) + + if err := setUIMode(); err != nil { + logger.Log.Panicf("Error setting ui mode, err: %v", err) + } app.Use(static.ServeRoot("/", "./site")) + app.Use(CORSMiddleware()) // This has to be called after the static middleware, does not work if its called before api.WebSocketRoutes(app, &eventHandlers, startTime) @@ -291,6 +299,22 @@ func CORSMiddleware() gin.HandlerFunc { } } +func setUIMode() error { + read, err := ioutil.ReadFile(uiIndexPath) + if err != nil { + return err + } + + replacedContent := strings.Replace(string(read), "__IS_STANDALONE__", strconv.FormatBool(config.Config.StandaloneMode), 1) + + err = ioutil.WriteFile(uiIndexPath, []byte(replacedContent), 0) + if err != nil { + return err + } + + return nil +} + func parseEnvVar(env string) map[string][]v1.Pod { var mapOfList map[string][]v1.Pod diff --git a/cli/cmd/installRunner.go b/cli/cmd/installRunner.go index e73b26be6..962d32098 100644 --- a/cli/cmd/installRunner.go +++ b/cli/cmd/installRunner.go @@ -65,6 +65,7 @@ func getInstallMizuAgentConfig(maxDBSizeBytes int64, tapperResources shared.Reso TapperResources: tapperResources, MizuResourcesNamespace: config.Config.MizuResourcesNamespace, AgentDatabasePath: shared.DataDirPath, + StandaloneMode: true, } return &mizuAgentConfig diff --git a/shared/models.go b/shared/models.go index 17efc230a..abf0c8b67 100644 --- a/shared/models.go +++ b/shared/models.go @@ -40,6 +40,7 @@ type MizuAgentConfig struct { TapperResources Resources `json:"tapperResources"` MizuResourcesNamespace string `json:"mizuResourceNamespace"` AgentDatabasePath string `json:"agentDatabasePath"` + StandaloneMode bool `json:"standaloneMode"` } type WebSocketMessageMetadata struct {