management

package
v7.2.87 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 55 Imported by: 0

Documentation

Overview

Package management provides the management API handlers and middleware for configuring the server and managing auth files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteOAuthSession

func CompleteOAuthSession(state string)

func CompleteOAuthSessionsByProvider

func CompleteOAuthSessionsByProvider(provider string) int

func CompletePluginOAuthSessionsByProvider

func CompletePluginOAuthSessionsByProvider(provider string) int

func GetOAuthSession

func GetOAuthSession(state string) (provider string, status string, ok bool)

func GetOAuthSessionDetails

func GetOAuthSessionDetails(state string) (provider string, status string, isPlugin bool, metadata map[string]any, completed bool, ok bool)

func IsOAuthSessionPending

func IsOAuthSessionPending(state, provider string) bool

func NormalizeOAuthCallbackProvider added in v7.2.49

func NormalizeOAuthCallbackProvider(provider string) (string, error)

func NormalizeOAuthProvider

func NormalizeOAuthProvider(provider string) (string, error)

func NormalizePluginOAuthCallbackProvider added in v7.2.49

func NormalizePluginOAuthCallbackProvider(provider string) (string, error)

func PopulateAuthContext

func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context

PopulateAuthContext extracts request info and adds it to the context

func RegisterOAuthSession

func RegisterOAuthSession(state, provider string)

func RegisterPluginOAuthSession

func RegisterPluginOAuthSession(state, provider string, metadata map[string]any) error

func SetOAuthSessionError

func SetOAuthSessionError(state, message string)

func ValidateOAuthState

func ValidateOAuthState(state string) error

func WriteConfig

func WriteConfig(path string, data []byte) error

func WriteOAuthCallbackFile

func WriteOAuthCallbackFile(authDir, provider, state, code, errorMessage string) (string, error)

func WriteOAuthCallbackFileForPendingSession

func WriteOAuthCallbackFileForPendingSession(authDir, provider, state, code, errorMessage string) (string, error)

Types

type Handler

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

Handler aggregates config reference, persistence path and helpers.

func NewHandler

func NewHandler(cfg *config.Config, configFilePath string, manager *coreauth.Manager) *Handler

NewHandler creates a new management handler instance.

func NewHandlerWithoutConfigFilePath

func NewHandlerWithoutConfigFilePath(cfg *config.Config, manager *coreauth.Manager) *Handler

NewHandler creates a new management handler instance.

func (*Handler) APICall

func (h *Handler) APICall(c *gin.Context)

APICall makes a generic HTTP request on behalf of the management API caller. It is protected by the management middleware.

Endpoint:

POST /v0/management/api-call

Authentication:

Same as other management APIs (requires a management key and remote-management rules).
You can provide the key via:
- Authorization: Bearer <key>
- X-Management-Key: <key>

Request JSON:

  • auth_index / authIndex / AuthIndex (optional): The credential "auth_index" from GET /v0/management/auth-files (or other endpoints returning it). If omitted or not found, credential-specific proxy/token substitution is skipped.
  • method (required): HTTP method, e.g. GET, POST, PUT, PATCH, DELETE.
  • url (required): Absolute URL including scheme and host, e.g. "https://api.example.com/v1/ping".
  • header (optional): Request headers map. Supports magic variable "$TOKEN$" which is replaced using the selected credential: 1) metadata.access_token 2) attributes.api_key 3) metadata.token / metadata.id_token / metadata.cookie Example: {"Authorization":"Bearer $TOKEN$"}. Note: if you need to override the HTTP Host header, set header["Host"].
  • data (optional): Raw request body as string (useful for POST/PUT/PATCH).

Proxy selection (highest priority first):

  1. Selected credential proxy_url
  2. Global config proxy-url
  3. Direct connect (environment proxies are not used)

Response JSON (returned with HTTP 200 when the APICall itself succeeds):

  • status_code: Upstream HTTP status code.
  • header: Upstream response headers.
  • body: Upstream response body as string.

Example:

curl -sS -X POST "http://127.0.0.1:8317/v0/management/api-call" \
  -H "Authorization: Bearer <MANAGEMENT_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"auth_index":"<AUTH_INDEX>","method":"GET","url":"https://api.example.com/v1/ping","header":{"Authorization":"Bearer $TOKEN$"}}'

curl -sS -X POST "http://127.0.0.1:8317/v0/management/api-call" \
  -H "Authorization: Bearer 831227" \
  -H "Content-Type: application/json" \
  -d '{"auth_index":"<AUTH_INDEX>","method":"POST","url":"https://api.example.com/v1/fetchAvailableModels","header":{"Authorization":"Bearer $TOKEN$","Content-Type":"application/json","User-Agent":"cliproxyapi"},"data":"{}"}'

