Repository: h2oai/wave
File: cmd/wave/main.go (Go)

Code before:
	}

	if auth.InactivityTimeout, err = time.ParseDuration(inactivityTimeout); err != nil {
		panic(err)
	}

	conf.WebDir, _ = filepath.Abs(conf.WebDir)
	conf.DataDir, _ = filepath.Abs(conf.DataDir)

	conf.Version = Version
	conf.BuildDate = BuildDate

	conf.Keychain = kc

	if conf.IDE {
		conf.Proxy = true // IDE won't function without proxy
	}

	requiredEnvOIDC := map[string]string{
		"oidc-client-id":     auth.ClientID,
		"oidc-client-secret": auth.ClientSecret,
		"oidc-provider-url":  auth.ProviderURL,
		"oidc-redirect-url":  auth.RedirectURL,
	}
	envOIDCEmpty := getEmptyOIDCValues(auth, requiredEnvOIDC)
	emptyRequiredOIDCParams := len(envOIDCEmpty)
	if emptyRequiredOIDCParams == 0 {
		conf.Auth = &auth
	}
	if emptyRequiredOIDCParams > 0 && emptyRequiredOIDCParams != len(requiredEnvOIDC) {
		log.Println("#", "warning: the following OIDC required params were not set: ", emptyRequiredOIDCParams)
	}

	if conf.IDE {
		conf.Proxy = true // IDE won't function without proxy
	}

	wave.Run(conf)
}

// getEmptyOIDCValues checks if any of the required OIDC values were not set and returns which were not.
func getEmptyOIDCValues(auth wave.AuthConf, requiredEnvOIDC map[string]string) []string {
	var emptyRequiredOIDCParams []string
	for key, val := range requiredEnvOIDC {
		if val == "" {
			switch key {
			case "oidc-client-id":
				emptyRequiredOIDCParams = append(emptyRequiredOIDCParams, "oidc-client-id")
			case "oidc-client-secret":
				emptyRequiredOIDCParams = append(emptyRequiredOIDCParams, "oidc-client-secret")
			case "oidc-provider-url":

Review comment (security):
naming:

```suggestion
	emptyRequiredOIDCParams := getEmptyOIDCValues(auth, requiredEnvOIDC)
	emptyRequiredOIDCParamsCount := len(emptyRequiredOIDCParams)
```

Code after:
	}

	if auth.InactivityTimeout, err = time.ParseDuration(inactivityTimeout); err != nil {
		panic(err)
	}

	conf.WebDir, _ = filepath.Abs(conf.WebDir)
	conf.DataDir, _ = filepath.Abs(conf.DataDir)

	conf.Version = Version
	conf.BuildDate = BuildDate

	conf.Keychain = kc

	requiredEnvOIDC := map[string]string{
		"oidc-client-id":     auth.ClientID,
		"oidc-client-secret": auth.ClientSecret,
		"oidc-provider-url":  auth.ProviderURL,
		"oidc-redirect-url":  auth.RedirectURL,
	}
	emptyRequiredOIDCParams := getEmptyOIDCValues(requiredEnvOIDC)
	emptyRequiredOIDCParamsCount := len(emptyRequiredOIDCParams)
	if emptyRequiredOIDCParamsCount == 0 {
		conf.Auth = &auth
	}
	if emptyRequiredOIDCParamsCount > 0 && emptyRequiredOIDCParamsCount != len(requiredEnvOIDC) {
		log.Println("#", "warning: the following OIDC required params were not set: ", emptyRequiredOIDCParams)
	}

	if conf.IDE {
		conf.Proxy = true // IDE won't function without proxy
	}

	wave.Run(conf)
}

func getEmptyOIDCValues(requiredEnvOIDC map[string]string) []string {
	var emptyRequiredOIDCParams []string
	for param, val := range requiredEnvOIDC {
		if val == "" {
			emptyRequiredOIDCParams = append(emptyRequiredOIDCParams, param)
		}
	}
	return emptyRequiredOIDCParams
}

func getEnv(key, value string) string {
	if v, ok := os.LookupEnv("H2O_WAVE_" + strings.ToUpper(strings.ReplaceAll(key, "-", "_"))); ok {
		return v
	}
	return value