mirror of
https://github.com/harness/drone.git
synced 2025-05-17 09:30:00 +08:00
fix: [CDE-632]: Fixing marshalling and unmarshalling logic for features and mounts. (#3405)
* fix: [CDE-632]: Fixing marshalling and unmarshalling logic for features and mounts.
This commit is contained in:
parent
5116297202
commit
d9c8d1c4d1
@ -188,6 +188,10 @@ func (f *FeatureValue) UnmarshalJSON(data []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FeatureValue) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(f.Options)
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Features) UnmarshalJSON(data []byte) error {
|
func (f *Features) UnmarshalJSON(data []byte) error {
|
||||||
if *f == nil {
|
if *f == nil {
|
||||||
*f = make(Features)
|
*f = make(Features)
|
||||||
@ -248,15 +252,27 @@ type Mount struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mount) UnmarshalJSON(data []byte) error {
|
func (m *Mount) UnmarshalJSON(data []byte) error {
|
||||||
if err := json.Unmarshal(data, m); err == nil {
|
type Alias Mount
|
||||||
|
aux := &struct {
|
||||||
|
*Alias
|
||||||
|
}{
|
||||||
|
Alias: (*Alias)(m),
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &aux); err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dst, err := stringToObject(string(data))
|
|
||||||
|
var str string
|
||||||
|
if err := json.Unmarshal(data, &str); err == nil {
|
||||||
|
dst, err := stringToObject(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*m = *dst
|
*m = *dst
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("failed to unmarshal JSON: %s", string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseMountsFromRawSlice(values []any) ([]*Mount, error) {
|
func ParseMountsFromRawSlice(values []any) ([]*Mount, error) {
|
||||||
@ -318,8 +334,6 @@ func stringToObject(mountStr string) (*Mount, error) {
|
|||||||
}
|
}
|
||||||
case "target", "dst", "destination":
|
case "target", "dst", "destination":
|
||||||
newMount.Target = val
|
newMount.Target = val
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unexpected key '%s' in '%s'", key, field)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &newMount, nil
|
return &newMount, nil
|
||||||
|
@ -58,11 +58,18 @@ func (o *OptionDefinition) ValidateValue(optionValue any, optionKey string, feat
|
|||||||
switch o.Type {
|
switch o.Type {
|
||||||
case enum.FeatureOptionValueTypeBoolean:
|
case enum.FeatureOptionValueTypeBoolean:
|
||||||
boolValue, ok := optionValue.(bool)
|
boolValue, ok := optionValue.(bool)
|
||||||
if !ok {
|
if ok {
|
||||||
|
return strconv.FormatBool(boolValue), nil
|
||||||
|
}
|
||||||
|
stringValue, ok := optionValue.(string)
|
||||||
|
if ok {
|
||||||
|
parsedBoolValue, err := strconv.ParseBool(stringValue)
|
||||||
|
if err == nil {
|
||||||
|
return strconv.FormatBool(parsedBoolValue), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
return "", fmt.Errorf("error during resolving feature %s, option Id %s "+
|
return "", fmt.Errorf("error during resolving feature %s, option Id %s "+
|
||||||
"expects boolean, got %s ", featureSource, optionKey, optionValue)
|
"expects boolean, got %s ", featureSource, optionKey, optionValue)
|
||||||
}
|
|
||||||
return strconv.FormatBool(boolValue), nil
|
|
||||||
case enum.FeatureOptionValueTypeString:
|
case enum.FeatureOptionValueTypeString:
|
||||||
stringValue, ok := optionValue.(string)
|
stringValue, ok := optionValue.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user