Documentation
¶
Index ¶
- Constants
- func NewCliCredentials(configPath, profile string) *credentials.Credentials
- func UnixTimestampToTime(ts int64) time.Time
- type CliProvider
- type ConsoleLoginOAuthAPIError
- type ConsoleLoginOAuthClient
- type ConsoleLoginOAuthClientAPI
- type ConsoleLoginOAuthClientConfig
- type ConsoleLoginRefreshTokenRequest
- type ConsoleLoginRefreshableProvider
- type ConsoleLoginTokenResponse
- type CreateTokenRequest
- type CreateTokenResponse
- type GetRoleCredentialsRequest
- type GetRoleCredentialsResponse
- type LoginTokenCache
- type OAuthAPIError
- type OAuthClient
- type OAuthClientAPI
- type OAuthClientConfig
- type PortalAPIError
- type PortalClient
- type PortalClientAPI
- type PortalClientConfig
- type ResponseMetadata
- type RoleCredentials
- type SsoRefreshableProvider
- type SsoSession
- type SsoTokenCache
Constants ¶
const (
// CliProviderName provides a name of CLI config provider.
CliProviderName = "CliProvider"
)
Variables ¶
This section is empty.
Functions ¶
func NewCliCredentials ¶
func NewCliCredentials(configPath, profile string) *credentials.Credentials
NewCliCredentials returns a pointer to a new Credentials object wrapping the volcengine-cli config provider.
func UnixTimestampToTime ¶
Types ¶
type CliProvider ¶
type CliProvider struct {
credentials.Expiry
// contains filtered or unexported fields
}
CliProvider retrieves credentials from volcengine-cli's config file (~/.volcengine/config.json).
It supports reading access-key/secret-key/session-token, and will treat sts-expiration (Unix timestamp in seconds or milliseconds) as the credential's expiration time if present.
func NewCliProvider ¶ added in v1.2.27
func NewCliProvider(configPath, profile string) *CliProvider
NewCliProvider returns a raw *CliProvider for use in the default credential chain. Unlike NewCliCredentials, it does not wrap in a Credentials object, allowing the chain to manage expiration and caching uniformly.
func (*CliProvider) IsExpired ¶
func (p *CliProvider) IsExpired() bool
func (*CliProvider) Retrieve ¶
func (p *CliProvider) Retrieve() (credentials.Value, error)
type ConsoleLoginOAuthAPIError ¶ added in v1.2.34
type ConsoleLoginOAuthAPIError struct {
StatusCode int
ErrorCode string
ErrorDesc string
RawBody string
RequestID string
}
ConsoleLoginOAuthAPIError 包装 signin OAuth 端点的非 2xx 响应。 暴露 StatusCode 和结构化 error code,便于上层判断是否属于"refresh token 失效"类不可重试错误(典型为 400 invalid_grant)。
func (*ConsoleLoginOAuthAPIError) Error ¶ added in v1.2.34
func (e *ConsoleLoginOAuthAPIError) Error() string
func (*ConsoleLoginOAuthAPIError) IsRefreshTokenInvalid ¶ added in v1.2.34
func (e *ConsoleLoginOAuthAPIError) IsRefreshTokenInvalid() bool
IsRefreshTokenInvalid 判断错误是否来自"refresh token 不可再用"语义。 服务端在 RT 失效 / 不存在 / 已撤销时按 OAuth 规范返回 400 + invalid_grant; 上层据此触发"重读磁盘 cache fallback"。
type ConsoleLoginOAuthClient ¶ added in v1.2.34
type ConsoleLoginOAuthClient struct {
// contains filtered or unexported fields
}
ConsoleLoginOAuthClient 封装对 signin OAuth 端点的调用,仅实现 refresh_token grant,因为 SDK 不参与交互式授权流程。
func NewConsoleLoginOAuthClient ¶ added in v1.2.34
func NewConsoleLoginOAuthClient(cfg *ConsoleLoginOAuthClientConfig) *ConsoleLoginOAuthClient
NewConsoleLoginOAuthClient 根据配置创建客户端。空配置/空字段时使用默认值。
func (*ConsoleLoginOAuthClient) RefreshToken ¶ added in v1.2.34
func (c *ConsoleLoginOAuthClient) RefreshToken(ctx context.Context, req *ConsoleLoginRefreshTokenRequest) (*ConsoleLoginTokenResponse, error)
RefreshToken 使用 refresh_token grant 换取新的 access_token。
字段校验失败时返回普通 error;HTTP 非 2xx 时返回 *ConsoleLoginOAuthAPIError, 调用方可通过 IsRefreshTokenInvalid 判断是否需触发 fallback。
type ConsoleLoginOAuthClientAPI ¶ added in v1.2.34
type ConsoleLoginOAuthClientAPI interface {
RefreshToken(ctx context.Context, req *ConsoleLoginRefreshTokenRequest) (*ConsoleLoginTokenResponse, error)
}
ConsoleLoginOAuthClientAPI 抽离接口便于在测试中替换实现。
type ConsoleLoginOAuthClientConfig ¶ added in v1.2.34
type ConsoleLoginOAuthClientConfig struct {
// EndpointURL 为 signin 服务的基础地址。空字符串时使用
// defaultConsoleLoginEndpoint。允许测试时注入 httptest.Server URL。
EndpointURL string
// HTTPClient 允许注入自定义 HTTP 客户端(例如代理、超时)。
HTTPClient *http.Client
}
ConsoleLoginOAuthClientConfig 用于配置 ConsoleLoginOAuthClient。
type ConsoleLoginRefreshTokenRequest ¶ added in v1.2.34
ConsoleLoginRefreshTokenRequest 表示 refresh_token grant 的请求参数。 与 ve login 写入的 LoginTokenCache 字段一一对应。
type ConsoleLoginRefreshableProvider ¶ added in v1.2.34
type ConsoleLoginRefreshableProvider struct {
// contains filtered or unexported fields
}
ConsoleLoginRefreshableProvider 提供 console-login 模式的凭证解析与续期。
契约:
- 永不写磁盘。读 login cache 文件只发生在 (a) bootstrap 第一次解析; (b) refresh_token 被服务端判定为 invalid_grant 时触发的 fallback。
- access_token 内含 STS 三元组,未过期时直接返回;过期时用 cache 中的 refresh_token 调 OAuth refresh,更新内存里的 cache + STS。
- refresh_token 失效(服务端 400 invalid_grant)时按 fallback 流程: 重读磁盘 cache → 若磁盘 RT 与内存不同则用磁盘 RT 重试一次 → 仍失败抛错并提示 've login'。
- 进程内并发使用 mu 串行化 refresh,避免重复刷新或竞态。
func (*ConsoleLoginRefreshableProvider) IsExpired ¶ added in v1.2.34
func (p *ConsoleLoginRefreshableProvider) IsExpired() bool
IsExpired 描述"下次 Retrieve 是否需要 refresh"。
func (*ConsoleLoginRefreshableProvider) Retrieve ¶ added in v1.2.34
func (p *ConsoleLoginRefreshableProvider) Retrieve() (credentials.Value, error)
Retrieve 返回当前可用的凭证;如内存状态过期则触发一次同步 refresh。
type ConsoleLoginTokenResponse ¶ added in v1.2.34
type ConsoleLoginTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
IDToken string `json:"id_token"`
}
ConsoleLoginTokenResponse 表示 token 端点的成功响应;字段与 volcengine-cli ConsoleTokenResponse 对齐,以便 SDK 解析行为完全一致。
type CreateTokenRequest ¶
type CreateTokenRequest struct {
GrantType string `json:"grant_type"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
RefreshToken string `json:"refresh_token,omitempty"`
DeviceCode string `json:"device_code,omitempty"`
}
CreateTokenRequest 对应 CreateToken API 的请求参数。
type CreateTokenResponse ¶
type CreateTokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in"`
}
CreateTokenResponse 表示获取 Token 成功后的返回结构。
type GetRoleCredentialsRequest ¶
type GetRoleCredentialsRequest struct {
AccessToken string
AccountID string
RoleName string
PageSize int
PageNumber int
}
GetRoleCredentialsRequest 为 GetRoleCredentials 的请求参数封装。
type GetRoleCredentialsResponse ¶
type GetRoleCredentialsResponse struct {
RoleCredentials RoleCredentials
RequestID string
}
GetRoleCredentialsResponse 返回临时凭证及请求 ID。
type LoginTokenCache ¶ added in v1.2.34
type LoginTokenCache struct {
LoginSession string `json:"login_session"`
AccessToken json.RawMessage `json:"access_token"`
IssuedAt string `json:"issued_at"`
ExpiresIn int64 `json:"expires_in"`
TokenType string `json:"token_type"`
// RefreshToken / ClientID / Scope / EndpointURL are required for the SDK to
// silently refresh the access_token in-memory; mirrors the fields written by
// volcengine-cli's ve login.
RefreshToken string `json:"refresh_token,omitempty"`
ClientID string `json:"client_id,omitempty"`
Scope string `json:"scope,omitempty"`
EndpointURL string `json:"endpoint_url,omitempty"`
}
type OAuthAPIError ¶
OAuthAPIError 用于承载 OAuth API 非 2xx 响应时的结构化错误信息。
func (*OAuthAPIError) Error ¶
func (e *OAuthAPIError) Error() string
type OAuthClient ¶
type OAuthClient struct {
// contains filtered or unexported fields
}
OAuthClient 缓存拼好的 URL 和 HTTP 客户端,避免每次调用重新计算。
func NewOAuthClient ¶
func NewOAuthClient(cfg *OAuthClientConfig) *OAuthClient
NewOAuthClient 根据配置创建 OAuthClient,包含默认值和可选覆盖项。
func (*OAuthClient) CreateToken ¶
func (c *OAuthClient) CreateToken(ctx context.Context, req *CreateTokenRequest) (*CreateTokenResponse, error)
CreateToken 调用 CreateToken API,获取 access/refresh token。
type OAuthClientAPI ¶
type OAuthClientAPI interface {
CreateToken(ctx context.Context, req *CreateTokenRequest) (*CreateTokenResponse, error)
}
OAuthClientAPI 定义 OAuth 客户端对外暴露的方法集合,便于测试或替换实现。
type OAuthClientConfig ¶
type OAuthClientConfig struct {
// Region 控制使用的区域(默认:cn-beijing)。
Region string
// HTTPClient 允许注入自定义 HTTP 客户端(例如代理、超时)。
HTTPClient *http.Client
}
OAuthClientConfig 用于配置 OAuth 客户端的可选项。
type PortalAPIError ¶
PortalAPIError 用于承载 Portal API 非 2xx 响应时的结构化错误信息。
func (*PortalAPIError) Error ¶
func (e *PortalAPIError) Error() string
type PortalClient ¶
type PortalClient struct {
// contains filtered or unexported fields
}
PortalClient 封装 CloudIdentity Portal API 调用,集中管理 URL、HTTP 客户端和默认分页参数。
func NewPortalClient ¶
func NewPortalClient(cfg *PortalClientConfig) *PortalClient
NewPortalClient 根据配置创建 PortalClient,包含默认值和可选覆盖项。
func (*PortalClient) GetRoleCredentials ¶
func (c *PortalClient) GetRoleCredentials(ctx context.Context, req *GetRoleCredentialsRequest) (*GetRoleCredentialsResponse, error)
GetRoleCredentials 使用 Portal 访问令牌换取指定账号和角色的临时凭证。
type PortalClientAPI ¶
type PortalClientAPI interface {
GetRoleCredentials(ctx context.Context, req *GetRoleCredentialsRequest) (*GetRoleCredentialsResponse, error)
}
PortalClientAPI 定义 Portal 客户端对外暴露的方法集合,便于测试或替换实现。
type PortalClientConfig ¶
type PortalClientConfig struct {
Region string // 区域标识(当前逻辑未使用)
BaseURL string // 自定义 Portal 基础地址
HTTPClient *http.Client // 自定义 HTTP 客户端(可注入超时、代理等)
DefaultPageSize int // 默认分页大小
}
PortalClientConfig 用于配置 Portal 客户端的可选项,比如自定义 BaseURL、HTTPClient 或分页大小。
type ResponseMetadata ¶
type ResponseMetadata struct {
RequestID string `json:"RequestId"`
}
ResponseMetadata 表示 Portal API 返回的基础元信息。
type RoleCredentials ¶
type RoleCredentials struct {
AccessKeyID string `json:"AccessKeyId"`
Expiration int64 `json:"Expiration"`
SecretAccessKey string `json:"SecretAccessKey"`
SessionToken string `json:"SessionToken"`
}
RoleCredentials 表示 GetRoleCredentials 返回的临时凭证信息。
type SsoRefreshableProvider ¶ added in v1.2.34
type SsoRefreshableProvider struct {
// contains filtered or unexported fields
}
SsoRefreshableProvider handles SSO credential retrieval and in-memory refresh.
Contract:
- Never writes to disk. The SSO token cache file is read on bootstrap and once more as a fallback when the OAuth server rejects the in-memory refresh token with invalid_grant.
- Fast path: if the in-memory access_token is still within TTL, the OAuth refresh call is skipped; Portal GetRoleCredentials is still called to obtain the STS triple.
- Slow path: calls OAuth refresh then Portal GetRoleCredentials; updates in-memory snapshot only.
- On refresh_token rejection (invalid_grant), re-reads the disk cache once; if the disk RT differs, retries once with the disk state; otherwise errors with a "please run 've sso login'" hint.
- Concurrent Retrieve calls are serialized with sync.Mutex.
func (*SsoRefreshableProvider) IsExpired ¶ added in v1.2.34
func (p *SsoRefreshableProvider) IsExpired() bool
IsExpired reports whether the next Retrieve will require a refresh.
func (*SsoRefreshableProvider) Retrieve ¶ added in v1.2.34
func (p *SsoRefreshableProvider) Retrieve() (credentials.Value, error)
Retrieve returns current valid credentials, refreshing if needed.
type SsoSession ¶
type SsoTokenCache ¶
type SsoTokenCache struct {
StartURL string `json:"start_url"`
SessionName string `json:"session_name"`
AccessToken string `json:"access_token"`
ExpiresAt string `json:"expires_at"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
ClientIdIssuedAt int64 `json:"client_id_issued_at,omitempty"`
ClientSecretExpiresAt int64 `json:"client_secret_expires_at,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Region string `json:"region"`
}