From 44e54402f2c208f522c10454be7cc8ff4e9ce7a3 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Fri, 26 Jul 2024 10:28:48 +0100 Subject: [PATCH] Sort Identities (#41) --- pkg/handler/handler.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index b9aae92..99c87a8 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -331,7 +331,7 @@ func (h *Handler) GetApiV1OrganizationsOrganizationIDIdentities(w http.ResponseW return } - var resources unikornv1.IdentityList + var result unikornv1.IdentityList options := &client.ListOptions{ LabelSelector: labels.SelectorFromSet(map[string]string{ @@ -339,12 +339,16 @@ func (h *Handler) GetApiV1OrganizationsOrganizationIDIdentities(w http.ResponseW }), } - if err := h.client.List(r.Context(), &resources, options); err != nil { + if err := h.client.List(r.Context(), &result, options); err != nil { errors.HandleError(w, r, errors.OAuth2ServerError("unable to list identities").WithError(err)) return } - util.WriteJSONResponse(w, r, http.StatusOK, convertIdentityList(resources)) + slices.SortFunc(result.Items, func(a, b unikornv1.Identity) int { + return cmp.Compare(a.Name, b.Name) + }) + + util.WriteJSONResponse(w, r, http.StatusOK, convertIdentityList(result)) } func (h *Handler) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentities(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter) {