package types
import "github.com/open-policy-agent/opa/server/types"
Package types contains request/response types and codes for the server.
Index ¶
- Constants
- func BadPatchOperationErr(op string) error
- func BadPatchPathErr(path string) error
- func IsBadRequest(err error) bool
- func IsWriteConflict(err error) bool
- type AdhocQueryResultSetV1
- type BadRequestErr
- type BindingV1
- type BindingsV1
- type DataRequestV1
- type DataResponseV1
- type ErrorV1
- func NewErrorV1(code, f string, a ...interface{}) *ErrorV1
- func (e *ErrorV1) Bytes() []byte
- func (e *ErrorV1) WithASTErrors(errors []*ast.Error) *ErrorV1
- func (e *ErrorV1) WithError(err error) *ErrorV1
- type ExplainModeV1
- type MetricsV1
- type PatchV1
- type PolicyGetResponseV1
- type PolicyListResponseV1
- type PolicyPutResponseV1
- type PolicyV1
- type QueryResponseV1
- type QueryResultSetV1
- type QueryResultV1
- type TraceEventV1
- type TraceV1
- type WriteConflictErr
Constants ¶
const ( CodeInternal = "internal_error" CodeEvaluation = "evaluation_error" = "unauthorized" CodeInvalidParameter = "invalid_parameter" CodeInvalidOperation = "invalid_operation" CodeResourceNotFound = "resource_not_found" CodeResourceConflict = "resource_conflict" CodeUndefinedDocument = "undefined_document" )
Error codes returned by OPA's REST API.
const ( MsgCompileModuleError = "error(s) occurred while compiling module(s)" MsgCompileQueryError = "error(s) occurred while compiling query" MsgEvaluationError = "error(s) occurred while evaluating query" MsgInputDocError = "input document is missing or conflicts with query" = "authorization policy missing or undefined" = "request rejected by administrative policy" MsgUndefinedError = "document missing or undefined" )
Messages included in error responses.
const ( // ParamInputV1 defines the name of the HTTP URL parameter that specifies // values for the "input" document. ParamInputV1 = "input" // ParamSourceV1 defines the name of the HTTP URL parameter that indicates // the client wants to receive the raw (uncompiled) version of the module. ParamSourceV1 = "source" // ParamPrettyV1 defines the name of the HTTP URL parameter that indicates // the client wants to receive a pretty-printed version of the response. ParamPrettyV1 = "pretty" // ParamMetricsV1 defines the name of the HTTP URL parameter that indicates // the client wants to receive performance metrics in addition to the // result. ParamMetricsV1 = "metrics" )
Functions ¶
func BadPatchOperationErr ¶
BadPatchOperationErr returns BadRequestErr indicating the patch operation was invalid.
func BadPatchPathErr ¶
BadPatchPathErr returns BadRequestErr indicating the patch path was invalid.
func IsBadRequest ¶
IsBadRequest returns true if err is a BadRequestErr.
func IsWriteConflict ¶
IsWriteConflict returns true if err is a WriteConflictErr.
Types ¶
type AdhocQueryResultSetV1 ¶
type AdhocQueryResultSetV1 []map[string]interface{}
AdhocQueryResultSetV1 models the result of a Query API query.
type BadRequestErr ¶
type BadRequestErr string
BadRequestErr represents an error condition raised if the caller passes invalid parameters.
func (BadRequestErr) Error ¶
func (err BadRequestErr) Error() string
type BindingV1 ¶
BindingV1 represents a single term binding.
func NewBindingsV1 ¶
NewBindingsV1 returns a new BindingsV1 object.
type BindingsV1 ¶
type BindingsV1 []*BindingV1
BindingsV1 represents a set of term bindings.
type DataRequestV1 ¶
type DataRequestV1 struct {
Input *interface{} `json:"input"`
}
DataRequestV1 models the request message for Data API POST operations.
type DataResponseV1 ¶
type DataResponseV1 struct { Explanation TraceV1 `json:"explanation,omitempty"` Metrics MetricsV1 `json:"metrics,omitempty"` Result *interface{} `json:"result,omitempty"` }
DataResponseV1 models the response message for Data API read operations.
type ErrorV1 ¶
type ErrorV1 struct { Code string `json:"code"` Message string `json:"message"` Errors []error `json:"errors,omitempty"` }
ErrorV1 models an error response sent to the client.
func NewErrorV1 ¶
NewErrorV1 returns a new ErrorV1 object.
func (*ErrorV1) Bytes ¶
Bytes marshals e with indentation for readability.
func (*ErrorV1) WithASTErrors ¶
WithASTErrors updates e to include detailed AST errors.
func (*ErrorV1) WithError ¶
WithError updates e to include a detailed error.
type ExplainModeV1 ¶
type ExplainModeV1 string
ExplainModeV1 defines supported values for the "explain" query parameter.
const ( ExplainOffV1 ExplainModeV1 = "off" ExplainFullV1 ExplainModeV1 = "full" ExplainTruthV1 ExplainModeV1 = "truth" )
Explanation mode enumeration.
type MetricsV1 ¶
type MetricsV1 map[string]interface{}
MetricsV1 models a collection of performance metrics.
type PatchV1 ¶
type PatchV1 struct { Op string `json:"op"` Path string `json:"path"` Value interface{} `json:"value"` }
PatchV1 models a single patch operation against a document.
type PolicyGetResponseV1 ¶
type PolicyGetResponseV1 struct { Result PolicyV1 `json:"result"` }
PolicyGetResponseV1 models the response message for the Policy API get operation.
type PolicyListResponseV1 ¶
type PolicyListResponseV1 struct { Result []PolicyV1 `json:"result"` }
PolicyListResponseV1 models the response mesasge for the Policy API list operation.
type PolicyPutResponseV1 ¶
type PolicyPutResponseV1 struct { Result PolicyV1 `json:"result"` }
PolicyPutResponseV1 models the response message for the Policy API put operation.
type PolicyV1 ¶
PolicyV1 models a policy module in OPA.
func (PolicyV1) Equal ¶
Equal returns true if p is equal to other.
type QueryResponseV1 ¶
type QueryResponseV1 struct { Explanation TraceV1 `json:"explanation,omitempty"` Metrics MetricsV1 `json:"metrics,omitempty"` Result AdhocQueryResultSetV1 `json:"result"` }
QueryResponseV1 models the response message for Query API operations.
type QueryResultSetV1 ¶
type QueryResultSetV1 []*QueryResultV1
QueryResultSetV1 models the result of a Data API query when the query would return multiple values for the document.
func NewQueryResultSetV1 ¶
func NewQueryResultSetV1(qrs topdown.QueryResultSet) *QueryResultSetV1
NewQueryResultSetV1 returns a new QueryResultSetV1 object.
type QueryResultV1 ¶
type QueryResultV1 struct {
// contains filtered or unexported fields
}
QueryResultV1 models a single result of a Data API query that would return multiple values for the document. The bindings can be used to differentiate between results.
func (*QueryResultV1) MarshalJSON ¶
func (qr *QueryResultV1) MarshalJSON() ([]byte, error)
MarshalJSON serializes the QueryResultV1 object as an array.
type TraceEventV1 ¶
type TraceEventV1 struct { Op string `json:"op"` QueryID uint64 `json:"query_id"` ParentID uint64 `json:"parent_id"` Type string `json:"type"` Node interface{} `json:"node"` Locals BindingsV1 `json:"locals"` }
TraceEventV1 represents a step in the query evaluation process.
func (*TraceEventV1) UnmarshalJSON ¶
func (te *TraceEventV1) UnmarshalJSON(bs []byte) error
UnmarshalJSON deserializes a TraceEventV1 object. The Node field is deserialized based on the type hint from the type property in the JSON object.
type TraceV1 ¶
type TraceV1 []TraceEventV1
TraceV1 models the trace result returned for queries that include the "explain" parameter. The trace is modelled as series of trace events that identify the expression, local term bindings, query hierarchy, etc.
func NewTraceV1 ¶
NewTraceV1 returns a new TraceV1 object.
type WriteConflictErr ¶
WriteConflictErr represents an error condition raised if the caller attempts to modify a virtual document or create a document at a path that conflicts with an existing document.
func (WriteConflictErr) Error ¶
func (err WriteConflictErr) Error() string
Source Files ¶
- Version
- v0.4.9
- Published
- May 16, 2017
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 29 minutes ago –
Tools for package owners.