diff --git a/cmd/menshen/main.go b/cmd/menshen/main.go index b920ce5aa17ccfe82ae4b2c68791bbd4ff6131a7..2ded484a409d23bd7081c00418a9cd12ed9a0eb2 100644 --- a/cmd/menshen/main.go +++ b/cmd/menshen/main.go @@ -42,6 +42,7 @@ var ( dbFile = "db-file" agentSharedKey = "agent-shared-key" lastSeenCutoffMillis = "last-seen-cutoff-millis" + isDevelopmentRun = "development" ) // @version 0.5.2 @@ -86,6 +87,7 @@ func main() { flag.String(agentSharedKey, "", "Shared key for verifying HMAC of agent registration requests. If empty, will disable agent registration.") flag.Int64(lastSeenCutoffMillis, 0, "the amount of milliseconds to wait since the last heartbeat from a bridge or gateway before removing them from the resources that are returned to clients. If this is zero then no cutoff will be applied") flag.Bool(verbose, false, "set log verbosity to DEBUG") + flag.Bool(isDevelopmentRun, false, "Enable development features like swagger endpoints and non-production ready endpoints") pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() @@ -139,6 +141,7 @@ func main() { err = viper.BindEnv(agentSharedKey, "MENSHEN_AGENT_SHARED_KEY") err = viper.BindEnv(lastSeenCutoffMillis, "MENSHEN_LAST_SEEN_CUTOFF_MILLIS") err = viper.BindEnv(verbose, "MENSHEN_VERBOSE") + err = viper.BindEnv(isDevelopmentRun, "MENSHEN_DEVELOPMENT") } if err != nil { log.Fatal().Msgf("Failed to BindEnv: %s", err) @@ -160,27 +163,28 @@ func main() { bridges := strings.Split(bridgesStr, ",") cfg := &api.Config{ - EnableCertv3: viper.GetBool(enableCertv3), - AllowGatewayListing: viper.GetBool(allowGatewayList), - AllowBridgeListing: viper.GetBool(allowBridgeList), - AutoTLS: viper.GetBool(autoTLS), - ServerName: viper.GetString(serverName), - EIP: viper.GetString(fromEIPFile), - EIPURL: viper.GetString(fromEIPURL), - ProviderJson: viper.GetString(fromProviderJsonFile), - LocalBridges: bridges, - Port: viper.GetInt(port), - PortMetrics: viper.GetInt(portMetrics), - LoadBalancerAddr: lbAddr, - ClientCertURL: viper.GetString(clientCertURL), - CaFile: viper.GetString(caFile), - OvpnCaCrt: viper.GetString(ovpnCaCrt), - OvpnCaKey: viper.GetString(ovpnCaKey), - OvpnClientCrtExpiry: viper.GetInt(ovpnClientCrtExpiry), - Algo: viper.GetString(algo), - DBFile: viper.GetString(dbFile), - AgentSharedKey: viper.GetString(agentSharedKey), - LastSeenCutoffMillis: viper.GetInt64(lastSeenCutoffMillis), + EnableCertv3: viper.GetBool(enableCertv3), + AllowGatewayListing: viper.GetBool(allowGatewayList), + AllowBridgeListing: viper.GetBool(allowBridgeList), + AutoTLS: viper.GetBool(autoTLS), + ServerName: viper.GetString(serverName), + EIP: viper.GetString(fromEIPFile), + EIPURL: viper.GetString(fromEIPURL), + ProviderJson: viper.GetString(fromProviderJsonFile), + LocalBridges: bridges, + Port: viper.GetInt(port), + PortMetrics: viper.GetInt(portMetrics), + LoadBalancerAddr: lbAddr, + ClientCertURL: viper.GetString(clientCertURL), + CaFile: viper.GetString(caFile), + OvpnCaCrt: viper.GetString(ovpnCaCrt), + OvpnCaKey: viper.GetString(ovpnCaKey), + OvpnClientCrtExpiry: viper.GetInt(ovpnClientCrtExpiry), + Algo: viper.GetString(algo), + DBFile: viper.GetString(dbFile), + AgentSharedKey: viper.GetString(agentSharedKey), + LastSeenCutoffMillis: viper.GetInt64(lastSeenCutoffMillis), + EnableDevelopmentFeatures: viper.GetBool(isDevelopmentRun), } if cfg.EIPURL != "" { diff --git a/pkg/api/api.go b/pkg/api/api.go index ff21d17a58f3d064d6cb86547b00e82164d532fd..b203a0ed47e2b3c92a3345456a9ace19023b9dbe 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -102,18 +102,16 @@ func InitServer(cfg *Config) *echo.Echo { e.GET("/api/5/openvpn/cert", CertGenHelper(r, cfg.OvpnCaCrt, cfg.OvpnCaKey, cfg.Algo, cfg.OvpnClientCrtExpiry, true)) - e.GET("/api/5/openvpn/config", GenConfigHelper(r, cfg)) - e.GET("/provider.json", r.GetProvider) - // document the API serving the Swagger spec - e.GET("/api/swagger/*", echoSwagger.WrapHandler) - - e.GET("/api/autoconf", DownloadConfigHelper(r, cfg)) - - e.GET("/api/help/ios", func(c echo.Context) error { - return c.HTML(http.StatusOK, help.HelpiOS) - }) + if cfg.EnableDevelopmentFeatures { + e.GET("/api/swagger/*", echoSwagger.WrapHandler) + e.GET("/api/5/openvpn/config", GenConfigHelper(r, cfg)) + e.GET("/api/autoconf", DownloadConfigHelper(r, cfg)) + e.GET("/api/help/ios", func(c echo.Context) error { + return c.HTML(http.StatusOK, help.HelpiOS) + }) + } if cfg.AgentSharedKey != "" { agentEndpoints := e.Group("/api/5/agent") diff --git a/pkg/api/config.go b/pkg/api/config.go index 3e7ee2c6b70957e0c43b4a91416fbe2e45a28c0c..d413e49d583031a273b7ddbad4e47085b7f0dcd7 100644 --- a/pkg/api/config.go +++ b/pkg/api/config.go @@ -22,10 +22,11 @@ type Config struct { OvpnCaKey string OvpnClientCrtExpiry int // ProviderJson is a file path to an existing provider.json - ProviderJson string - Algo string - DBFile string - AgentSharedKey string + ProviderJson string + Algo string + DBFile string + AgentSharedKey string + EnableDevelopmentFeatures bool // This is the amount of milliseconds to wait since the last heartbeat from a bridge or gateway before // removing them from the resources that are returned to clients.