Skip to content

Commit

Permalink
Merge pull request #269 from uselagoon/v1task-marshal
Browse files Browse the repository at this point in the history
fix: add json marshal for v1beta1 tasks
  • Loading branch information
tobybellwood authored Nov 7, 2024
2 parents c30e457 + e6afa30 commit b65633a
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 b65633a

Please sign in to comment.