AuthConfig is used for interacting with some persistent configuration for gh, with knowledge on how to access encrypted storage when necessary. Behavior is scoped to authentication specific tasks.
| 134 | // with knowledge on how to access encrypted storage when necessary. |
| 135 | // Behavior is scoped to authentication specific tasks. |
| 136 | type AuthConfig interface { |
| 137 | // HasActiveToken returns true when a token for the hostname is present. |
| 138 | HasActiveToken(hostname string) bool |
| 139 | |
| 140 | // ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, |
| 141 | // general configuration, and finally encrypted storage. |
| 142 | ActiveToken(hostname string) (token string, source string) |
| 143 | |
| 144 | // ActiveTokenType reports what kind of credential the active token for the |
| 145 | // hostname is, so a caller can decide whether it will do without handling |
| 146 | // the token itself. |
| 147 | ActiveTokenType(hostname string) TokenType |
| 148 | |
| 149 | // HasEnvToken returns true when a token has been specified in an environment variable, else returns false. |
| 150 | HasEnvToken() bool |
| 151 | |
| 152 | // TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage. |
| 153 | TokenFromKeyring(hostname string) (token string, err error) |
| 154 | |
| 155 | // TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching |
| 156 | // in encrypted storage. |
| 157 | // |
| 158 | // An empty username will return an error because the potential to return the currently active token under |
| 159 | // surprising cases is just too high to risk compared to the utility of having the function being smart. |
| 160 | TokenFromKeyringForUser(hostname, username string) (token string, err error) |
| 161 | |
| 162 | // ActiveUser will retrieve the username for the active user at the given hostname. |
| 163 | // |
| 164 | // This will not be accurate if the oauth token is set from an environment variable. |
| 165 | ActiveUser(hostname string) (username string, err error) |
| 166 | |
| 167 | // Hosts retrieves a list of known hosts. |
| 168 | Hosts() []string |
| 169 | |
| 170 | // DefaultHost retrieves the default host. |
| 171 | DefaultHost() (host string, source string) |
| 172 | |
| 173 | // Login will set user, git protocol, and auth token for the given hostname. |
| 174 | // |
| 175 | // If the encrypt option is specified it will first try to store the auth token |
| 176 | // in encrypted storage and will fall back to the general insecure configuration. |
| 177 | Login(hostname, username, token, gitProtocol string, secureStorage bool) (insecureStorageUsed bool, err error) |
| 178 | |
| 179 | // SwitchUser switches the active user for a given hostname. |
| 180 | SwitchUser(hostname, user string) error |
| 181 | |
| 182 | // Logout will remove user, git protocol, and auth token for the given hostname. |
| 183 | // It will remove the auth token from the encrypted storage if it exists there. |
| 184 | Logout(hostname, username string) error |
| 185 | |
| 186 | // UsersForHost retrieves a list of users configured for a specific host. |
| 187 | UsersForHost(hostname string) []string |
| 188 | |
| 189 | // TokenForUser retrieves the authentication token and its source for a specified user and hostname. |
| 190 | TokenForUser(hostname, user string) (token string, source string, err error) |
| 191 | |
| 192 | // The following methods are only for testing and that is a design smell we should consider fixing. |
| 193 |
no outgoing calls
no test coverage detected