Language: Go
Label: safe
CWE: CWE-798 \u2014 Use of Hard-coded Credentials
The product contains hard-coded credentials, such as a password or cryptographic key, which it uses for its own inbound authentication, outbound communication to external components, or encryption of internal data.

Code:
func ReadConfig(c *config.Config, path ...string) error {
	v := viper.New()
	v.SetConfigName("app")
	v.SetConfigType("yaml")

	for i := range path {
		configFilePaths = append(configFilePaths, path[i])
	}
	for i := range configFilePaths {
		realDir := file.ReplaceHomeDir(configFilePaths[i])

		if exists := fileutil.Exist(realDir); !exists {
			fmt.Println(fmt.Sprintf(configNotFoundSkipErr, realDir))
			continue
		}

		v.AddConfigPath(realDir)
		if err := v.ReadInConfig(); err != nil {
			fmt.Println(fmt.Sprintf(configReadErr, realDir, err.Error()))
			continue
		}
		if err := v.MergeInConfig(); err != nil {
			fmt.Println(fmt.Sprintf(configMergeErr, configFilePaths))
		}

	}

	var configMap map[string]interface{}
	if err := v.Unmarshal(&configMap); err != nil {
		return err
	}
	str, err := json.Marshal(&configMap)
	if err != nil {
		return err
	}
	if err := json.Unmarshal(str, &c); err != nil {
		return nil
	}
	if c.Spec.Jwt.Key == "" {
		v.Set("spec.jwt.key", generate(32))
		if err := v.WriteConfig(); err != nil {
			return err
		}
	}
	return nil
}