pub struct Credentials { /* private fields */ }Expand description
The credential sources of every service.
Implementations§
Source§impl Credentials
impl Credentials
Sourcepub fn from_system(config: &Config) -> Self
pub fn from_system(config: &Config) -> Self
Uses the process environment, the signed-in accounts and the real
gh CLI.
Sourcepub fn new(
config: &Config,
environment: impl Environment + 'static,
runner: impl Runner + 'static,
) -> Self
pub fn new( config: &Config, environment: impl Environment + 'static, runner: impl Runner + 'static, ) -> Self
Signed-in accounts are kept in memory until Self::with_signed_in.
Sourcepub fn with_signed_in(self, accounts: SignedInAccounts) -> Self
pub fn with_signed_in(self, accounts: SignedInAccounts) -> Self
Reads and keeps signed-in accounts in accounts.
Sourcepub fn with_sign_in_offered(self, offered: bool) -> Self
pub fn with_sign_in_offered(self, offered: bool) -> Self
Whether the app offers Sign in with GitHub (it has an OAuth App). Guidance names it only then; the credential order is the same.
pub fn sign_in_offered(&self) -> bool
Sourcepub fn github(&self, login: Option<&str>) -> Result<Credential, CredentialError>
pub fn github(&self, login: Option<&str>) -> Result<Credential, CredentialError>
The GitHub credential. Without an environment or config token, the
token of login’s account, or of gh’s active account (else the first
account) when login is None.
Sourcepub fn account(&self, login: &str) -> Result<Credential, CredentialError>
pub fn account(&self, login: &str) -> Result<Credential, CredentialError>
The token of exactly the account login: its sign-in through
Subspace, else its gh CLI token. GH_TOKEN, GITHUB_TOKEN and the
config file token are ignored.
Sourcepub fn sign_in(
&self,
login: &str,
token: &Secret,
) -> Result<(), CredentialError>
pub fn sign_in( &self, login: &str, token: &Secret, ) -> Result<(), CredentialError>
Keeps a new sign-in of login, replacing an earlier one.
Sourcepub fn sign_out(&self, login: &str) -> Result<Option<Secret>, CredentialError>
pub fn sign_out(&self, login: &str) -> Result<Option<Secret>, CredentialError>
Forgets the sign-in of login and gives back its token, so it can be
revoked. gh’s own account of the same login is not changed.
Sourcepub fn gh_cli(&self, login: &str) -> Result<Credential, CredentialError>
pub fn gh_cli(&self, login: &str) -> Result<Credential, CredentialError>
The gh CLI token of exactly login, ignoring GH_TOKEN, GITHUB_TOKEN
and the config file token.
Sourcepub fn github_accounts(&self) -> Result<GitHubAccounts, CredentialError>
pub fn github_accounts(&self) -> Result<GitHubAccounts, CredentialError>
The github.com accounts: those signed in through Subspace and gh’s,
from hosts.yml in gh’s config directory. Only logins are read,
never token values.
Sourcepub fn invalidate(&self, credential: &Credential)
pub fn invalidate(&self, credential: &Credential)
Drops a cached token after the service rejected it (REQ-22), so the next call asks again. A rejected signed-in token marks its account as needing sign-in again.
Sourcepub fn forget_gh_token(&self, login: &str)
pub fn forget_gh_token(&self, login: &str)
Drops the cached gh token of login, such as after a new sign-in.