func (*Handler) AuthenticateManagementKey added in v7.2.49

func (h *Handler) AuthenticateManagementKey(clientIP string, localClient bool, provided string) (bool, int, string)

AuthenticateManagementKey 校验管理密钥,并复用管理端的失败计数和封禁规则。 Redis RESP 入口没有 gin.Context,所以需要一个可被非 HTTP 调用方复用的认证方法。

func (*Handler) DeleteAPIKeys

func (h *Handler) DeleteAPIKeys(c *gin.Context)

func (*Handler) DeleteAuthFile

func (h *Handler) DeleteAuthFile(c *gin.Context)

Delete auth files: single by name or all

func (*Handler) DeleteClaudeKey

func (h *Handler) DeleteClaudeKey(c *gin.Context)

func (*Handler) DeleteCodexKey

func (h *Handler) DeleteCodexKey(c *gin.Context)

func (*Handler) DeleteGeminiKey

func (h *Handler) DeleteGeminiKey(c *gin.Context)

func (*Handler) DeleteInteractionsKey added in v7.2.53

func (h *Handler) DeleteInteractionsKey(c *gin.Context)

func (*Handler) DeleteLogs

func (h *Handler) DeleteLogs(c *gin.Context)

DeleteLogs removes all rotated log files and truncates the active log.

func (*Handler) DeleteOAuthExcludedModels

func (h *Handler) DeleteOAuthExcludedModels(c *gin.Context)

func (*Handler) DeleteOAuthModelAlias

func (h *Handler) DeleteOAuthModelAlias(c *gin.Context)

func (*Handler) DeleteOpenAICompat

func (h *Handler) DeleteOpenAICompat(c *gin.Context)

func (*Handler) DeletePlugin

func (h *Handler) DeletePlugin(c *gin.Context)

DeletePlugin removes the selected local plugin file and its saved config.

func (*Handler) DeleteProxyURL

func (h *Handler) DeleteProxyURL(c *gin.Context)

func (*Handler) DeleteVertexCompatKey

func (h *Handler) DeleteVertexCompatKey(c *gin.Context)

func (*Handler) DownloadAuthFile

func (h *Handler) DownloadAuthFile(c *gin.Context)

Download single auth file by name

func (*Handler) DownloadRequestErrorLog

func (h *Handler) DownloadRequestErrorLog(c *gin.Context)

DownloadRequestErrorLog downloads a specific error request log file by name.

func (*Handler) ExportUsageStatistics

func (h *Handler) ExportUsageStatistics(c *gin.Context)

ExportUsageStatistics returns a complete usage snapshot for backup/migration.

func (*Handler) GetAPIKeyUsage

func (h *Handler) GetAPIKeyUsage(c *gin.Context)

GetAPIKeyUsage returns recent request buckets for all in-memory api_key auths, grouped by provider and keyed by "base_url|api_key".

func (*Handler) GetAPIKeys

func (h *Handler) GetAPIKeys(c *gin.Context)

api-keys

func (*Handler) GetAuthFileModels

func (h *Handler) GetAuthFileModels(c *gin.Context)

GetAuthFileModels returns the models supported by a specific auth file

func (*Handler) GetAuthStatus

func (h *Handler) GetAuthStatus(c *gin.Context)

func (*Handler) GetClaudeKeys

func (h *Handler) GetClaudeKeys(c *gin.Context)

claude-api-key: []ClaudeKey

func (*Handler) GetCodexKeys

func (h *Handler) GetCodexKeys(c *gin.Context)

codex-api-key: []CodexKey

func (*Handler) GetConfig

func (h *Handler) GetConfig(c *gin.Context)

func (*Handler) GetConfigYAML

func (h *Handler) GetConfigYAML(c *gin.Context)

GetConfigYAML returns the raw config.yaml file bytes without re-encoding. It preserves comments and original formatting/styles.

func (*Handler) GetDebug

func (h *Handler) GetDebug(c *gin.Context)

Debug

func (*Handler) GetErrorLogsMaxFiles

func (h *Handler) GetErrorLogsMaxFiles(c *gin.Context)

ErrorLogsMaxFiles

func (*Handler) GetForceModelPrefix

func (h *Handler) GetForceModelPrefix(c *gin.Context)

ForceModelPrefix

func (*Handler) GetGeminiKeys

func (h *Handler) GetGeminiKeys(c *gin.Context)

