Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add json marshal for v1beta1 tasks #269

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading