-
Notifications
You must be signed in to change notification settings - Fork 0
Update validation schema #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e84f62e
d615039
5189ac8
de8eb1f
b59c700
cc5aa0a
e784e47
ea74911
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,88 @@ | ||
| package main | ||
|
|
||
| import "encoding/json" | ||
|
|
||
| type Registry struct { | ||
| Name string `yaml:"name" json:"name"` | ||
| RegistryHost string `yaml:"registry" json:"registry"` | ||
| AuthStrategy string `yaml:"auth_strategy" json:"auth_strategy"` | ||
| RegistryHost string `yaml:"url,omitempty" json:"registry,omitempty"` | ||
| AuthStrategy string `yaml:"auth_strategy" json:"auth_strategy,omitempty"` | ||
| Default bool `yaml:"default" json:"default"` | ||
| ImageTypes []string `yaml:"image_types" json:"image_types"` | ||
| BasePaths map[string]string `yaml:"base_paths" json:"base_paths"` | ||
|
jalvarezit marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Custom YAML unmarshaling to support both 'registry' and 'url' mapping to RegistryHost | ||
| func (r *Registry) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
|
jalvarezit marked this conversation as resolved.
|
||
| var aux map[string]interface{} | ||
| if err := unmarshal(&aux); err != nil { | ||
| return err | ||
| } | ||
| if name, ok := aux["name"].(string); ok { | ||
| r.Name = name | ||
| } | ||
| if reg, ok := aux["registry"].(string); ok { | ||
| r.RegistryHost = reg | ||
| } else if url, ok := aux["url"].(string); ok { | ||
| r.RegistryHost = url | ||
| } | ||
|
Comment on lines
+23
to
+27
|
||
| if auth, ok := aux["auth_strategy"].(string); ok { | ||
| r.AuthStrategy = auth | ||
| } | ||
| if def, ok := aux["default"].(bool); ok { | ||
| r.Default = def | ||
| } | ||
| if img, ok := aux["image_types"].([]interface{}); ok { | ||
| r.ImageTypes = make([]string, len(img)) | ||
| for i, v := range img { | ||
| if s, ok := v.(string); ok { | ||
| r.ImageTypes[i] = s | ||
| } | ||
| } | ||
| } | ||
| if bp, ok := aux["base_paths"].(map[string]interface{}); ok { | ||
| r.BasePaths = make(map[string]string) | ||
| for k, v := range bp { | ||
| if s, ok := v.(string); ok { | ||
| r.BasePaths[k] = s | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Custom JSON unmarshaling to support both 'registry' and 'url' mapping to Url | ||
| func (r *Registry) UnmarshalJSON(data []byte) error { | ||
| var aux map[string]interface{} | ||
| if err := json.Unmarshal(data, &aux); err != nil { | ||
| return err | ||
| } | ||
| if name, ok := aux["name"].(string); ok { | ||
| r.Name = name | ||
| } | ||
| if reg, ok := aux["registry"].(string); ok { | ||
| r.RegistryHost = reg | ||
| } | ||
|
jalvarezit marked this conversation as resolved.
|
||
| if auth, ok := aux["auth_strategy"].(string); ok { | ||
| r.AuthStrategy = auth | ||
| } | ||
| if def, ok := aux["default"].(bool); ok { | ||
| r.Default = def | ||
| } | ||
| if img, ok := aux["image_types"].([]interface{}); ok { | ||
| r.ImageTypes = make([]string, len(img)) | ||
| for i, v := range img { | ||
| if s, ok := v.(string); ok { | ||
| r.ImageTypes[i] = s | ||
| } | ||
| } | ||
| } | ||
| if bp, ok := aux["base_paths"].(map[string]interface{}); ok { | ||
| r.BasePaths = make(map[string]string) | ||
| for k, v := range bp { | ||
| if s, ok := v.(string); ok { | ||
| r.BasePaths[k] = s | ||
| } | ||
| } | ||
| } | ||
|
jalvarezit marked this conversation as resolved.
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.