credential

package
v0.0.1-beta.5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package credential 是账号凭据抽象层:类型注册表 + Provider 分发,为后续 多种号池类型(codex oauth、codex personal_access_token、claude code 等) 打地基。本轮实现接口 + api_key/responses-special 两 provider + 接线。

正交原则:Provider 只返回凭据值(key/token),不感知请求格式——鉴权头名由 格式侧决定(openai → Authorization: Bearer、anthropic → x-api-key, aiclient 现状已按格式分头)。

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("credential: unsupported credential type")

ErrUnsupported 未知/未注册的凭据类型。

Functions

This section is empty.

Types

type CredentialInput

type CredentialInput struct {
	AccountID int64
	Type      Type
	APIKey    string // api_key 类型的静态 Key
}

CredentialInput 凭据取用输入:api_key 类型用 APIKey(调度 Selection 携带 的静态 Key);oauth 等类型后续按 AccountID 从凭据扩展表加载(Phase 2)。

type Provider

type Provider interface {
	Type() Type
	Credential(ctx context.Context, in CredentialInput) (string, error)
}

Provider 凭据提供者:Credential 返回当前可用的凭据值(api_key → key; oauth → access_token)。鉴权头名由转发器按请求格式决定,provider 不感知 格式(正交)。

type Registry

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

Registry 类型 → Provider 分发表。

func New

func New() *Registry

New 构造注册表并默认注册 api_key + responses-special 两 provider。

func (*Registry) For

func (r *Registry) For(t Type) Provider

For 取类型的 provider;未注册 → unsupportedProvider 兜底。兜底是安全网而非 静默 fallback:Valid() 通过但未注册的类型也会走到这里——兜底 provider 的 Credential 恒返回 ErrUnsupported,显式报错不吐值(评审 M1)。

func (*Registry) Register

func (r *Registry) Register(p Provider)

Register 注册/覆盖指定类型的 provider。

type Type

type Type string

Type 账号凭据类型:按生态命名(api_key = 静态 Key + 模板 BaseURL,现状语义)。

const (
	// TypeAPIKey 默认类型:静态 Key(调度 Selection 携带的 UpstreamKey)。
	TypeAPIKey Type = "api_key"
	// TypeResponsesSpecial Responses 特殊需求模板(图像 tool 剥离等开关);
	// 只支持 resp / resp-ws 格式(service 校验),配置挂 template_ext。
	TypeResponsesSpecial Type = "responses-special"
	// TypeCodexOAuth Codex OAuth 账号池模板/账号;配置挂 ext 子表,鉴权
	// 接 SDK ws(W6)。
	TypeCodexOAuth Type = "codex-oauth"
	// TypeCodexPAT Codex PAT 账号池模板/账号;配置挂 ext 子表,鉴权接 SDK ws(W6)。
	TypeCodexPAT Type = "codex-pat"
)

func (Type) Valid

func (t Type) Valid() bool

Valid 类型是否已注册可用的凭据类型(模板主列 credential_type 全量:api_key 四格式任意;生态三类型只支持 resp/resp-ws——service 校验)。未知类型(含 空串)→ false。

func (Type) ValidAccountExt

func (t Type) ValidAccountExt() bool

ValidAccountExt 账号 ext 子表可用类型(账号只两种 codex 类型)。

func (Type) ValidTemplateExt

func (t Type) ValidTemplateExt() bool

ValidTemplateExt 模板 ext 子表可用类型(api_key 类型模板无 ext 行——主列已 表达静态 Key 语义)。

Jump to

Keyboard shortcuts

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