Skip to content

Commit 038ee0b

Browse files
committed
fixed ANY and prefix
1 parent 4c2a95f commit 038ee0b

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

data/service/search.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,29 +1158,52 @@ func uniqueHepTable(hepSlice []model.HepTable) []model.HepTable {
11581158
}
11591159
}
11601160

1161-
// this method create new user in the database
1162-
// it doesn't check internally whether all the validation are applied or not
11631161
func (ss *SearchService) GetTransactionData(table string, fieldKey string, dataWhere []interface{}, timeFrom,
11641162
timeTo time.Time, nodes []string, userGroup string, likeSearch bool, whitelist []string) ([]model.HepTable, error) {
11651163

11661164
searchData := []model.HepTable{}
1167-
query := "create_date between ? AND ? "
11681165

1169-
query += fmt.Sprintf("AND %s %s ANY(ARRAY[?])", fieldKey, heputils.GetSQLEqualityOperator(likeSearch))
1166+
// Start with base query conditions
1167+
baseQuery := "create_date between ? AND ?"
1168+
params := []interface{}{
1169+
timeFrom.Format(time.RFC3339),
1170+
timeTo.Format(time.RFC3339),
1171+
}
1172+
1173+
// Handle the ANY condition differently - we'll construct it based on length of dataWhere
1174+
anyPlaceholders := make([]string, len(dataWhere))
1175+
for i := range anyPlaceholders {
1176+
anyPlaceholders[i] = "?"
1177+
}
1178+
1179+
anyQueryPart := fmt.Sprintf("AND %s %s ANY(ARRAY[%s])",
1180+
fieldKey,
1181+
heputils.GetSQLEqualityOperator(likeSearch),
1182+
strings.Join(anyPlaceholders, ","))
1183+
1184+
query := baseQuery + " " + anyQueryPart
1185+
params = append(params, dataWhere...)
11701186

1187+
logger.Debug("GetTransactionData: ", table, fieldKey, dataWhere, timeFrom, timeTo, nodes, userGroup, likeSearch, whitelist)
11711188
logger.Debug("ISOLATEGROUP ", config.Setting.MAIN_SETTINGS.IsolateGroup)
11721189
logger.Debug("USERGROUP ", userGroup)
11731190

1191+
// Add isolation group condition if needed
11741192
if config.Setting.MAIN_SETTINGS.IsolateGroup != "" && config.Setting.MAIN_SETTINGS.IsolateGroup == userGroup {
11751193
query = query + " AND " + config.Setting.MAIN_SETTINGS.IsolateQuery
11761194
}
11771195

1178-
var whitelistParams []interface{}
1196+
// Add whitelist conditions
11791197
for _, ip := range whitelist {
1180-
query = query + " AND (protocol_header->>'srcIp' != ? AND protocol_header->>'dstIp' != ? ) "
1181-
whitelistParams = append(whitelistParams, ip, ip)
1198+
query = query + " AND (protocol_header->>'srcIp' != ? AND protocol_header->>'dstIp' != ?) "
1199+
params = append(params, ip, ip)
11821200
}
11831201

1202+
// Debug the final query and parameters
1203+
logger.Debug("Final query: ", query)
1204+
logger.Debug("Params count: ", len(params))
1205+
logger.Debug("Params: ", params)
1206+
11841207
for session := range ss.Session {
11851208
/* if node doesnt exists - continue */
11861209
if !heputils.ElementExists(nodes, session) {
@@ -1190,15 +1213,15 @@ func (ss *SearchService) GetTransactionData(table string, fieldKey string, dataW
11901213
searchTmp := []model.HepTable{}
11911214
if err := ss.Session[session].Debug().
11921215
Table(table).
1193-
Where(query, append([]interface{}{timeFrom.Format(time.RFC3339), timeTo.Format(time.RFC3339)}, append(dataWhere, whitelistParams...)...)...).
1216+
Where(query, params...).
11941217
Find(&searchTmp).Error; err != nil {
11951218
logger.Error("GetTransactionData: We have got error: ", err)
1219+
return nil, err
11961220
}
11971221

11981222
logger.Debug("GetTransactionData: Len: ", len(searchTmp))
11991223

12001224
if len(searchTmp) > 0 {
1201-
12021225
profileName := strings.TrimPrefix(table, "hep_proto_")
12031226

12041227
for val := range searchTmp {
@@ -1210,7 +1233,6 @@ func (ss *SearchService) GetTransactionData(table string, fieldKey string, dataW
12101233
}
12111234
}
12121235

1213-
//response, _ := json.Marshal(searchData)
12141236
return searchData, nil
12151237
}
12161238

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ func configureAsHTTPServer() {
810810
if strings.HasSuffix(c.Request().RequestURI, ".js") {
811811

812812
//Prefix
813-
if *appFlags.APIPrefix != "" && strings.HasPrefix(c.Request().RequestURI, *appFlags.APIPrefix) {
814-
c.Request().RequestURI = strings.TrimPrefix(c.Request().RequestURI, *appFlags.APIPrefix)
813+
if config.Setting.MAIN_SETTINGS.APIPrefix != "" && strings.HasPrefix(c.Request().RequestURI, config.Setting.MAIN_SETTINGS.APIPrefix) {
814+
c.Request().RequestURI = strings.TrimPrefix(c.Request().RequestURI, config.Setting.MAIN_SETTINGS.APIPrefix)
815815
}
816816

817817
if heputils.FileExists(config.Setting.MAIN_SETTINGS.RootPath + c.Request().RequestURI + ".gz") {
@@ -1734,7 +1734,7 @@ func applyDBConfigParamToConfig(user *string, password *string, dbname *string,
17341734

17351735
func registerGetRedirect(e *echo.Echo, path string) {
17361736

1737-
prefix := *appFlags.APIPrefix
1737+
prefix := config.Setting.MAIN_SETTINGS.APIPrefix
17381738

17391739
if viper.IsSet("http_settings.api_prefix") {
17401740
prefix = viper.GetString("http_settings.api_prefix")

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
// VERSION
4-
var VERSION_APPLICATION = "1.5.7"
4+
var VERSION_APPLICATION = "1.5.8"
55

66
// NAME
77
var NAME_APPLICATION = "homer-app"

0 commit comments

Comments
 (0)