Skip to content

Commit

Permalink
RHINENG-2547: add satellite_managed info to /ids/systems
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Oct 12, 2023
1 parent 3e16d7f commit a627836
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
30 changes: 29 additions & 1 deletion docs/v3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3771,7 +3771,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/controllers.IDsResponse"
"$ref": "#/components/schemas/controllers.IDsSatelliteManagedResponse"
}
}
}
Expand Down Expand Up @@ -6280,6 +6280,17 @@
}
}
},
"controllers.IDSatelliteManaged": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"satellite_managed": {
"type": "boolean"
}
}
},
"controllers.IDStatus": {
"type": "object",
"properties": {
Expand All @@ -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": {
Expand Down
12 changes: 12 additions & 0 deletions manager/controllers/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,25 @@ 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
// TODO: delete later once UI is using only the new `data` field
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"`
Expand Down
13 changes: 9 additions & 4 deletions manager/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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)
}

Expand Down
26 changes: 26 additions & 0 deletions manager/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a627836

Please sign in to comment.