diff --git a/docs/v3/openapi.json b/docs/v3/openapi.json index 8841ab903..c07da02d5 100644 --- a/docs/v3/openapi.json +++ b/docs/v3/openapi.json @@ -2346,6 +2346,30 @@ "type": "string" } }, + { + "name": "filter[osname]", + "in": "query", + "description": "Filter OS name", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osmajor]", + "in": "query", + "description": "Filter OS major version", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osminor]", + "in": "query", + "description": "Filter OS minor version", + "schema": { + "type": "string" + } + }, { "name": "tags", "in": "query", @@ -4089,6 +4113,30 @@ "type": "string" } }, + { + "name": "filter[osname]", + "in": "query", + "description": "Filter OS name", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osmajor]", + "in": "query", + "description": "Filter OS major version", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osminor]", + "in": "query", + "description": "Filter OS minor version", + "schema": { + "type": "string" + } + }, { "name": "filter[satellite_managed]", "in": "query", @@ -5337,6 +5385,30 @@ "type": "string" } }, + { + "name": "filter[osname]", + "in": "query", + "description": "Filter OS name", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osmajor]", + "in": "query", + "description": "Filter OS major version", + "schema": { + "type": "string" + } + }, + { + "name": "filter[osminor]", + "in": "query", + "description": "Filter OS minor version", + "schema": { + "type": "string" + } + }, { "name": "tags", "in": "query", diff --git a/manager/controllers/systems.go b/manager/controllers/systems.go index 4f9ea20f7..112a4ee44 100644 --- a/manager/controllers/systems.go +++ b/manager/controllers/systems.go @@ -236,6 +236,9 @@ func systemsCommon(c *gin.Context) (*gorm.DB, *ListMeta, []string, error) { // @Param filter[satellite_managed] query string false "Filter" // @Param filter[built_pkgcache] query string false "Filter" // @Param filter[os] query string false "Filter OS version" +// @Param filter[osname] query string false "Filter OS name" +// @Param filter[osmajor] query string false "Filter OS major version" +// @Param filter[osminor] query string false "Filter OS minor version" // @Param tags query []string false "Tag filter" // @Param filter[group_name] query []string false "Filter systems by inventory groups" // @Param filter[system_profile][sap_system] query string false "Filter only SAP systems" @@ -311,6 +314,9 @@ func SystemsListHandler(c *gin.Context) { // @Param filter[created] query string false "Filter" // @Param filter[baseline_name] query string false "Filter" // @Param filter[os] query string false "Filter OS version" +// @Param filter[osname] query string false "Filter OS name" +// @Param filter[osmajor] query string false "Filter OS major version" +// @Param filter[osminor] query string false "Filter OS minor version" // @Param filter[satellite_managed] query string false "Filter" // @Param filter[built_pkgcache] query string false "Filter" // @Param tags query []string false "Tag filter" diff --git a/manager/controllers/systems_export.go b/manager/controllers/systems_export.go index 9b6f1e8c2..8d030676a 100644 --- a/manager/controllers/systems_export.go +++ b/manager/controllers/systems_export.go @@ -43,6 +43,9 @@ import ( // @Param filter[system_profile][mssql][version] query string false "Filter systems by mssql version" // @Param filter[baseline_name] query string false "Filter" // @Param filter[os] query string false "Filter OS version" +// @Param filter[osname] query string false "Filter OS name" +// @Param filter[osmajor] query string false "Filter OS major version" +// @Param filter[osminor] query string false "Filter OS minor version" // @Param tags query []string false "Tag filter" // @Success 200 {array} SystemDBLookup // @Failure 415 {object} utils.ErrorResponse diff --git a/manager/controllers/systems_export_test.go b/manager/controllers/systems_export_test.go index 068ad35ab..2498d06d2 100644 --- a/manager/controllers/systems_export_test.go +++ b/manager/controllers/systems_export_test.go @@ -124,3 +124,15 @@ func TestSystemsExportBaselineFilter(t *testing.T) { assert.Equal(t, "00000000-0000-0000-0000-000000000001", output[0].ID) assert.Equal(t, "00000000-0000-0000-0000-000000000002", output[1].ID) } + +func TestSystemsExportFilterPartialOS(t *testing.T) { + w := makeRequest(t, "/?filter[osname]=RHEL&filter[osmajor]=8&filter[osminor]=1", "application/json") + + var output []SystemDBLookup + CheckResponse(t, w, http.StatusOK, &output) + + assert.Equal(t, 3, len(output)) + for _, o := range output { + assert.Equal(t, "RHEL 8.1", o.OS) + } +} diff --git a/manager/controllers/systems_test.go b/manager/controllers/systems_test.go index 48863af31..0fb0d121a 100644 --- a/manager/controllers/systems_test.go +++ b/manager/controllers/systems_test.go @@ -214,6 +214,14 @@ func TestSystemsFilterOS(t *testing.T) { assert.Equal(t, "RHEL 8.1", output.Data[2].Attributes.OS) } +func TestSystemsFilterPartialOS(t *testing.T) { + output := testSystems(t, "?filter[osname]=RHEL&filter[osmajor]=8&filter[osminor]=1", 1) + assert.Equal(t, 3, len(output.Data)) + for _, d := range output.Data { + assert.Equal(t, "RHEL 8.1", d.Attributes.OS) + } +} + func TestSystemsOrderOS(t *testing.T) { output := testSystems(t, `?sort=os`, 1) assert.Equal(t, "RHEL 7.3", output.Data[0].Attributes.OS)