From e6afa3041149b3313a5886afde40a693a263fe92 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 6 Nov 2024 19:39:10 +1100 Subject: [PATCH] fix: add json marshal for v1beta1 tasks --- apis/lagoon/v1beta1/lagoontask_types.go | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apis/lagoon/v1beta1/lagoontask_types.go b/apis/lagoon/v1beta1/lagoontask_types.go index 46426cc6..14afee1b 100644 --- a/apis/lagoon/v1beta1/lagoontask_types.go +++ b/apis/lagoon/v1beta1/lagoontask_types.go @@ -187,6 +187,20 @@ func (a *LagoonTaskEnvironment) UnmarshalJSON(data []byte) error { return nil } +// convert to uint as required for environment ID for backwards compatability +func (a *LagoonTaskEnvironment) MarshalJSON() ([]byte, error) { + type LagoonTaskEnvironmentA LagoonTaskEnvironment + id, _ := strconv.Atoi(a.ID) + idUint := uint(id) + return json.Marshal(&struct { + ID *uint `json:"id"` + *LagoonTaskEnvironmentA + }{ + ID: &idUint, + LagoonTaskEnvironmentA: (*LagoonTaskEnvironmentA)(a), + }) +} + // convert to string as required for project ID for backwards compatability func (a *LagoonTaskProject) UnmarshalJSON(data []byte) error { tmpMap := map[string]interface{}{} @@ -197,6 +211,20 @@ func (a *LagoonTaskProject) UnmarshalJSON(data []byte) error { return nil } +// convert to uint as required for environment ID for backwards compatability +func (a *LagoonTaskProject) MarshalJSON() ([]byte, error) { + type LagoonTaskProjectA LagoonTaskProject + id, _ := strconv.Atoi(a.ID) + idUint := uint(id) + return json.Marshal(&struct { + ID *uint `json:"id"` + *LagoonTaskProjectA + }{ + ID: &idUint, + LagoonTaskProjectA: (*LagoonTaskProjectA)(a), + }) +} + // 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 {