From 672127426d97f14fd51ecd866887b7b33fba6e41 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 26 Nov 2024 11:46:10 +1100 Subject: [PATCH] fix: add json unmarshal fix for v1beta1 retrieving as v1beta2 --- apis/lagoon/v1beta2/lagoontask_types.go | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/apis/lagoon/v1beta2/lagoontask_types.go b/apis/lagoon/v1beta2/lagoontask_types.go index 8e9e4d6f..9f5b0024 100644 --- a/apis/lagoon/v1beta2/lagoontask_types.go +++ b/apis/lagoon/v1beta2/lagoontask_types.go @@ -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 {