MCPcopy Create free account
hub / github.com/Scalingo/cli / existingAuth

Function existingAuth

config/auth.go:295–312  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

293}
294
295func existingAuth(ctx context.Context) (*auth.ConfigData, error) {
296 authConfig := auth.NewConfigData()
297 content, err := os.ReadFile(C.AuthFile)
298 if err == nil {
299 // We don't care of the error
300 json.Unmarshal(content, &authConfig)
301 } else if os.IsNotExist(err) {
302 config := make(auth.ConfigPerHostV2)
303 buffer, err := json.Marshal(&config)
304 if err != nil {
305 return nil, errors.Wrapf(ctx, err, "encode non-existing authentication file")
306 }
307 authConfig.AuthConfigPerHost = json.RawMessage(buffer)
308 } else {
309 return nil, errors.Wrapf(ctx, err, "read existing authentication file")
310 }
311 return authConfig, nil
312}

Callers 3

StoreAuthMethod · 0.85
RemoveAuthMethod · 0.85
TestExistingAuthFunction · 0.85

Calls 1

NewConfigDataFunction · 0.92

Tested by 1

TestExistingAuthFunction · 0.68