Documentation
¶
Index ¶
- func IsAuthError(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsOAuthError(err error) bool
- func IsServerError(err error) bool
- type Action
- type AuthorizeContext
- type AuthorizeRequest
- type AuthorizeResponse
- type BatchEvalItem
- type BatchEvaluationRequest
- type BatchEvaluationResponse
- type BatchOptions
- type Client
- func (c *Client) Authorize(ctx context.Context, req *AuthorizeRequest) (*AuthorizeResponse, error)
- func (c *Client) AuthorizeBatch(ctx context.Context, req *BatchEvaluationRequest) (*BatchEvaluationResponse, error)
- func (c *Client) Check(ctx context.Context, subject Subject, action string, resource Resource) (bool, error)
- func (c *Client) CheckBatch(ctx context.Context, req *BatchEvaluationRequest) ([]bool, error)
- func (c *Client) HTTPMiddleware(resourceType, action, subjectIDHeader string) func(http.Handler) http.Handler
- type ClientOption
- type Error
- type OAuthError
- type Resource
- type Subject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAuthError ¶
IsAuthError returns true if the error is a 401 Unauthorized.
func IsForbidden ¶
IsForbidden returns true if the error is a 403 Forbidden.
func IsNotFound ¶
IsNotFound returns true if the error is a 404 Not Found.
func IsOAuthError ¶
IsOAuthError returns true if err is an *OAuthError.
func IsServerError ¶
IsServerError returns true if the error is a 5xx server error.
Types ¶
type Action ¶
type Action struct {
Name string `json:"name"`
Properties map[string]interface{} `json:"properties,omitempty"`
}
Action represents an authorization action (AuthZEN 1.0).
type AuthorizeContext ¶
type AuthorizeContext struct {
Reason string `json:"reason,omitempty"`
ReasonCode string `json:"reason_code,omitempty"`
PolicyID string `json:"policy_id,omitempty"`
AccessPath string `json:"access_path,omitempty"`
}
AuthorizeContext holds detailed context about an authorization decision.
type AuthorizeRequest ¶
type AuthorizeRequest struct {
Subject Subject `json:"subject"`
Resource Resource `json:"resource"`
Action Action `json:"action"`
Context map[string]interface{} `json:"context,omitempty"`
}
AuthorizeRequest is the input for an authorization check.
type AuthorizeResponse ¶
type AuthorizeResponse struct {
Decision bool `json:"decision"`
Context *AuthorizeContext `json:"context,omitempty"`
}
AuthorizeResponse is the result of an authorization check.
type BatchEvalItem ¶
type BatchEvalItem struct {
Subject *Subject `json:"subject,omitempty"`
Action *Action `json:"action,omitempty"`
Resource *Resource `json:"resource,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
}
BatchEvalItem is a single evaluation within a batch request. Nil fields inherit from the top-level defaults in BatchEvaluationRequest.
type BatchEvaluationRequest ¶
type BatchEvaluationRequest struct {
Subject *Subject `json:"subject,omitempty"`
Action *Action `json:"action,omitempty"`
Resource *Resource `json:"resource,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
Evaluations []BatchEvalItem `json:"evaluations"`
Options *BatchOptions `json:"options,omitempty"`
}
BatchEvaluationRequest is the input for a batch authorization check (AuthZEN 1.0 POST /access/v1/evaluations).
type BatchEvaluationResponse ¶
type BatchEvaluationResponse struct {
Evaluations []AuthorizeResponse `json:"evaluations"`
}
BatchEvaluationResponse is the result of a batch authorization check.
type BatchOptions ¶
type BatchOptions struct {
EvaluationsSemantic string `json:"evaluations_semantic,omitempty"`
}
BatchOptions configures batch evaluation behavior.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Vengtoo SDK client.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a new Vengtoo client. For cloud with API key: vengtoo.NewClient("azx_...") For cloud with OAuth: vengtoo.NewClient("", vengtoo.WithOAuth("client-id", "azx_cs_...")) For local agent: vengtoo.NewClient("", vengtoo.WithBaseURL("http://localhost:8181"))
func NewClientWithOptions ¶
func NewClientWithOptions(opts ...ClientOption) (*Client, error)
NewClientWithOptions builds a client using only options (no positional API key). It returns an error if the combination of auth options is invalid (e.g. both apiKey and OAuth provided, or neither for a non-local base URL).
Existing callers should continue using NewClient; this constructor is for callers who want construction-time validation of their auth config.
func (*Client) Authorize ¶
func (c *Client) Authorize(ctx context.Context, req *AuthorizeRequest) (*AuthorizeResponse, error)
Authorize sends a full authorization request and returns the detailed response.
func (*Client) AuthorizeBatch ¶
func (c *Client) AuthorizeBatch(ctx context.Context, req *BatchEvaluationRequest) (*BatchEvaluationResponse, error)
AuthorizeBatch sends a batch evaluation request (AuthZEN 1.0) and returns detailed responses for each evaluation item.
func (*Client) Check ¶
func (c *Client) Check(ctx context.Context, subject Subject, action string, resource Resource) (bool, error)
Check is a convenience method that returns just the boolean result. It accepts action as a plain string for ergonomics and wraps it into an Action object internally.
func (*Client) CheckBatch ¶
CheckBatch is a convenience method that returns just the boolean decisions.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures the client.
func WithBaseURL ¶
func WithBaseURL(url string) ClientOption
WithBaseURL sets a custom base URL (e.g., "http://localhost:8181" for local agent).
func WithHTTPClient ¶
func WithHTTPClient(hc *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client.
func WithOAuth ¶
func WithOAuth(clientID, clientSecret string) ClientOption
WithOAuth configures OAuth2 Client Credentials authentication. The SDK will exchange these credentials for a short-lived bearer token at https://api.vengtoo.com/v1/oauth/token (or the URL set via WithOAuthTokenURL), cache it in memory, and refresh it ~60s before expiry. Mutually exclusive with providing an API key to NewClient.
func WithOAuthTokenURL ¶
func WithOAuthTokenURL(tokenURL string) ClientOption
WithOAuthTokenURL overrides the OAuth2 token endpoint URL (useful for tests and self-hosted Vengtoo installations). Has no effect unless WithOAuth is also supplied.
func WithRetries ¶
func WithRetries(n int) ClientOption
WithRetries sets the max number of retries on transient (5xx) errors. Default is 2.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the HTTP client timeout.
type OAuthError ¶
type OAuthError struct {
StatusCode int
Code string // RFC 6749 error code, e.g. "invalid_client"
Description string
}
OAuthError represents a failure during the OAuth2 Client Credentials token exchange. It is distinct from Error (which wraps API-call failures) so customers can tell "bad client_id/client_secret" apart from "bad authorization request".
func (*OAuthError) Error ¶
func (e *OAuthError) Error() string
type Resource ¶
type Resource struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
}
Resource represents the target of the action.
type Subject ¶
type Subject struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
Properties map[string]interface{} `json:"properties,omitempty"`
Roles []string `json:"roles,omitempty"`
}
Subject represents the entity performing the action.