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.
| 103 | // with knowledge on how to access encrypted storage when necessary. |
| 104 | // Behavior is scoped to authentication specific tasks. |
| 105 | type AuthConfig interface { |
| 106 | // HasActiveToken returns true when a token for the hostname is present. |
| 107 | HasActiveToken(hostname string) bool |
| 108 | |
| 109 | // ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, |
| 110 | // general configuration, and finally encrypted storage. |
| 111 | ActiveToken(hostname string) (token string, source string) |
| 112 | |
| 113 | // HasEnvToken returns true when a token has been specified in an environment variable, else returns false. |
| 114 | HasEnvToken() bool |
| 115 | |
| 116 | // TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage. |
| 117 | TokenFromKeyring(hostname string) (token string, err error) |
| 118 | |
| 119 | // TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching |
| 120 | // in encrypted storage. |
| 121 | // |
| 122 | // An empty username will return an error because the potential to return the currently active token under |
| 123 | // surprising cases is just too high to risk compared to the utility of having the function being smart. |
| 124 | TokenFromKeyringForUser(hostname, username string) (token string, err error) |
| 125 | |
| 126 | // ActiveUser will retrieve the username for the active user at the given hostname. |
| 127 | // |
| 128 | // This will not be accurate if the oauth token is set from an environment variable. |
| 129 | ActiveUser(hostname string) (username string, err error) |
| 130 | |
| 131 | // Hosts retrieves a list of known hosts. |
| 132 | Hosts() []string |
| 133 | |
| 134 | // DefaultHost retrieves the default host. |
| 135 | DefaultHost() (host string, source string) |
| 136 | |
| 137 | // Login will set user, git protocol, and auth token for the given hostname. |
| 138 | // |
| 139 | // If the encrypt option is specified it will first try to store the auth token |
| 140 | // in encrypted storage and will fall back to the general insecure configuration. |
| 141 | Login(hostname, username, token, gitProtocol string, secureStorage bool) (insecureStorageUsed bool, err error) |
| 142 | |
| 143 | // SwitchUser switches the active user for a given hostname. |
| 144 | SwitchUser(hostname, user string) error |
| 145 | |
| 146 | // Logout will remove user, git protocol, and auth token for the given hostname. |
| 147 | // It will remove the auth token from the encrypted storage if it exists there. |
| 148 | Logout(hostname, username string) error |
| 149 | |
| 150 | // UsersForHost retrieves a list of users configured for a specific host. |
| 151 | UsersForHost(hostname string) []string |
| 152 | |
| 153 | // TokenForUser retrieves the authentication token and its source for a specified user and hostname. |
| 154 | TokenForUser(hostname, user string) (token string, source string, err error) |
| 155 | |
| 156 | // The following methods are only for testing and that is a design smell we should consider fixing. |
| 157 | |
| 158 | // SetActiveToken will override any token resolution and return the given token and source for all calls to |
| 159 | // ActiveToken. |
| 160 | // Use for testing purposes only. |
| 161 | SetActiveToken(token, source string) |
| 162 |
no outgoing calls
no test coverage detected