MCPcopy Index your code
hub / github.com/coder/coder / Write

Method Write

cli/sessionstore/sessionstore.go:148–180  ·  view source on GitHub ↗
(serverURL *url.URL, token string)

Source from the content-addressed store, hash-verified

146}
147
148func (o Keyring) Write(serverURL *url.URL, token string) error {
149 host, err := normalizeHost(serverURL)
150 if err != nil {
151 return err
152 }
153
154 existingJSON, err := o.provider.Get(o.serviceName)
155 if err != nil && !errors.Is(err, os.ErrNotExist) {
156 return xerrors.Errorf("read existing credentials: %w", err)
157 }
158
159 creds, err := parseCredentialsJSON(existingJSON)
160 if err != nil {
161 return xerrors.Errorf("write: parse existing credentials: %w", err)
162 }
163
164 // Upsert the credential for this URL.
165 creds[host] = credential{
166 CoderURL: host,
167 APIToken: token,
168 }
169
170 credsJSON, err := json.Marshal(creds)
171 if err != nil {
172 return xerrors.Errorf("marshal credentials: %w", err)
173 }
174
175 err = o.provider.Set(o.serviceName, string(credsJSON))
176 if err != nil {
177 return xerrors.Errorf("write credentials to keyring: %w", err)
178 }
179 return nil
180}
181
182func (o Keyring) Delete(serverURL *url.URL) error {
183 host, err := normalizeHost(serverURL)

Callers

nothing calls this directly

Calls 7

parseCredentialsJSONFunction · 0.85
normalizeHostFunction · 0.70
GetMethod · 0.65
SetMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected