fix(endpoints): filter by all edge stack states (#9218)

pull/9231/head
Chaim Lev-Ari 2023-07-19 18:21:47 +03:00 committed by GitHub
parent 9fa097d45f
commit 5ad83d0adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 11 deletions

View File

@ -87,17 +87,9 @@ func parseQuery(r *http.Request) (EnvironmentsQuery, error) {
edgeStackId, _ := request.RetrieveNumericQueryParameter(r, "edgeStackId", true)
edgeStackStatusQuery, _ := request.RetrieveQueryParameter(r, "edgeStackStatus", true)
var edgeStackStatus *portainer.EdgeStackStatusType
if edgeStackStatusQuery != "" {
edgeStackStatusNumber, err := strconv.Atoi(edgeStackStatusQuery)
if err != nil ||
edgeStackStatusNumber < 0 ||
edgeStackStatusNumber > int(portainer.EdgeStackStatusRemoving) {
return EnvironmentsQuery{}, errors.New("invalid edgeStackStatus parameter")
}
edgeStackStatus = ptr(portainer.EdgeStackStatusType(edgeStackStatusNumber))
edgeStackStatus, err := getEdgeStackStatusParam(r)
if err != nil {
return EnvironmentsQuery{}, err
}
return EnvironmentsQuery{
@ -544,3 +536,33 @@ func contains(strings []string, param string) bool {
return false
}
func getEdgeStackStatusParam(r *http.Request) (*portainer.EdgeStackStatusType, error) {
edgeStackStatusQuery, _ := request.RetrieveQueryParameter(r, "edgeStackStatus", true)
if edgeStackStatusQuery == "" {
return nil, nil
}
edgeStackStatusNumber, err := strconv.Atoi(edgeStackStatusQuery)
edgeStackStatus := portainer.EdgeStackStatusType(edgeStackStatusNumber)
if err != nil {
return nil, fmt.Errorf("failed parsing edgeStackStatus: %w", err)
}
if !slices.Contains([]portainer.EdgeStackStatusType{
portainer.EdgeStackStatusPending,
portainer.EdgeStackStatusDeploymentReceived,
portainer.EdgeStackStatusError,
portainer.EdgeStackStatusAcknowledged,
portainer.EdgeStackStatusRemoved,
portainer.EdgeStackStatusRemoteUpdateSuccess,
portainer.EdgeStackStatusImagesPulled,
portainer.EdgeStackStatusRunning,
portainer.EdgeStackStatusDeploying,
portainer.EdgeStackStatusRemoving,
}, edgeStackStatus) {
return nil, errors.New("invalid edgeStackStatus parameter")
}
return &edgeStackStatus, nil
}