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

Function mergedStorageJSON

internal/pluginhost/auth_provider.go:478–503  ·  view source on GitHub ↗
(raw []byte, metadata map[string]any, provider string)

Source from the content-addressed store, hash-verified

476}
477
478func mergedStorageJSON(raw []byte, metadata map[string]any, provider string) ([]byte, error) {
479 out := make(map[string]any)
480 if len(bytes.TrimSpace(raw)) > 0 {
481 if errUnmarshal := json.Unmarshal(raw, &out); errUnmarshal != nil {
482 return nil, fmt.Errorf("decode plugin token storage: %w", errUnmarshal)
483 }
484 if out == nil {
485 out = make(map[string]any)
486 }
487 }
488 for key, value := range metadata {
489 out[key] = value
490 }
491 provider = normalizeProviderID(provider)
492 if provider != "" {
493 out["type"] = provider
494 }
495 if len(out) == 0 {
496 return nil, fmt.Errorf("plugin token storage payload is empty")
497 }
498 payload, errMarshal := json.Marshal(out)
499 if errMarshal != nil {
500 return nil, fmt.Errorf("encode plugin token storage: %w", errMarshal)
501 }
502 return payload, nil
503}
504
505func atomicWriteFile(path string, data []byte) error {
506 path = strings.TrimSpace(path)

Callers 2

RawJSONMethod · 0.85
SaveTokenToFileMethod · 0.85

Calls 1

normalizeProviderIDFunction · 0.85

Tested by

no test coverage detected