serviceauth

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizationContext

func AuthorizationContext(ctx context.Context, token string) context.Context

AuthorizationContext 创建带 Authorization 头的 Context。

func AuthorizationMetadata

func AuthorizationMetadata(token string) metadata.MD

AuthorizationMetadata 返回包含 Authorization 的 metadata。

Types

type RefreshState

type RefreshState int32

RefreshState 刷新状态。

const (
	RefreshStateNormal RefreshState = iota
	RefreshStateRetrying
	RefreshStateCircuitOpen
)

func (RefreshState) String

func (s RefreshState) String() string

type RefreshStats

type RefreshStats struct {
	TotalRefreshes      int64
	SuccessfulRefreshes int64
	FailedRefreshes     int64
	ConsecutiveFailures int64
	LastRefreshTime     time.Time
	LastRefreshError    error
	State               RefreshState
}

RefreshStats 刷新统计。

type RefreshStrategy

type RefreshStrategy struct {
	JitterRatio         float64
	MinBackoff          time.Duration
	MaxBackoff          time.Duration
	BackoffMultiplier   float64
	MaxRetries          int
	CircuitOpenDuration time.Duration
	OnRefreshSuccess    func(token string, expiresIn time.Duration)
	OnRefreshFailure    func(err error, attempt int, nextRetry time.Duration)
	OnCircuitOpen       func()
	OnCircuitClose      func()
}

RefreshStrategy 刷新策略配置。

func DefaultRefreshStrategy

func DefaultRefreshStrategy() *RefreshStrategy

DefaultRefreshStrategy 默认刷新策略。

type ServiceAuthHelper

type ServiceAuthHelper struct {
	// contains filtered or unexported fields
}

ServiceAuthHelper 服务间认证助手。

func NewServiceAuthHelper

func NewServiceAuthHelper(cfg *config.ServiceAuthConfig, authClient ServiceTokenIssuer, opts ...ServiceAuthOption) (*ServiceAuthHelper, error)

NewServiceAuthHelper 创建服务认证助手。

func NewServiceAuthHelperWithCallbacks

func NewServiceAuthHelperWithCallbacks(
	cfg *config.ServiceAuthConfig,
	authClient ServiceTokenIssuer,
	onSuccess func(token string, expiresIn time.Duration),
	onFailure func(err error, attempt int, nextRetry time.Duration),
) (*ServiceAuthHelper, error)

NewServiceAuthHelperWithCallbacks 创建带回调的服务认证助手。

func (*ServiceAuthHelper) CallWithAuth

func (h *ServiceAuthHelper) CallWithAuth(ctx context.Context, fn func(ctx context.Context) error) error

CallWithAuth 使用认证信息执行调用。

func (*ServiceAuthHelper) GetToken

func (h *ServiceAuthHelper) GetToken(ctx context.Context) (string, error)

GetToken 获取当前有效的服务 Token。

func (*ServiceAuthHelper) NewAuthenticatedContext

func (h *ServiceAuthHelper) NewAuthenticatedContext(ctx context.Context) (context.Context, error)

NewAuthenticatedContext 创建带认证信息的 Context。

func (*ServiceAuthHelper) State

func (h *ServiceAuthHelper) State() RefreshState

State 获取当前刷新状态。

func (*ServiceAuthHelper) Stats

func (h *ServiceAuthHelper) Stats() RefreshStats

Stats 获取刷新统计。

func (*ServiceAuthHelper) Stop

func (h *ServiceAuthHelper) Stop()

Stop 停止后台刷新。

type ServiceAuthOption

type ServiceAuthOption func(*ServiceAuthHelper)

ServiceAuthOption 配置选项。

func WithRefreshStrategy

func WithRefreshStrategy(strategy *RefreshStrategy) ServiceAuthOption

WithRefreshStrategy 设置刷新策略。

type ServiceTokenIssuer

type ServiceTokenIssuer interface {
	IssueServiceToken(context.Context, *authnv1.IssueServiceTokenRequest) (*authnv1.IssueServiceTokenResponse, error)
}

ServiceTokenIssuer 定义服务间认证所需的最小签发能力。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL