pub struct GitHubAuthProvider<R: CommandRunner = RealCommandRunner> { /* private fields */ }Expand description
GitHub 认证提供者,通过 gh CLI 操作认证。
命令执行通过 CommandRunner 抽象,生产环境默认使用
RealCommandRunner,测试可注入自定义 runner 以模拟成功或失败场景。
§Examples
use gitflow_github::GitHubAuthProvider;
let provider = GitHubAuthProvider::new();Implementations§
Source§impl<R: CommandRunner> GitHubAuthProvider<R>
impl<R: CommandRunner> GitHubAuthProvider<R>
Sourcepub fn with_runner(runner: R) -> Self
pub fn with_runner(runner: R) -> Self
使用自定义 CommandRunner 创建提供者。
主要用于测试,可注入模拟 runner 以控制 gh CLI 的输出。
Trait Implementations§
Source§impl<R: CommandRunner> AuthChecker for GitHubAuthProvider<R>
impl<R: CommandRunner> AuthChecker for GitHubAuthProvider<R>
Source§fn is_authenticated(&self) -> bool
fn is_authenticated(&self) -> bool
快速检查是否已认证(不查询 API,仅检查本地凭据)。 Read more
Source§fn check_status(&self) -> AuthCheckResult
fn check_status(&self) -> AuthCheckResult
获取认证检查的详细状态。 Read more
Source§impl<R: CommandRunner + 'static> AuthProvider for GitHubAuthProvider<R>
impl<R: CommandRunner + 'static> AuthProvider for GitHubAuthProvider<R>
Source§fn login<'life0, 'life1, 'async_trait>(
&'life0 self,
token: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn login<'life0, 'life1, 'async_trait>(
&'life0 self,
token: Option<&'life1 str>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
执行交互式登录。
调用 gh auth login,将子进程的 stdout/stderr 透传给终端。
如果提供了 token,则通过 --with-token 参数进行非交互式登录,
并将 token 写入子进程的标准输入,避免其出现在进程参数中。
§Errors
当认证失败或 gh 调用失败时返回错误。
Source§fn logout<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn logout<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
查询当前认证状态。
调用 gh auth status 并解析输出来构造 AuthStatus。
当 gh 命令执行失败或用户未登录时,返回 AuthStatus { logged_in: false }
而非传播错误。
§Errors
仅在 gh 返回非零退出码且无法识别为“未登录“模式时返回错误。
Source§impl<R: Clone + CommandRunner> Clone for GitHubAuthProvider<R>
impl<R: Clone + CommandRunner> Clone for GitHubAuthProvider<R>
Source§fn clone(&self) -> GitHubAuthProvider<R>
fn clone(&self) -> GitHubAuthProvider<R>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<R: Debug + CommandRunner> Debug for GitHubAuthProvider<R>
impl<R: Debug + CommandRunner> Debug for GitHubAuthProvider<R>
Auto Trait Implementations§
impl<R> Freeze for GitHubAuthProvider<R>where
R: Freeze,
impl<R> RefUnwindSafe for GitHubAuthProvider<R>where
R: RefUnwindSafe,
impl<R> Send for GitHubAuthProvider<R>
impl<R> Sync for GitHubAuthProvider<R>
impl<R> Unpin for GitHubAuthProvider<R>where
R: Unpin,
impl<R> UnsafeUnpin for GitHubAuthProvider<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for GitHubAuthProvider<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more