Documentation
¶
Index ¶
- Variables
- func CommitLogin(ctx context.Context, config ConfigLoader, tokens TokenSaver, locker Locker, ...) error
- func LockProfile(ctx context.Context, locker Locker, profile string) (func() error, error)
- func ValidateTokenSite(token credential.Token, site string) error
- type ConfigLoader
- type CredentialLoader
- type Locker
- type LoginIdentity
- type LoginOptions
- type Manager
- func (m Manager) EnsureFresh(ctx context.Context, profile string) (credential.Token, error)
- func (m Manager) Identity(ctx context.Context, profile string) (LoginIdentity, error)
- func (m Manager) RefreshNow(ctx context.Context, profile string) (credential.Token, error)
- func (m Manager) Supervise(ctx context.Context, profile string, interval time.Duration, ...)
- type ProfileSupervisor
- type Service
- func (s Service) Login(ctx context.Context, requestedProfile string, options LoginOptions) (Status, error)
- func (s Service) Logout(ctx context.Context, requestedProfile string) error
- func (s Service) Refresh(ctx context.Context, requestedProfile string) (Status, error)
- func (s Service) Status(requestedProfile string) (Status, error)
- type Status
- type TokenFreshener
- type TokenRepository
- type TokenSaver
Constants ¶
This section is empty.
Variables ¶
var ErrLoginRequired = errors.New("login required")
Functions ¶
func CommitLogin ¶ added in v0.1.4
func CommitLogin(ctx context.Context, config ConfigLoader, tokens TokenSaver, locker Locker, profile string, token credential.Token) error
CommitLogin 供 CLI 与桌面登录共用。浏览器交互不占锁,提交时重新核对 Profile。
func LockProfile ¶ added in v0.1.4
LockProfile 统一所有凭据写操作的跨进程互斥;同时需要配置锁时先取得此锁。
func ValidateTokenSite ¶ added in v0.1.4
func ValidateTokenSite(token credential.Token, site string) error
ValidateTokenSite 在构造 API 请求前绑定凭据和站点,防止配置变更后发送旧站点的 Token。
Types ¶
type ConfigLoader ¶
type ConfigLoader interface {
Load() (projectconfig.Config, error)
}
type CredentialLoader ¶
type CredentialLoader interface {
Load(profile string) (credential.Token, error)
}
type LoginIdentity ¶ added in v0.2.0
LoginIdentity 代表一次本地登录,不推断未验证的远端用户名或 JWT 声明。
type LoginOptions ¶
type Manager ¶
type Manager struct {
Config ConfigLoader
Tokens TokenRepository
Locker Locker
Refresh func(context.Context, credential.Token) (oauth.TokenResponse, error)
Now func() time.Time
RefreshBefore time.Duration
}
func (Manager) EnsureFresh ¶
func (Manager) RefreshNow ¶
func (Manager) Supervise ¶
func (m Manager) Supervise(ctx context.Context, profile string, interval time.Duration, onError func(error))
Supervise refreshes credentials for future API requests. Its context belongs to the supervisor, not to an established SSH session, so a refresh failure is reported but never closes an active connection.
type ProfileSupervisor ¶
type ProfileSupervisor struct {
Config ConfigLoader
Credentials CredentialLoader
Freshener TokenFreshener
Interval time.Duration
OnError func(profile string, err error)
}
ProfileSupervisor 在应用存活期间持续检查所有已保存 Refresh Token 的 Profile。它每轮重新读取配置和凭据,因此运行期间新增、删除或重新登录的 Profile 不需要重启应用即可生效。
func (ProfileSupervisor) Run ¶
func (s ProfileSupervisor) Run(ctx context.Context)
type Service ¶
type Service struct {
Config ConfigLoader
Tokens TokenRepository
Manager Manager
LoginFlow func(context.Context, string, LoginOptions) (credential.Token, error)
// ManualLoginFlow 是其他程序占用私有协议或系统禁止注册协议时永久保留的回退方式。
ManualLoginFlow func(context.Context, string, LoginOptions) (credential.Token, error)
Revoke func(context.Context, credential.Token) error
Now func() time.Time
Timeout time.Duration
}
type TokenFreshener ¶
type TokenRepository ¶
type TokenRepository interface {
Load(profile string) (credential.Token, error)
Save(profile string, token credential.Token) error
Delete(profile string) error
}
type TokenSaver ¶ added in v0.1.4
type TokenSaver interface {
Save(string, credential.Token) error
}