(data pluginapi.AuthData, path, fileName string, authDir string)
| 535 | } |
| 536 | |
| 537 | func pluginAuthDataToCoreAuth(data pluginapi.AuthData, path, fileName string, authDir string) *coreauth.Auth { |
| 538 | provider := normalizeProviderID(data.Provider) |
| 539 | if provider == "" { |
| 540 | return nil |
| 541 | } |
| 542 | metadata := cloneAnyMap(data.Metadata) |
| 543 | if metadata == nil { |
| 544 | metadata = make(map[string]any) |
| 545 | } |
| 546 | if provider != "" { |
| 547 | metadata["type"] = provider |
| 548 | } |
| 549 | attributes := cloneStringMap(data.Attributes) |
| 550 | if attributes == nil { |
| 551 | attributes = make(map[string]string) |
| 552 | } |
| 553 | path = strings.TrimSpace(path) |
| 554 | if path != "" { |
| 555 | attributes[coreauth.AttributePath] = path |
| 556 | attributes[coreauth.AttributeSource] = path |
| 557 | attributes[coreauth.AttributeSourceBackend] = coreauth.AuthSourceFile |
| 558 | } |
| 559 | fileName = strings.TrimSpace(firstNonEmpty(data.FileName, fileName)) |
| 560 | if fileName != "" && attributes[coreauth.AttributeSource] == "" { |
| 561 | attributes[coreauth.AttributeSource] = fileName |
| 562 | } |
| 563 | id := strings.TrimSpace(data.ID) |
| 564 | if id == "" { |
| 565 | id = authIDForPath(firstNonEmpty(path, fileName), authDir) |
| 566 | } |
| 567 | status := coreauth.StatusActive |
| 568 | if data.Disabled { |
| 569 | status = coreauth.StatusDisabled |
| 570 | } |
| 571 | now := time.Now().UTC() |
| 572 | auth := &coreauth.Auth{ |
| 573 | Provider: provider, |
| 574 | ID: id, |
| 575 | FileName: fileName, |
| 576 | Label: strings.TrimSpace(data.Label), |
| 577 | Prefix: strings.TrimSpace(data.Prefix), |
| 578 | ProxyURL: strings.TrimSpace(data.ProxyURL), |
| 579 | Disabled: data.Disabled, |
| 580 | Status: status, |
| 581 | Storage: &pluginTokenStorage{provider: provider, rawJSON: bytes.Clone(data.StorageJSON), meta: metadata}, |
| 582 | Metadata: metadata, |
| 583 | Attributes: attributes, |
| 584 | CreatedAt: now, |
| 585 | UpdatedAt: now, |
| 586 | NextRefreshAfter: data.NextRefreshAfter, |
| 587 | } |
| 588 | return auth |
| 589 | } |
| 590 | |
| 591 | func firstNonEmpty(values ...string) string { |
| 592 | for _, value := range values { |
no test coverage detected