Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
tag some config fields as secret
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Jul 30, 2024
1 parent d63d6ca commit 464c8e1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ type Config struct {
MqttHost string `json:"mqtt_host"`
MqttPort string `json:"mqtt_port"`
MqttClientId string `json:"mqtt_client_id"`
MqttUser string `json:"mqtt_user"`
MqttPw string `json:"mqtt_pw"`
MqttUser string `json:"mqtt_user" config:"secret"`
MqttPw string `json:"mqtt_pw" config:"secret"`
MqttPrefix string `json:"mqtt_prefix"`
MqttQos int `json:"mqtt_qos"`
MqttSubscribeTopic string `json:"mqtt_subscribe_topic"`
MqttUnsubscribeTopic string `json:"mqtt_unsubscribe_topic"`
MqttLogTopic string `json:"mqtt_log_topic"`

AuthEndpoint string `json:"auth_endpoint"`
AuthClientId string `json:"auth_client_id"`
AuthClientSecret string `json:"auth_client_secret"`
AuthUserName string `json:"auth_user_name"`
AuthPassword string `json:"auth_password"`
AuthClientId string `json:"auth_client_id" config:"secret"`
AuthClientSecret string `json:"auth_client_secret" config:"secret"`
AuthUserName string `json:"auth_user_name" config:"secret"`
AuthPassword string `json:"auth_password" config:"secret"`

Debug bool `json:"debug"`
}
Expand Down Expand Up @@ -115,10 +115,13 @@ func handleEnvironmentVars(config *Config) {
configType := configValue.Type()
for index := 0; index < configType.NumField(); index++ {
fieldName := configType.Field(index).Name
fieldConfig := configType.Field(index).Tag.Get("config")
envName := fieldNameToEnvName(fieldName)
envValue := os.Getenv(envName)
if envValue != "" {
fmt.Println("use environment variable: ", envName, " = ", envValue)
if !strings.Contains(fieldConfig, "secret") {
fmt.Println("use environment variable: ", envName, " = ", envValue)
}
if configValue.FieldByName(fieldName).Kind() == reflect.Int64 {
i, _ := strconv.ParseInt(envValue, 10, 64)
configValue.FieldByName(fieldName).SetInt(i)
Expand Down

0 comments on commit 464c8e1

Please sign in to comment.