Documentation
¶
Index ¶
- Variables
- type ConfigLoader
- type CredentialLoader
- type Locker
- type LoginOptions
- type Manager
- 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
Constants ¶
This section is empty.
Variables ¶
var ErrLoginRequired = errors.New("login required")
Functions ¶
This section is empty.
Types ¶
type ConfigLoader ¶
type ConfigLoader interface {
Load() (projectconfig.Config, error)
}
type CredentialLoader ¶
type CredentialLoader interface {
Load(profile string) (credential.Token, error)
}
type LoginOptions ¶
type LoginOptions struct {
Manual bool
}
type Manager ¶
type Manager struct {
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) (credential.Token, error)
// ManualLoginFlow 是其他程序占用私有协议或系统禁止注册协议时永久保留的回退方式。
ManualLoginFlow func(context.Context, string) (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
}