func (sc *ServerConfig) GetAllowedHosts() []string {
	return append([]string{sc.Host}, sc.AllowedHosts...)
}
GetAllowedHosts returns the allowed hosts for this server. Requests whose host is not found in this slice should be
rejected by the server.
package config
import (
	"time"
	"github.com/rs/zerolog/log"
)
func NewDefaultConfig() *AgentConfig {
	config := AgentConfig{
		Version: "",
		Author:  "Optimizely Inc.",
		Name:    "optimizely",
		Admin: AdminConfig{
			Auth: ServiceAuthConfig{
				Clients:            make([]OAuthClientCredentials, 0),
				HMACSecrets:        make([]string, 0),
				TTL:                0,
				JwksURL:            "",
				JwksUpdateInterval: 0,
			},
			Port: "8088",
		},
		API: APIConfig{
			Auth: ServiceAuthConfig{
				Clients:            make([]OAuthClientCredentials, 0),
				HMACSecrets:        make([]string, 0),
				TTL:                0,
				JwksURL:            "",
				JwksUpdateInterval: 0,
			},
			CORS: CORSConfig{
				AllowedOrigins: nil,
				AllowedMethods: nil,
				AllowedHeaders:     []string{},
				ExposedHeaders:     []string{},
				AllowedCredentials: false,
				MaxAge:             300,
			},
			MaxConns:            0,
			Port:                "8080",
			EnableNotifications: false,
			EnableOverrides:     false,
		},
		Log: LogConfig{
			Pretty: false,
			Level:  "info",
		},
		Client: ClientConfig{
			PollingInterval:     1 * time.Minute,
			BatchSize:           10,
			QueueSize:           1000,
			FlushInterval:       30 * time.Second,
			DatafileURLTemplate: "https://cdn.optimizely.com/datafiles/%s.json",
			EventURL:            "https://logx.optimizely.com/v1/events",
			SdkKeyRegex: "^\\w+(:\\w+)?$",
		},
		Runtime: RuntimeConfig{
			BlockProfileRate:     0,  
			MutexProfileFraction: 0,  
		},
		Server: ServerConfig{
			AllowedHosts:    []string{"localhost"},
			ReadTimeout:     5 * time.Second,
			WriteTimeout:    10 * time.Second,
			HealthCheckPath: "/health",
			CertFile:        "",
			KeyFile:         "",
			DisabledCiphers: make([]string, 0),
			Host:            "127.0.0.1",
			Interceptors:    make(map[string]interface{}),
			BatchRequests: BatchRequestsConfig{
				MaxConcurrency:  10,
				OperationsLimit: 500,
			},
		},
		Webhook: WebhookConfig{
			Port: "8085",
		},
	}
	return &config
}
type AgentConfig struct {
	Version string `json:"version"`
	Author  string `json:"author"`
	Name    string `json:"name"`
	SDKKeys []string `yaml:"sdkKeys" json:"sdkKeys"`
	Admin   AdminConfig   `json:"admin"`
	API     APIConfig     `json:"api"`
	Log     LogConfig     `json:"log"`
	Client  ClientConfig  `json:"client"`
	Runtime RuntimeConfig `json:"runtime"`
	Server  ServerConfig  `json:"server"`
	Webhook WebhookConfig `json:"webhook"`
}
var HTTPSDisabledWarning = "keyfile and certfile not available, so server will use HTTP. For production deployments, it is recommended to either set keyfile and certfile for HTTPS, or run Agent behind a load balancer/reverse proxy that uses HTTPS."
var AuthDisabledWarningTemplate = "Authorization not enabled for %v endpoint. For production deployments, authorization is recommended."
func (ac *AgentConfig) LogConfigWarnings() {
	if !ac.Server.isHTTPSEnabled() {
		log.Warn().Msg(HTTPSDisabledWarning)
	}
	if !ac.API.Auth.isAuthorizationEnabled() {
		log.Warn().Msgf(AuthDisabledWarningTemplate, "API")
	}
	if !ac.Admin.Auth.isAuthorizationEnabled() {
		log.Warn().Msgf(AuthDisabledWarningTemplate, "Admin")
	}
}
type ClientConfig struct {
	PollingInterval     time.Duration `json:"pollingInterval"`
	BatchSize           int           `json:"batchSize" default:"10"`
	QueueSize           int           `json:"queueSize" default:"1000"`
	FlushInterval       time.Duration `json:"flushInterval" default:"30s"`
	DatafileURLTemplate string        `json:"datafileURLTemplate"`
	EventURL            string        `json:"eventURL"`
	SdkKeyRegex         string        `json:"sdkKeyRegex"`
}
type LogConfig struct {
	Pretty bool   `json:"pretty"`
	Level  string `json:"level"`
}
type PluginConfigs map[string]interface{}
type ServerConfig struct {
	AllowedHosts    []string            `json:"allowedHosts"`
	ReadTimeout     time.Duration       `json:"readTimeout"`
	WriteTimeout    time.Duration       `json:"writeTimeout"`
	CertFile        string              `json:"certFile"`
	KeyFile         string              `json:"keyFile"`
	DisabledCiphers []string            `json:"disabledCiphers"`
	HealthCheckPath string              `json:"healthCheckPath"`
	Host            string              `json:"host"`
	BatchRequests   BatchRequestsConfig `json:"batchRequests"`
	Interceptors    PluginConfigs       `json:"interceptors"`
}
func (sc *ServerConfig) isHTTPSEnabled() bool {
	return sc.KeyFile != "" && sc.CertFile != ""
}