Skip to content

Commit

Permalink
fix: add json marshal for v1beta1 tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Nov 6, 2024
1 parent c30e457 commit e6afa30
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apis/lagoon/v1beta1/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
Expand All @@ -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 {
Expand Down

0 comments on commit e6afa30

Please sign in to comment.