MCPcopy Index your code
hub / github.com/git-bug/git-bug / LoadWithPrefix

Function LoadWithPrefix

bridge/core/auth/credential.go:76–116  ·  view source on GitHub ↗

LoadWithPrefix load a credential from the repo config with a prefix

(repo repository.RepoKeyring, prefix string)

Source from the content-addressed store, hash-verified

74
75// LoadWithPrefix load a credential from the repo config with a prefix
76func LoadWithPrefix(repo repository.RepoKeyring, prefix string) (Credential, error) {
77 keys, err := repo.Keyring().Keys()
78 if err != nil {
79 return nil, err
80 }
81
82 // preallocate but empty
83 matching := make([]Credential, 0, 5)
84
85 for _, key := range keys {
86 if !strings.HasPrefix(key, keyringKeyPrefix+prefix) {
87 continue
88 }
89
90 item, err := repo.Keyring().Get(key)
91 if err != nil {
92 return nil, err
93 }
94
95 cred, err := decode(item)
96 if err != nil {
97 return nil, err
98 }
99
100 matching = append(matching, cred)
101 }
102
103 if len(matching) > 1 {
104 ids := make([]entity.Id, len(matching))
105 for i, cred := range matching {
106 ids[i] = cred.ID()
107 }
108 return nil, NewErrMultipleMatchCredential(ids)
109 }
110
111 if len(matching) == 0 {
112 return nil, ErrCredentialNotExist
113 }
114
115 return matching[0], nil
116}
117
118// decode is a helper to construct a Credential from the keyring Item
119func decode(item repository.Item) (Credential, error) {

Callers 8

ConfigureMethod · 0.92
ConfigureMethod · 0.92
ConfigureMethod · 0.92
runBridgeAuthRmFunction · 0.92
runBridgeNewFunction · 0.92
runBridgeAuthShowFunction · 0.92
PrefixExistFunction · 0.85
TestCredentialFunction · 0.85

Calls 7

decodeFunction · 0.85
GetMethod · 0.80
KeysMethod · 0.65
KeyringMethod · 0.65
IDMethod · 0.65
HasPrefixMethod · 0.45

Tested by 1

TestCredentialFunction · 0.68