Skip to content

Commit ec2bd80

Browse files
authored
Fix parsing of install response (#1436)
New and old APIs for packages include the assets in different fields in the response. Old API uses `response`, while new API uses `items`.
1 parent 006a64d commit ec2bd80

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/kibana/packages.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,20 @@ func processResults(action string, statusCode int, respBody []byte) ([]packages.
7676
}
7777

7878
var resp struct {
79-
Assets []packages.Asset `json:"response"`
79+
// Assets are here when old packages API is used (with hyphen, before 8.0).
80+
Response []packages.Asset `json:"response"`
81+
82+
// Assets are here when new packages API is used (with slash, since 8.0).
83+
Items []packages.Asset `json:"items"`
8084
}
8185

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

86-
return resp.Assets, nil
90+
if len(resp.Response) > 0 {
91+
return resp.Response, nil
92+
}
93+
94+
return resp.Items, nil
8795
}

0 commit comments

Comments
 (0)