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

Method saveAuthFile

internal/pluginhost/auth_callbacks.go:281–303  ·  view source on GitHub ↗
(ctx context.Context, name string, data []byte)

Source from the content-addressed store, hash-verified

279}
280
281func (h *Host) saveAuthFile(ctx context.Context, name string, data []byte) (string, error) {
282 authDir := h.resolvedAuthDir()
283 if authDir == "" {
284 return "", fmt.Errorf("auth directory is unavailable")
285 }
286 dst := filepath.Join(authDir, filepath.Base(name))
287 if !filepath.IsAbs(dst) {
288 if abs, errAbs := filepath.Abs(dst); errAbs == nil {
289 dst = abs
290 }
291 }
292 auth, errBuild := h.buildAuthFromFileData(dst, data)
293 if errBuild != nil {
294 return "", errBuild
295 }
296 if errWrite := os.WriteFile(dst, data, 0o600); errWrite != nil {
297 return "", fmt.Errorf("failed to write auth file: %w", errWrite)
298 }
299 if errUpsert := h.upsertAuthRecord(ctx, auth); errUpsert != nil {
300 return "", errUpsert
301 }
302 return dst, nil
303}
304
305func (h *Host) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) {
306 if strings.TrimSpace(path) == "" {

Callers 1

callHostAuthSaveMethod · 0.95

Calls 3

resolvedAuthDirMethod · 0.95
buildAuthFromFileDataMethod · 0.95
upsertAuthRecordMethod · 0.95

Tested by

no test coverage detected