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

Function maskDocumentString

backend/api/v1/document_masking.go:256–276  ·  view source on GitHub ↗

--------------------------------------------------------------------------- Shared JSON masking utilities --------------------------------------------------------------------------- maskDocumentString unmarshals a JSON string, masks it recursively using the ObjectSchema and semantic type maskers, an

(document string, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker)

Source from the content-addressed store, hash-verified

254// maskDocumentString unmarshals a JSON string, masks it recursively using
255// the ObjectSchema and semantic type maskers, and marshals it back.
256func maskDocumentString(document string, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker) (string, error) {
257 if document == "" || objectSchema == nil {
258 return document, nil
259 }
260
261 var parsed any
262 if err := json.Unmarshal([]byte(document), &parsed); err != nil {
263 return "", errors.Wrap(err, "failed to unmarshal document")
264 }
265
266 masked, err := walkAndMaskJSONRecursive(parsed, objectSchema, semanticTypeToMasker)
267 if err != nil {
268 return "", errors.Wrap(err, "failed to mask document")
269 }
270
271 out, err := json.Marshal(masked)
272 if err != nil {
273 return "", errors.Wrap(err, "failed to marshal masked document")
274 }
275 return string(out), nil
276}
277
278func walkAndMaskJSON(data map[string]any, fieldPaths map[string][]*parserbase.PathAST, objectSchema *storepb.ObjectSchema, semanticTypeToMasker map[string]masker.Masker) (map[string]any, error) {
279 result := make(map[string]any)

Callers 4

maskResultsMethod · 0.85
maskResultsMethod · 0.85

Calls 2

walkAndMaskJSONRecursiveFunction · 0.85
UnmarshalMethod · 0.80

Tested by 2