Documentation
¶
Index ¶
- func GatedFunc(client *Client, action string, fn func() (interface{}, error)) (interface{}, error)
- func GatedFuncWithContext(ctx context.Context, client *Client, action string, target string, ...) (interface{}, error)
- func HTTPMiddleware(client *Client, opts *GatedOptions) func(http.Handler) http.Handler
- type ApprovalRequiredError
- type Client
- func (c *Client) Evaluate(ctx context.Context, action string, target string, actor string, ...) (*GateResult, error)
- func (c *Client) Gate(ctx context.Context, action string, target string, actor string, ...) (*GateResult, error)
- func (c *Client) WaitForApproval(ctx context.Context, flowID string) (string, error)
- type ClientConfig
- type ExecutionAuthorizationRequiredError
- type GateBlockedError
- type GateDecision
- type GateHandler
- type GateResult
- type GatedOptions
- type QerexaError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GatedFunc ¶
GatedFunc wraps a function with gate enforcement.
Example ¶
ExampleGatedFunc demonstrates the GatedFunc wrapper.
client, err := NewClient(&ClientConfig{
APIKey: "sk_live_...",
})
if err != nil {
log.Fatal(err)
}
// Wrap a low-risk function with gate enforcement.
result, err := GatedFunc(client, "records.read", func() (interface{}, error) {
return "public record", nil
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Result: %v\n", result)
func GatedFuncWithContext ¶
func GatedFuncWithContext(ctx context.Context, client *Client, action string, target string, metadata map[string]interface{}, fn func() (interface{}, error)) (interface{}, error)
GatedFuncWithContext wraps a function with gate enforcement using context.
func HTTPMiddleware ¶
HTTPMiddleware wraps an HTTP handler with gate enforcement.
Types ¶
type ApprovalRequiredError ¶
ApprovalRequiredError is raised when human approval is needed but not obtained.
func (*ApprovalRequiredError) Error ¶
func (e *ApprovalRequiredError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Qerexa gate client.
Example ¶
ExampleClient demonstrates basic gate evaluation.
client, err := NewClient(&ClientConfig{
APIKey: "sk_live_...",
})
if err != nil {
log.Fatal(err)
}
// Evaluate without throwing on block
result, err := client.Evaluate(context.Background(), "database.write", "users", "", nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Decision: %v\n", result.Decision)
fmt.Printf("Reason: %s\n", result.Reason)
func NewClient ¶
func NewClient(config *ClientConfig) (*Client, error)
NewClient creates a new Qerexa client.
func (*Client) Evaluate ¶
func (c *Client) Evaluate(ctx context.Context, action string, target string, actor string, metadata map[string]interface{}) (*GateResult, error)
Evaluate makes a gate evaluation request without throwing on block.
type ClientConfig ¶
type ClientConfig struct {
APIKey string
BaseURL string
Timeout int // milliseconds
PollInterval int // milliseconds
ApprovalTimeout int // milliseconds
}
ClientConfig holds configuration for QerexaClient.
type ExecutionAuthorizationRequiredError ¶
ExecutionAuthorizationRequiredError prevents a review approval from being mistaken for permission to execute the protected action.
func (*ExecutionAuthorizationRequiredError) Error ¶
func (e *ExecutionAuthorizationRequiredError) Error() string
type GateBlockedError ¶
GateBlockedError is raised when a gate blocks an action.
func (*GateBlockedError) Error ¶
func (e *GateBlockedError) Error() string
type GateDecision ¶
type GateDecision string
GateDecision represents the outcome of a gate evaluation.
const ( Allowed GateDecision = "allowed" Blocked GateDecision = "blocked" ApprovalRequired GateDecision = "approval_required" )
type GateHandler ¶
GateHandler is a function type that can be gated.
func Gate ¶
func Gate(client *Client, opts *GatedOptions, handler GateHandler) GateHandler
Gate wraps a handler function with gate enforcement.
Example ¶
ExampleGate demonstrates gate enforcement that throws on block.
client, err := NewClient(&ClientConfig{
APIKey: "sk_live_...",
})
if err != nil {
log.Fatal(err)
}
// Gate will raise GateBlockedError if policy denies
result, err := client.Gate(context.Background(), "records.read", "public-catalog", "", nil, true)
if err != nil {
if gbe, ok := err.(*GateBlockedError); ok {
fmt.Printf("Gate blocked: %v\n", gbe.Reason)
} else if are, ok := err.(*ApprovalRequiredError); ok {
fmt.Printf("Approval required: flow %s\n", are.FlowID)
} else {
log.Fatal(err)
}
return
}
fmt.Printf("Action allowed, trust score: %v\n", result.TrustScore)
type GateResult ¶
type GateResult struct {
Decision GateDecision `json:"decision"`
DecisionID string `json:"decision_id,omitempty"`
Reason string `json:"reason,omitempty"`
FlowID string `json:"flow_id,omitempty"`
ReviewDeadline string `json:"review_deadline,omitempty"`
RiskScore *float64 `json:"risk_score,omitempty"`
TrustScore *float64 `json:"trust_score,omitempty"`
Raw map[string]interface{} `json:"raw"`
}
GateResult contains the result of a gate evaluation.
type GatedOptions ¶
type GatedOptions struct {
Action string
Client *Client
Target string
WaitForApproval bool
OnBlock func(error *GateBlockedError) interface{}
}
GatedOptions configures gate behavior for a function or handler.
type QerexaError ¶
type QerexaError struct {
Message string
}
QerexaError is the base error type for all Qerexa errors.
func (*QerexaError) Error ¶
func (e *QerexaError) Error() string