gemini-api-key: []GeminiKey

func (*Handler) GetInteractionsKeys added in v7.2.53

func (h *Handler) GetInteractionsKeys(c *gin.Context)

interactions-api-key: []GeminiKey

func (*Handler) GetLatestVersion

func (h *Handler) GetLatestVersion(c *gin.Context)

GetLatestVersion returns the latest release version from GitHub without downloading assets.

func (*Handler) GetLoggingToFile

func (h *Handler) GetLoggingToFile(c *gin.Context)

UsageStatisticsEnabled

func (*Handler) GetLogs

func (h *Handler) GetLogs(c *gin.Context)

GetLogs returns log lines with optional incremental loading.

The legacy timestamp path keeps line-count as the total scanned line count for compatibility. Cursor and tail reads avoid scanning older files, so line-count is the number of returned lines there. A cursor emitted by the legacy path points at the latest complete log boundary; combining after with limit is therefore tail semantics and does not replay lines trimmed by limit.

func (*Handler) GetLogsMaxTotalSizeMB

func (h *Handler) GetLogsMaxTotalSizeMB(c *gin.Context)

LogsMaxTotalSizeMB

func (*Handler) GetMaxRetryInterval

func (h *Handler) GetMaxRetryInterval(c *gin.Context)

Max retry interval

func (*Handler) GetOAuthCallback added in v7.2.49

func (h *Handler) GetOAuthCallback(c *gin.Context)

func (*Handler) GetOAuthExcludedModels

func (h *Handler) GetOAuthExcludedModels(c *gin.Context)

oauth-excluded-models: map[string][]string

func (*Handler) GetOAuthModelAlias

func (h *Handler) GetOAuthModelAlias(c *gin.Context)

oauth-model-alias: map[string][]OAuthModelAlias

func (*Handler) GetOpenAICompat

func (h *Handler) GetOpenAICompat(c *gin.Context)

openai-compatibility: []OpenAICompatibility

func (*Handler) GetPluginConfig

func (h *Handler) GetPluginConfig(c *gin.Context)

GetPluginConfig returns the preserved plugins.configs.<id> object as JSON.

func (*Handler) GetProxyURL

func (h *Handler) GetProxyURL(c *gin.Context)

Proxy URL

func (*Handler) GetQuotaCache

func (h *Handler) GetQuotaCache(c *gin.Context)

func (*Handler) GetRequestErrorLogs

func (h *Handler) GetRequestErrorLogs(c *gin.Context)

GetRequestErrorLogs lists error request log files when RequestLog is disabled. It returns an empty list when RequestLog is enabled.

func (*Handler) GetRequestLog

func (h *Handler) GetRequestLog(c *gin.Context)

Request log

func (*Handler) GetRequestLogByID

func (h *Handler) GetRequestLogByID(c *gin.Context)

GetRequestLogByID finds and downloads a request log file by its request ID. The ID is matched against the suffix of log file names (format: *-{requestID}.log).

func (*Handler) GetRequestRetry

func (h *Handler) GetRequestRetry(c *gin.Context)

Request retry

func (*Handler) GetRoutingStrategy

func (h *Handler) GetRoutingStrategy(c *gin.Context)

RoutingStrategy

func (*Handler) GetStaticModelDefinitions

func (h *Handler) GetStaticModelDefinitions(c *gin.Context)

GetStaticModelDefinitions returns static model metadata for a given channel. Channel is provided via path param (:channel) or query param (?channel=...).

func (*Handler) GetSwitchPreviewModel

func (h *Handler) GetSwitchPreviewModel(c *gin.Context)

func (*Handler) GetSwitchProject

func (h *Handler) GetSwitchProject(c *gin.Context)

Quota exceeded toggles

func (*Handler) GetUsageQueue added in v7.2.62

func (h *Handler) GetUsageQueue(c *gin.Context)

GetUsageQueue 从 usage 队列弹出最旧的若干条记录,供管理端批量消费。 query: count(可选,默认 1,必须为正整数)。

func (*Handler) GetUsageStatistics

func (h *Handler) GetUsageStatistics(c *gin.Context)

GetUsageStatistics returns the in-memory request statistics snapshot.

func (*Handler) GetUsageStatisticsEnabled

func (h *Handler) GetUsageStatisticsEnabled(c *gin.Context)

UsageStatisticsEnabled

func (*Handler) GetVertexCompatKeys

func (h *Handler) GetVertexCompatKeys(c *gin.Context)

vertex-api-key: []VertexCompatKey

func (*Handler) GetWebsocketAuth

