Documentation
¶
Index ¶
- Constants
- type Plugin
- type PluginMetrics
- type SecurePlugin
- func (p *SecurePlugin) CheckResourceLimits() error
- func (p *SecurePlugin) Close() error
- func (p *SecurePlugin) GetDetailedResourceMetrics() map[string]interface{}
- func (p *SecurePlugin) GetMetrics() *PluginMetrics
- func (p *SecurePlugin) GetResourceUsage() (memoryBytes int64, goroutines int32, connections int32)
- func (p *SecurePlugin) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
- func (p *SecurePlugin) SetResourceLimits(maxMemoryBytes int64, maxGoroutines int32, maxConnections int32) error
- func (p *SecurePlugin) UpdateSecurityConfig(config *SecurityConfig)
- type SecurityConfig
Constants ¶
View Source
const ( // 與 contracts/module.card 規範一致:tools 命名空間 ToolID = "detectviz.tools.http_request" PluginID = "detectviz.plugins.http_request_gateway" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) Invoke ¶
func (p *Plugin) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
type PluginMetrics ¶
type PluginMetrics struct {
RequestsTotal int64 // 總請求數
RequestsBlocked int64 // 被安全策略阻擋的請求數
RequestsFailed int64 // 失敗請求數
ResponseSizeSum int64 // 回應體總大小
}
PluginMetrics HTTP 插件的監控指標
type SecurePlugin ¶
type SecurePlugin struct {
// contains filtered or unexported fields
}
SecurePlugin 提供具備安全邊界的 HTTP 請求功能
func NewSecurePluginWithConfig ¶
func NewSecurePluginWithConfig(config *SecurityConfig) *SecurePlugin
NewSecurePluginWithConfig 使用自訂安全配置創建插件
func (*SecurePlugin) CheckResourceLimits ¶
func (p *SecurePlugin) CheckResourceLimits() error
CheckResourceLimits 檢查是否超過資源限制
func (*SecurePlugin) GetDetailedResourceMetrics ¶
func (p *SecurePlugin) GetDetailedResourceMetrics() map[string]interface{}
GetDetailedResourceMetrics 獲取詳細的資源指標
func (*SecurePlugin) GetMetrics ¶
func (p *SecurePlugin) GetMetrics() *PluginMetrics
GetMetrics 返回插件的監控指標
func (*SecurePlugin) GetResourceUsage ¶
func (p *SecurePlugin) GetResourceUsage() (memoryBytes int64, goroutines int32, connections int32)
GetResourceUsage 實作 ResourceAwareHandler 接口 - 返回當前資源使用情況
func (*SecurePlugin) Invoke ¶
func (p *SecurePlugin) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
Invoke 執行 HTTP 請求(具備完整安全檢查)
func (*SecurePlugin) SetResourceLimits ¶
func (p *SecurePlugin) SetResourceLimits(maxMemoryBytes int64, maxGoroutines int32, maxConnections int32) error
SetResourceLimits 實作 ResourceAwareHandler 接口 - 設置資源限制
func (*SecurePlugin) UpdateSecurityConfig ¶
func (p *SecurePlugin) UpdateSecurityConfig(config *SecurityConfig)
UpdateSecurityConfig 更新安全配置(熱更新)
type SecurityConfig ¶
type SecurityConfig struct {
// URL 白名單和黑名單
AllowedDomains []string `json:"allowed_domains"` // 允許的域名列表
BlockedDomains []string `json:"blocked_domains"` // 禁止的域名列表
AllowedURLPattern []*regexp.Regexp `json:"-"` // 允許的 URL 正則模式
BlockedURLPattern []*regexp.Regexp `json:"-"` // 禁止的 URL 正則模式
// 資源限制
MaxRequestSize int64 `json:"max_request_size"` // 最大請求體大小(位元組)
MaxResponseSize int64 `json:"max_response_size"` // 最大回應體大小(位元組)
MaxRedirects int `json:"max_redirects"` // 最大重定向次數
// 超時控制
MinTimeoutMs int `json:"min_timeout_ms"` // 最小超時時間(毫秒)
MaxTimeoutMs int `json:"max_timeout_ms"` // 最大超時時間(毫秒)
// 網路限制
BlockPrivateIPs bool `json:"block_private_ips"` // 禁止私有 IP 地址
BlockLocalhost bool `json:"block_localhost"` // 禁止 localhost
AllowedSchemes []string `json:"allowed_schemes"` // 允許的協定方案
// Headers 控制
BlockedHeaders []string `json:"blocked_headers"` // 禁止的標頭名稱
RequiredHeaders map[string]string `json:"required_headers"` // 必要的標頭
}
安全邊界配置 - 防範惡意或誤用的外部調用
func DefaultSecurityConfig ¶
func DefaultSecurityConfig() *SecurityConfig
DefaultSecurityConfig 返回預設的安全配置
func (*SecurityConfig) SanitizeHeaders ¶
func (sc *SecurityConfig) SanitizeHeaders(headers map[string]string) map[string]string
SanitizeHeaders 清理和標準化請求標頭
func (*SecurityConfig) ValidateRequest ¶
func (sc *SecurityConfig) ValidateRequest(method, urlStr string, headers map[string]string, body []byte, timeoutMs int) error
ValidateRequest 驗證 HTTP 請求是否符合安全要求
func (*SecurityConfig) ValidateResponseSize ¶
func (sc *SecurityConfig) ValidateResponseSize(size int64) error
ValidateResponseSize 驗證回應體大小
Click to show internal directories.
Click to hide internal directories.