@@ -96,12 +96,13 @@ type NestedFilterMap map[string]string
9696
9797var nestedFilters = NestedFilterMap {
9898 "group_name" : "group_name" ,
99- "system_profile][sap_system" : "system_profile][sap_system" ,
100- "system_profile][sap_sids" : "system_profile][sap_sids" ,
101- "system_profile][ansible" : "system_profile][ansible" ,
102- "system_profile][ansible][controller_version" : "system_profile][ansible][controller_version" ,
103- "system_profile][mssql" : "system_profile][mssql" ,
104- "system_profile][mssql][version" : "system_profile][mssql][version" ,
99+ "system_profile][sap_system" : "(ih.system_profile->'workloads'->'sap'->>'sap_system')" ,
100+ "system_profile][sap_sids" : "(ih.system_profile->'workloads'->'sap'->>'sids')" ,
101+ "system_profile][sap_sids][in]" : "(ih.system_profile->'workloads'->'sap'->>'sids')" ,
102+ "system_profile][ansible" : "(ih.system_profile->'workloads'->>'ansible')" ,
103+ "system_profile][ansible][controller_version" : "(ih.system_profile->'workloads'->'ansible'->>'controller_version')" ,
104+ "system_profile][mssql" : "(ih.system_profile->'workloads'->>'mssql')" ,
105+ "system_profile][mssql][version" : "(ih.system_profile->'workloads'->'mssql'->>'version')" ,
105106}
106107
107108func ParseFilters (c * gin.Context , filters Filters , allowedFields database.AttrMap ,
@@ -112,8 +113,7 @@ func ParseFilters(c *gin.Context, filters Filters, allowedFields database.AttrMa
112113 subject := name [7 : len (name )- 1 ] // strip key from "filter[...]"
113114 for _ , v := range values {
114115 if _ , ok := nestedFilters [subject ]; ok {
115- nested := nestedFilters [subject ]
116- filters .Update (InventoryFilter , nested , v )
116+ filters .Update (InventoryFilter , subject , v )
117117 continue
118118 }
119119 if _ , ok := allowedFields [subject ]; ! ok {
@@ -413,10 +413,10 @@ func ApplyInventoryWhere(filters map[string]FilterData, tx *gorm.DB) (*gorm.DB,
413413 return tx , applied
414414}
415415
416- // Builds inventory sub query in generic way.
416+ // Builds inventory sub query
417417// Example:
418- // buildSystemProfileQuery("mssql-> version", "1.0")
419- // returns "(ih.system_profile -> ' mssql' ->> 'version')::text = 1.0"
418+ // buildSystemProfileQuery("system_profile][ mssql][ version", "1.0")
419+ // returns "(ih.system_profile->'workloads'->' mssql'->>'version') = 1.0"
420420func buildInventoryQuery (tx * gorm.DB , key string , values []string ) * gorm.DB {
421421 if strings .Contains (key , "group_name" ) {
422422 groups := []string {}
@@ -444,20 +444,10 @@ func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB {
444444 bval , _ := sonic .Marshal (values )
445445 val = string (bval )
446446 default :
447- cmp = "::text = ?"
447+ cmp = " = ?"
448448 }
449449
450- sbkeys := strings .Split (key , "][" )
451- subq := fmt .Sprintf ("(ih.%s" , sbkeys [0 ])
452- nSbkeys := len (sbkeys )
453- if nSbkeys > 2 {
454- subq = fmt .Sprintf ("%s -> '%s'" , subq , strings .Join (sbkeys [1 :nSbkeys - 1 ], "' -> '" ))
455- }
456- if nSbkeys > 1 {
457- subq = fmt .Sprintf ("%s ->> '%s')" , subq , sbkeys [nSbkeys - 1 ])
458- }
459-
460- subq = fmt .Sprintf ("%s%s" , subq , cmp )
450+ subq := fmt .Sprintf ("%s%s" , nestedFilters [key ], cmp )
461451 if val == "not_nil" {
462452 return tx .Where (subq )
463453 }
0 commit comments