func (h *Handler) GetWebsocketAuth(c *gin.Context)

Websocket auth

func (*Handler) ImportUsageStatistics

func (h *Handler) ImportUsageStatistics(c *gin.Context)

ImportUsageStatistics merges a previously exported usage snapshot into memory.

func (*Handler) ImportVertexCredential

func (h *Handler) ImportVertexCredential(c *gin.Context)

ImportVertexCredential handles uploading a Vertex service account JSON and saving it as an auth record.

func (*Handler) InstallPluginFromStore

func (h *Handler) InstallPluginFromStore(c *gin.Context)

func (*Handler) ListAuthFiles

func (h *Handler) ListAuthFiles(c *gin.Context)

func (*Handler) ListPluginStore

func (h *Handler) ListPluginStore(c *gin.Context)

func (*Handler) ListPlugins

func (h *Handler) ListPlugins(c *gin.Context)

ListPlugins returns discovered, configured, and registered plugin entries.

func (*Handler) Middleware

func (h *Handler) Middleware() gin.HandlerFunc

Middleware enforces access control for management endpoints. All requests (local and remote) require a valid management key. Additionally, remote access requires allow-remote-management=true.

func (*Handler) PatchAPIKeys

func (h *Handler) PatchAPIKeys(c *gin.Context)

func (*Handler) PatchAuthFileFields

func (h *Handler) PatchAuthFileFields(c *gin.Context)

PatchAuthFileFields updates editable fields of one or more auth files.

func (*Handler) PatchAuthFileStatus

func (h *Handler) PatchAuthFileStatus(c *gin.Context)

PatchAuthFileStatus toggles the disabled state of an auth file

func (*Handler) PatchClaudeKey

func (h *Handler) PatchClaudeKey(c *gin.Context)

func (*Handler) PatchCodexKey

func (h *Handler) PatchCodexKey(c *gin.Context)

func (*Handler) PatchGeminiKey

func (h *Handler) PatchGeminiKey(c *gin.Context)

func (*Handler) PatchInteractionsKey added in v7.2.53

func (h *Handler) PatchInteractionsKey(c *gin.Context)

func (*Handler) PatchOAuthExcludedModels

func (h *Handler) PatchOAuthExcludedModels(c *gin.Context)

func (*Handler) PatchOAuthModelAlias

func (h *Handler) PatchOAuthModelAlias(c *gin.Context)

func (*Handler) PatchOpenAICompat

func (h *Handler) PatchOpenAICompat(c *gin.Context)

func (*Handler) PatchPluginConfig

func (h *Handler) PatchPluginConfig(c *gin.Context)

PatchPluginConfig shallow-merges plugins.configs.<id> with the request object.

func (*Handler) PatchPluginEnabled

func (h *Handler) PatchPluginEnabled(c *gin.Context)

PatchPluginEnabled updates plugins.configs.<id>.enabled without touching plugins.enabled.

func (*Handler) PatchVertexCompatKey

func (h *Handler) PatchVertexCompatKey(c *gin.Context)

func (*Handler) PostOAuthCallback

func (h *Handler) PostOAuthCallback(c *gin.Context)

func (*Handler) PutAPIKeys

func (h *Handler) PutAPIKeys(c *gin.Context)

func (*Handler) PutClaudeKeys

func (h *Handler) PutClaudeKeys(c *gin.Context)

func (*Handler) PutCodexKeys

func (h *Handler) PutCodexKeys(c *gin.Context)

func (*Handler) PutConfigYAML

func (h *Handler) PutConfigYAML(c *gin.Context)

func (*Handler) PutDebug

func (h *Handler) PutDebug(c *gin.Context)

func (*Handler) PutErrorLogsMaxFiles

func (h *Handler) PutErrorLogsMaxFiles(c *gin.Context)

func (*Handler) PutForceModelPrefix

func (h *Handler) PutForceModelPrefix(c *gin.Context)

func (*Handler) PutGeminiKeys

func (h *Handler) PutGeminiKeys(c *gin.Context)

func (*Handler) PutInteractionsKeys added in v7.2.53

func (h *Handler) PutInteractionsKeys(c *gin.Context)

func (*Handler) PutLoggingToFile

func (h *Handler) PutLoggingToFile(c *gin.Context)

func (*Handler) PutLogsMaxTotalSizeMB

func (h *Handler) PutLogsMaxTotalSizeMB(c *gin.Context)

func (*Handler) PutMaxRetryInterval

func (h *Handler) PutMaxRetryInterval(c *gin.Context)

func (*Handler) PutOAuthExcludedModels

