Skip to content

Commit

Permalink
Fix parsing of install response (#1436)
Browse files Browse the repository at this point in the history
New and old APIs for packages include the assets in different fields
in the response.
Old API uses `response`, while new API uses `items`.
  • Loading branch information
jsoriano authored Sep 5, 2023
1 parent 006a64d commit ec2bd80
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/kibana/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ func processResults(action string, statusCode int, respBody []byte) ([]packages.
}

var resp struct {
Assets []packages.Asset `json:"response"`
// Assets are here when old packages API is used (with hyphen, before 8.0).
Response []packages.Asset `json:"response"`

// Assets are here when new packages API is used (with slash, since 8.0).
Items []packages.Asset `json:"items"`
}

if err := json.Unmarshal(respBody, &resp); err != nil {
return nil, fmt.Errorf("could not convert %s package (response) to JSON: %w", action, err)
}

return resp.Assets, nil
if len(resp.Response) > 0 {
return resp.Response, nil
}

return resp.Items, nil
}

0 comments on commit ec2bd80

Please sign in to comment.