返回 DeepSeek-Reasonix
credentials_keyring_default.go
根目录 / internal / config / credentials_keyring_default.go
1 //go:build !linux && !netbsd && !openbsd && !(dragonfly && cgo) && !(freebsd && cgo)
2
3 package config
4
5 import (
6 "context"
7 "errors"
8 "strings"
9
10 "github.com/zalando/go-keyring"
11 )
12
13 // legacyKeyringProbe reads one legacy credential from the platform keyring.
14 // keyring.ErrNotFound (and empty values) are absent; other errors stay error.
15 // ctx is checked before the call so a shared batch budget can stop the scan;
16 // platform Get is not context-aware on these OSes.
17 func legacyKeyringProbe(ctx context.Context, key string) legacyKeyringOutcome {
18 key = strings.TrimSpace(key)
19 if key == "" {
20 return legacyKeyringOutcome{Status: legacyKeyringAbsent}
21 }
22 if err := ctx.Err(); err != nil {
23 return legacyKeyringOutcome{Status: legacyKeyringTimeout}
24 }
25 value, err := keyring.Get(credentialsKeyringService, key)
26 if err != nil {
27 if errors.Is(err, keyring.ErrNotFound) {
28 return legacyKeyringOutcome{Status: legacyKeyringAbsent}
29 }
30 if ctx.Err() != nil {
31 return legacyKeyringOutcome{Status: legacyKeyringTimeout}
32 }
33 return legacyKeyringOutcome{Status: legacyKeyringError}
34 }
35 if strings.TrimSpace(value) == "" {
36 return legacyKeyringOutcome{Status: legacyKeyringAbsent}
37 }
38 return legacyKeyringOutcome{Status: legacyKeyringFound, Value: value}
39 }
40
40 lines GO