From 5b25f5df99ef766e179c964ad7cd0bd56684630c Mon Sep 17 00:00:00 2001 From: 0xmuralik Date: Fri, 17 Mar 2023 11:11:28 +0530 Subject: [PATCH 1/3] refactor getReferences --- gql/util.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gql/util.go b/gql/util.go index 935b293f..66b4607b 100644 --- a/gql/util.go +++ b/gql/util.go @@ -164,24 +164,24 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au } func getReferences(ctx context.Context, resolver QueryResolver, r *registrytypes.RecordType) ([]*Record, error) { - var ids []string + ids := getIds(r.Attributes) + return resolver.GetRecordsByIds(ctx, ids) +} - // #nosec G705 - for key := range r.Attributes { - //nolint: all - switch r.Attributes[key].(type) { - case interface{}: - if obj, ok := r.Attributes[key].(map[string]interface{}); ok { - if _, ok := obj["/"]; ok && len(obj) == 1 { - if _, ok := obj["/"].(string); ok { - ids = append(ids, obj["/"].(string)) - } +func getIds(obj map[string]interface{}) []string { + var ids []string + for _, val := range obj { + if innerObj, ok := val.(map[string]interface{}); ok { + if _, ok := innerObj["/"]; ok && len(innerObj) == 1 { + if _, ok := innerObj["/"].(string); ok { + ids = append(ids, innerObj["/"].(string)) } + } else { + ids = append(ids, getIds(innerObj)...) } } } - - return resolver.GetRecordsByIds(ctx, ids) + return ids } func getAttributes(r *registrytypes.RecordType) ([]*KeyValue, error) { -- 2.45.2 From 3ffff8d9928e44350fc6b996cdfda36378f4a7cd Mon Sep 17 00:00:00 2001 From: 0xmuralik Date: Fri, 17 Mar 2023 11:25:07 +0530 Subject: [PATCH 2/3] fix lint --- .semgrepignore | 3 +++ gql/util.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.semgrepignore b/.semgrepignore index cb655af1..b65ff62f 100644 --- a/.semgrepignore +++ b/.semgrepignore @@ -19,6 +19,9 @@ test/ tests/ *_test.go +# false positive +testutil/network/network.go + # Semgrep rules folder .semgrep diff --git a/gql/util.go b/gql/util.go index 66b4607b..1bc5748f 100644 --- a/gql/util.go +++ b/gql/util.go @@ -170,8 +170,8 @@ func getReferences(ctx context.Context, resolver QueryResolver, r *registrytypes func getIds(obj map[string]interface{}) []string { var ids []string - for _, val := range obj { - if innerObj, ok := val.(map[string]interface{}); ok { + for key := range obj { + if innerObj, ok := obj[key].(map[string]interface{}); ok { if _, ok := innerObj["/"]; ok && len(innerObj) == 1 { if _, ok := innerObj["/"].(string); ok { ids = append(ids, innerObj["/"].(string)) -- 2.45.2 From fa938e76bb25b2e9a0df0c2c1eeac5bd8d815cd6 Mon Sep 17 00:00:00 2001 From: 0xmuralik Date: Fri, 17 Mar 2023 11:37:13 +0530 Subject: [PATCH 3/3] nosec g705 --- gql/util.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gql/util.go b/gql/util.go index 1bc5748f..5eeba91b 100644 --- a/gql/util.go +++ b/gql/util.go @@ -170,6 +170,8 @@ func getReferences(ctx context.Context, resolver QueryResolver, r *registrytypes func getIds(obj map[string]interface{}) []string { var ids []string + + // #nosec G705 for key := range obj { if innerObj, ok := obj[key].(map[string]interface{}); ok { if _, ok := innerObj["/"]; ok && len(innerObj) == 1 { -- 2.45.2