MCPcopy Create free account
hub / github.com/bytebase/bytebase / maskElasticsearchHitSort

Function maskElasticsearchHitSort

backend/api/v1/document_masking.go:1066–1099  ·  view source on GitHub ↗

maskElasticsearchHitSort masks the "sort" array of a hit based on the sort fields from the request. sortFields is the ordered list of field names used in the sort clause (from request analysis).

(hitMap map[string]any, sortFields []string, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker)

Source from the content-addressed store, hash-verified

1064// maskElasticsearchHitSort masks the "sort" array of a hit based on the sort fields from the request.
1065// sortFields is the ordered list of field names used in the sort clause (from request analysis).
1066func maskElasticsearchHitSort(hitMap map[string]any, sortFields []string, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker) error {
1067 sortVal, ok := hitMap["sort"]
1068 if !ok {
1069 return nil
1070 }
1071 sortArr, ok := sortVal.([]any)
1072 if !ok {
1073 return nil
1074 }
1075 for i, val := range sortArr {
1076 if i >= len(sortFields) {
1077 break
1078 }
1079 fieldName := sortFields[i]
1080 if fieldName == "" {
1081 continue
1082 }
1083 semanticType := lookupSemanticTypeByDotPath(fieldName, objectSchema)
1084 if semanticType == "" {
1085 continue
1086 }
1087 m, ok := semanticTypeToMasker[semanticType]
1088 if !ok {
1089 continue
1090 }
1091 masked, err := applyMaskerToData(val, m)
1092 if err != nil {
1093 return err
1094 }
1095 sortArr[i] = masked
1096 }
1097 hitMap["sort"] = sortArr
1098 return nil
1099}
1100
1101// maskElasticsearchSingleHit masks _source, fields, highlight, sort, and inner_hits for a single hit.
1102func maskElasticsearchSingleHit(hitMap map[string]any, sortFields []string, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker) error {

Callers 1

Calls 2

applyMaskerToDataFunction · 0.85

Tested by

no test coverage detected