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 6721274
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions apis/lagoon/v1beta2/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ 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 {
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 {
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 6721274

Please sign in to comment.