From a627836cf35625a6630d5b7f17e2166808729f2a Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Thu, 12 Oct 2023 16:06:06 +0200 Subject: [PATCH] RHINENG-2547: add satellite_managed info to /ids/systems --- docs/v3/openapi.json | 30 +++++++++++++++++++++++++++++- manager/controllers/structures.go | 12 ++++++++++++ manager/controllers/systems.go | 13 +++++++++---- manager/controllers/utils.go | 26 ++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/docs/v3/openapi.json b/docs/v3/openapi.json index 1e244dee8..07452bbe9 100644 --- a/docs/v3/openapi.json +++ b/docs/v3/openapi.json @@ -3771,7 +3771,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/controllers.IDsResponse" + "$ref": "#/components/schemas/controllers.IDsSatelliteManagedResponse" } } } @@ -6280,6 +6280,17 @@ } } }, + "controllers.IDSatelliteManaged": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "satellite_managed": { + "type": "boolean" + } + } + }, "controllers.IDStatus": { "type": "object", "properties": { @@ -6302,6 +6313,23 @@ } } }, + "controllers.IDsSatelliteManagedResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/controllers.IDSatelliteManaged" + } + }, + "ids": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "controllers.IDsStatusResponse": { "type": "object", "properties": { diff --git a/manager/controllers/structures.go b/manager/controllers/structures.go index b748d4b75..aac9014e6 100644 --- a/manager/controllers/structures.go +++ b/manager/controllers/structures.go @@ -42,6 +42,11 @@ type IDStatus struct { Status string `json:"status"` } +type IDSatelliteManaged struct { + ID string `json:"id"` + SatelliteManaged bool `json:"satellite_managed"` +} + type IDsStatusResponse struct { Data []IDStatus `json:"data"` // backward compatibility @@ -49,6 +54,13 @@ type IDsStatusResponse struct { IDsResponse } +type IDsSatelliteManagedResponse struct { + Data []IDSatelliteManaged `json:"data"` + // backward compatibility + // TODO: delete later once UI is using only the new `data` field + IDsResponse +} + type SystemGroup struct { ID string `json:"id"` Name string `json:"name"` diff --git a/manager/controllers/systems.go b/manager/controllers/systems.go index d3a3ef5f3..38bb0a00d 100644 --- a/manager/controllers/systems.go +++ b/manager/controllers/systems.go @@ -35,6 +35,12 @@ type SystemsID struct { MetaTotalHelper } +type SystemsSatelliteManagedID struct { + ID string `query:"sp.inventory_id" gorm:"column:id"` + SystemSatelliteManaged + MetaTotalHelper +} + // nolint: lll type SystemDBLookupCommon struct { SystemIDAttribute @@ -296,7 +302,7 @@ func SystemsListHandler(c *gin.Context) { // @Param filter[system_profile][ansible][controller_version] query string false "Filter systems by ansible version" // @Param filter[system_profile][mssql] query string false "Filter systems by mssql version" // @Param filter[system_profile][mssql][version] query string false "Filter systems by mssql version" -// @Success 200 {object} IDsResponse +// @Success 200 {object} IDsSatelliteManagedResponse // @Failure 400 {object} utils.ErrorResponse // @Failure 500 {object} utils.ErrorResponse // @Router /ids/systems [get] @@ -307,18 +313,17 @@ func SystemsListIDsHandler(c *gin.Context) { return } // Error handled in method itself - var sids []SystemsID + var sids []SystemsSatelliteManagedID if err = query.Scan(&sids).Error; err != nil { LogAndRespError(c, err, "db error") return } - ids, err := systemsIDs(c, sids, meta) + resp, err := systemsSatelliteIDs(c, sids, meta) if err != nil { return // Error handled in method itself } - var resp = IDsResponse{IDs: ids} c.JSON(http.StatusOK, &resp) } diff --git a/manager/controllers/utils.go b/manager/controllers/utils.go index 9587a43c7..09b4333cf 100644 --- a/manager/controllers/utils.go +++ b/manager/controllers/utils.go @@ -600,6 +600,32 @@ func systemsIDs(c *gin.Context, systems []SystemsID, meta *ListMeta) ([]string, return ids, nil } +func systemsSatelliteIDs(c *gin.Context, systems []SystemsSatelliteManagedID, meta *ListMeta, +) (IDsSatelliteManagedResponse, error) { + var total int + resp := IDsSatelliteManagedResponse{} + if len(systems) > 0 { + total = systems[0].Total + } + if meta.Offset > total { + err := errors.New("Offset") + LogAndRespBadRequest(c, err, InvalidOffsetMsg) + return resp, err + } + if systems == nil { + return resp, nil + } + ids := make([]string, len(systems)) + data := make([]IDSatelliteManaged, len(systems)) + for i, x := range systems { + ids[i] = x.ID + data[i] = IDSatelliteManaged{x.ID, x.SatelliteManaged} + } + resp.IDs = ids + resp.Data = data + return resp, nil +} + type SystemDBLookupSlice []SystemDBLookup type AdvisorySystemDBLookupSlice []AdvisorySystemDBLookup type BaselineSystemsDBLookupSlice []BaselineSystemsDBLookup