fix: Parse boolean in slice for gitauth (#5113)

This was causing a panic for the new `no_refesh` option!
This commit is contained in:
Kyle Carberry
2022-11-17 07:52:11 -06:00
committed by GitHub
parent 8e468c49cb
commit 60cec022eb
2 changed files with 5 additions and 1 deletions
+3 -1
View File
@@ -529,9 +529,11 @@ func readSliceFromViper[T any](vip *viper.Viper, key string, value any) []T {
newType := reflect.Indirect(reflect.New(elementType))
instance = &newType
}
switch instance.Field(i).Type().String() {
switch v := instance.Field(i).Type().String(); v {
case "[]string":
value = vip.GetStringSlice(configKey)
case "bool":
value = vip.GetBool(configKey)
default:
}
instance.Field(i).Set(reflect.ValueOf(value))
+2
View File
@@ -167,6 +167,7 @@ func TestConfig(t *testing.T) {
"CODER_GITAUTH_0_TOKEN_URL": "https://token.com",
"CODER_GITAUTH_0_REGEX": "github.com",
"CODER_GITAUTH_0_SCOPES": "read write",
"CODER_GITAUTH_0_NO_REFRESH": "true",
"CODER_GITAUTH_1_ID": "another",
"CODER_GITAUTH_1_TYPE": "gitlab",
@@ -187,6 +188,7 @@ func TestConfig(t *testing.T) {
TokenURL: "https://token.com",
Regex: "github.com",
Scopes: []string{"read", "write"},
NoRefresh: true,
}, {
ID: "another",
Type: "gitlab",