-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor configutil and fix bug with catalog parsing
This will refactor configutil to pass the validators in sync config function so that defaulting and validation can be performed separately default validators are exposed to be used by deps catalog parsing was broken as soon as it find the other key for same catalog so fixed that refactored internal catalog parsing to have index data in map to convert the strut back to configmap added utility to convert struct back to configmap to be used by deps and added unit tests
- Loading branch information
1 parent
3f9bcd0
commit 17aae4b
Showing
16 changed files
with
336 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package settings | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
func ConvertPacStructToConfigMap(settings *Settings) map[string]string { | ||
config := map[string]string{} | ||
if settings == nil { | ||
return config | ||
} | ||
structValue := reflect.ValueOf(settings).Elem() | ||
structType := reflect.TypeOf(settings).Elem() | ||
|
||
for i := 0; i < structType.NumField(); i++ { | ||
field := structType.Field(i) | ||
fieldName := field.Name | ||
|
||
jsonTag := field.Tag.Get("json") | ||
if jsonTag == "-" { | ||
continue | ||
} | ||
key := strings.ToLower(jsonTag) | ||
element := structValue.FieldByName(fieldName) | ||
if !element.IsValid() { | ||
continue | ||
} | ||
|
||
//nolint | ||
switch field.Type.Kind() { | ||
case reflect.String: | ||
config[key] = element.String() | ||
case reflect.Bool: | ||
config[key] = strconv.FormatBool(element.Bool()) | ||
case reflect.Int: | ||
config[key] = strconv.FormatInt(element.Int(), 10) | ||
case reflect.Ptr: | ||
// for hub catalogs map | ||
if key == "" { | ||
data := element.Interface().(*sync.Map) | ||
data.Range(func(key, value interface{}) bool { | ||
catalogData := value.(HubCatalog) | ||
if key == "default" { | ||
config[HubURLKey] = catalogData.URL | ||
config[HubCatalogNameKey] = catalogData.Name | ||
return true | ||
} | ||
config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "id")] = key.(string) | ||
config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "name")] = catalogData.Name | ||
config[fmt.Sprintf("%s-%s-%s", "catalog", catalogData.Index, "url")] = catalogData.URL | ||
return true | ||
}) | ||
} | ||
default: | ||
// Skip unsupported field types | ||
continue | ||
} | ||
} | ||
|
||
return config | ||
} |
Oops, something went wrong.