MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / NormalizeServiceAccountMap

Function NormalizeServiceAccountMap

internal/auth/vertex/keyutil.go:37–55  ·  view source on GitHub ↗

NormalizeServiceAccountMap returns a copy of the given service account map with a sanitized private_key field that is guaranteed to contain a valid RSA PRIVATE KEY PEM block.

(sa map[string]any)

Source from the content-addressed store, hash-verified

35// NormalizeServiceAccountMap returns a copy of the given service account map with
36// a sanitized private_key field that is guaranteed to contain a valid RSA PRIVATE KEY PEM block.
37func NormalizeServiceAccountMap(sa map[string]any) (map[string]any, error) {
38 if sa == nil {
39 return nil, fmt.Errorf("service account payload is empty")
40 }
41 pk, _ := sa["private_key"].(string)
42 if strings.TrimSpace(pk) == "" {
43 return nil, fmt.Errorf("service account missing private_key")
44 }
45 normalized, err := sanitizePrivateKey(pk)
46 if err != nil {
47 return nil, err
48 }
49 clone := make(map[string]any, len(sa))
50 for k, v := range sa {
51 clone[k] = v
52 }
53 clone["private_key"] = normalized
54 return clone, nil
55}
56
57func sanitizePrivateKey(raw string) (string, error) {
58 pk := strings.ReplaceAll(raw, "\r\n", "\n")

Callers 3

DoVertexImportFunction · 0.92

Calls 1

sanitizePrivateKeyFunction · 0.85

Tested by

no test coverage detected