(cs *iostreams.ColorScheme)
| 85 | } |
| 86 | |
| 87 | func (e authEntry) String(cs *iostreams.ColorScheme) string { |
| 88 | var sb strings.Builder |
| 89 | |
| 90 | switch e.State { |
| 91 | case authEntryStateSuccess: |
| 92 | sb.WriteString( |
| 93 | fmt.Sprintf(" %s Logged in to %s account %s (%s)\n", cs.SuccessIcon(), e.Host, cs.Bold(e.Login), e.TokenSource), |
| 94 | ) |
| 95 | activeStr := fmt.Sprintf("%v", e.Active) |
| 96 | sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr))) |
| 97 | sb.WriteString(fmt.Sprintf(" - Git operations protocol: %s\n", cs.Bold(e.GitProtocol))) |
| 98 | sb.WriteString(fmt.Sprintf(" - Token: %s\n", cs.Bold(e.Token))) |
| 99 | |
| 100 | if e.Refreshable { |
| 101 | e.writeExpiry(&sb, cs) |
| 102 | if e.justRefreshed { |
| 103 | sb.WriteString(" - Token refreshed just now\n") |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | if expectScopes(e.Token) { |
| 108 | sb.WriteString(fmt.Sprintf(" - Token scopes: %s\n", cs.Bold(displayScopes(e.Scopes)))) |
| 109 | if err := shared.HeaderHasMinimumScopes(e.Scopes); err != nil { |
| 110 | if missingScopesError, ok := errors.AsType[*shared.MissingScopesError](err); ok { |
| 111 | missingScopes := strings.Join(missingScopesError.MissingScopes, ",") |
| 112 | sb.WriteString(fmt.Sprintf(" %s Missing required token scopes: %s\n", |
| 113 | cs.WarningIcon(), |
| 114 | cs.Bold(displayScopes(missingScopes)))) |
| 115 | refreshInstructions := fmt.Sprintf("gh auth refresh -h %s", e.Host) |
| 116 | sb.WriteString(fmt.Sprintf(" - To request missing scopes, run: %s\n", cs.Bold(refreshInstructions))) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | case authEntryStateError: |
| 122 | if e.expiredWithoutRefresh { |
| 123 | sb.WriteString(fmt.Sprintf(" %s Token for %s account %s (%s) has expired\n", cs.Red("X"), e.Host, cs.Bold(e.Login), e.TokenSource)) |
| 124 | activeStr := fmt.Sprintf("%v", e.Active) |
| 125 | sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr))) |
| 126 | e.writeExpiry(&sb, cs) |
| 127 | if e.RefreshTokenExpiresAt != nil && !e.RefreshTokenExpiresAt.After(timeNow()) { |
| 128 | loginInstructions := fmt.Sprintf("gh auth login -h %s", e.Host) |
| 129 | sb.WriteString(fmt.Sprintf(" - To re-authenticate, run: %s\n", cs.Bold(loginInstructions))) |
| 130 | } else { |
| 131 | sb.WriteString(fmt.Sprintf(" - To refresh it, run %s (without %s)\n", cs.Bold("gh auth status"), cs.Bold("--no-refresh"))) |
| 132 | } |
| 133 | break |
| 134 | } |
| 135 | if e.Login != "" { |
| 136 | sb.WriteString(fmt.Sprintf(" %s Failed to log in to %s account %s (%s)\n", cs.Red("X"), e.Host, cs.Bold(e.Login), e.TokenSource)) |
| 137 | } else { |
| 138 | sb.WriteString(fmt.Sprintf(" %s Failed to log in to %s using token (%s)\n", cs.Red("X"), e.Host, e.TokenSource)) |
| 139 | } |
| 140 | activeStr := fmt.Sprintf("%v", e.Active) |
| 141 | sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr))) |
| 142 | sb.WriteString(fmt.Sprintf(" - The token in %s is invalid.\n", e.TokenSource)) |
| 143 | if authTokenWriteable(e.TokenSource) { |
| 144 | loginInstructions := fmt.Sprintf("gh auth login -h %s", e.Host) |
nothing calls this directly
no test coverage detected