func ParseConfig()

in traffic_ops/traffic_ops_golang/config/config.go [461:546]


func ParseConfig(cfg Config) (Config, error) {
	missings := ""
	if cfg.Cert == "" {
		missings += `"cert", `
	}
	if cfg.Key == "" {
		missings += `"key", `
	}
	if cfg.Port == "" {
		missings += "port, "
	}
	if len(cfg.Secrets) == 0 {
		missings += "secrets, "
	}
	if cfg.LogLocationError == "" {
		cfg.LogLocationError = log.LogLocationNull
	}
	if cfg.LogLocationWarning == "" {
		cfg.LogLocationWarning = log.LogLocationNull
	}
	if cfg.LogLocationInfo == "" {
		cfg.LogLocationInfo = log.LogLocationNull
	}
	if cfg.LogLocationDebug == "" {
		cfg.LogLocationDebug = log.LogLocationNull
	}
	if cfg.LogLocationEvent == "" {
		cfg.LogLocationEvent = log.LogLocationNull
	}
	if cfg.DBMaxIdleConnections == 0 {
		cfg.DBMaxIdleConnections = DBMaxIdleConnectionsDefault
	}
	if cfg.DBConnMaxLifetimeSeconds == 0 {
		cfg.DBConnMaxLifetimeSeconds = DBConnMaxLifetimeSecondsDefault
	}
	if cfg.DBQueryTimeoutSeconds == 0 {
		cfg.DBQueryTimeoutSeconds = DefaultDBQueryTimeoutSecs
	}
	if cfg.UserCacheRefreshIntervalSec < 0 {
		cfg.UserCacheRefreshIntervalSec = 0
	}
	if cfg.ServerUpdateStatusCacheRefreshIntervalSec < 0 {
		cfg.ServerUpdateStatusCacheRefreshIntervalSec = 0
	}

	invalidTOURLStr := ""
	var err error
	rawURL := fmt.Sprintf("cert=%s&key=%s", cfg.Cert, cfg.Key)
	if cfg.URL, err = url.Parse(rawURL); err != nil {
		invalidTOURLStr = fmt.Sprintf("invalid Traffic Ops URL '%s': %v", rawURL, err)
	}
	cfg.KeyPath = cfg.GetKeyPath()
	cfg.CertPath = cfg.GetCertPath()

	newURL := url.URL{Scheme: "https", Host: cfg.URL.Host}
	cfg.URL = &newURL

	if cfg.ConfigTO == nil {
		missings += "to, "
	} else {
		if cfg.ConfigTO.BaseURL == nil || cfg.ConfigTO.BaseURL.String() == "" {
			missings += "to.base_url, "
		}
		if cfg.ConfigTO.EmailFrom == nil || cfg.ConfigTO.EmailFrom.String() == "<@>" {
			missings += "to.email_from, "
		}
		if cfg.ConfigTO.NoAccountFoundMessage == nil || *cfg.ConfigTO.NoAccountFoundMessage == "" {
			missings += "to.no_account_found_msg, "
		}
	}

	if len(missings) > 0 {
		missings = "missing fields: " + missings[:len(missings)-2] // strip final `, `
	}

	errStr := missings
	if errStr != "" && invalidTOURLStr != "" {
		errStr += "; "
	}
	errStr += invalidTOURLStr
	if err := ValidateRoutingBlacklist(cfg.RoutingBlacklist); err != nil {
		return Config{}, err
	}

	return cfg, nil
}