func (h *Handler) PutOAuthExcludedModels(c *gin.Context)

func (*Handler) PutOAuthModelAlias

func (h *Handler) PutOAuthModelAlias(c *gin.Context)

func (*Handler) PutOpenAICompat

func (h *Handler) PutOpenAICompat(c *gin.Context)

func (*Handler) PutPluginConfig

func (h *Handler) PutPluginConfig(c *gin.Context)

PutPluginConfig replaces plugins.configs.<id> with the request object.

func (*Handler) PutProxyURL

func (h *Handler) PutProxyURL(c *gin.Context)

func (*Handler) PutRequestLog

func (h *Handler) PutRequestLog(c *gin.Context)

func (*Handler) PutRequestRetry

func (h *Handler) PutRequestRetry(c *gin.Context)

func (*Handler) PutRoutingStrategy

func (h *Handler) PutRoutingStrategy(c *gin.Context)

func (*Handler) PutSwitchPreviewModel

func (h *Handler) PutSwitchPreviewModel(c *gin.Context)

func (*Handler) PutSwitchProject

func (h *Handler) PutSwitchProject(c *gin.Context)

func (*Handler) PutUsageStatisticsEnabled

func (h *Handler) PutUsageStatisticsEnabled(c *gin.Context)

func (*Handler) PutVertexCompatKeys

func (h *Handler) PutVertexCompatKeys(c *gin.Context)

func (*Handler) PutWebsocketAuth

func (h *Handler) PutWebsocketAuth(c *gin.Context)

func (*Handler) RefreshQuotaCache

func (h *Handler) RefreshQuotaCache(c *gin.Context)

func (*Handler) RequestAnthropicToken

func (h *Handler) RequestAnthropicToken(c *gin.Context)

func (*Handler) RequestAntigravityToken

func (h *Handler) RequestAntigravityToken(c *gin.Context)

func (*Handler) RequestCodexToken

func (h *Handler) RequestCodexToken(c *gin.Context)

func (*Handler) RequestKimiToken

func (h *Handler) RequestKimiToken(c *gin.Context)

func (*Handler) RequestXAIToken

func (h *Handler) RequestXAIToken(c *gin.Context)

func (*Handler) ResetQuota added in v7.2.49

func (h *Handler) ResetQuota(c *gin.Context)

ResetQuota clears quota/cooldown routing state for one auth index.

func (*Handler) ServePluginAuthURL

func (h *Handler) ServePluginAuthURL(c *gin.Context) bool

func (*Handler) SetAuthManager

func (h *Handler) SetAuthManager(manager *coreauth.Manager)

SetAuthManager updates the auth manager reference used by management endpoints.

func (*Handler) SetConfig

func (h *Handler) SetConfig(cfg *config.Config)

SetConfig updates the in-memory config reference when the server hot-reloads.

func (*Handler) SetConfigReloadHook

func (h *Handler) SetConfigReloadHook(hook func(context.Context, *config.Config))

SetConfigReloadHook updates the callback used after management saves config changes.

func (*Handler) SetLocalPassword

func (h *Handler) SetLocalPassword(password string)

SetLocalPassword configures the runtime-local password accepted for localhost requests.

func (*Handler) SetLogDirectory

func (h *Handler) SetLogDirectory(dir string)

SetLogDirectory updates the directory where main.log should be looked up.

func (*Handler) SetPluginHost

func (h *Handler) SetPluginHost(host *pluginhost.Host)

SetPluginHost updates the plugin host used by plugin-backed management endpoints.

func (*Handler) SetPostAuthHook

func (h *Handler) SetPostAuthHook(hook coreauth.PostAuthHook)

SetPostAuthHook registers a hook to be called after auth record creation but before persistence.

func (*Handler) SetPostAuthPersistHook

func (h *Handler) SetPostAuthPersistHook(hook coreauth.PostAuthHook)

SetPostAuthPersistHook registers a hook to be called after auth persistence.

func (*Handler) SetUsageStatistics

func (h *Handler) SetUsageStatistics(stats *usage.RequestStatistics)

SetUsageStatistics allows replacing the usage statistics reference.

func (*Handler) StartQuotaCacheScheduler

func (h *Handler) StartQuotaCacheScheduler(ctx context.Context)

func (*Handler) StopQuotaCacheScheduler

func (h *Handler) StopQuotaCacheScheduler(ctx context.Context)

func (*Handler) UploadAuthFile

func (h *Handler) UploadAuthFile(c *gin.Context)

Upload auth file: multipart or raw JSON with ?name=

Jump to

Keyboard shortcuts

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