Skip to content

Commit

Permalink
fix: add json unmarshal fix for v1beta1 retrieving as v1beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Nov 26, 2024
1 parent b65633a commit bd36d6a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions apis/lagoon/v1beta2/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,46 @@ func init() {
SchemeBuilder.Register(&LagoonTask{}, &LagoonTaskList{})
}

// convert to string as required for environment ID for backwards compatability
func (a *LagoonTaskEnvironment) UnmarshalJSON(data []byte) error {
tmpMap := map[string]interface{}{}
json.Unmarshal(data, &tmpMap)
if value, ok := tmpMap["id"]; ok {
if reflect.TypeOf(value).Kind() == reflect.String {
id, _ := strconv.Atoi(value.(string))
idUint := uint(id)
a.ID = &idUint
} else if reflect.TypeOf(value).Kind() == reflect.Float64 {
idUint := uint(value.(float64))
a.ID = &idUint
} else {
aid := value.(uint)
a.ID = &aid
}
}
return nil
}

// convert to string as required for project ID for backwards compatability
func (a *LagoonTaskProject) UnmarshalJSON(data []byte) error {
tmpMap := map[string]interface{}{}
json.Unmarshal(data, &tmpMap)
if value, ok := tmpMap["id"]; ok {
if reflect.TypeOf(value).Kind() == reflect.String {
id, _ := strconv.Atoi(value.(string))
idUint := uint(id)
a.ID = &idUint
} else if reflect.TypeOf(value).Kind() == reflect.Float64 {
idUint := uint(value.(float64))
a.ID = &idUint
} else {
aid := value.(uint)
a.ID = &aid
}
}
return nil
}

// this is a custom unmarshal function that will check deployerToken and sshKey which come from Lagoon as `1|0` booleans because javascript
// this converts them from floats to bools
func (a *LagoonAdvancedTaskInfo) UnmarshalJSON(data []byte) error {
Expand Down

0 comments on commit bd36d6a

Please sign in to comment.