opa: github.com/open-policy-agent/opa/server/types Index | Files

package types

import "github.com/open-policy-agent/opa/server/types"

Package types contains request/response types and codes for the server.

Index

Package Files

types.go

Constants

const (
    CodeInternal          = "internal_error"
    CodeEvaluation        = "evaluation_error"
    CodeUnauthorized      = "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)"
    MsgParseQueryError            = "error(s) occurred while parsing query"
    MsgCompileQueryError          = "error(s) occurred while compiling query"
    MsgEvaluationError            = "error(s) occurred while evaluating query"
    MsgUnauthorizedUndefinedError = "authorization policy missing or undefined"
    MsgUnauthorizedError          = "request rejected by administrative policy"
    MsgUndefinedError             = "document missing or undefined"
    MsgPluginConfigError          = "error(s) occurred while configuring plugin(s)"
)

Messages included in error responses.

const (
    // ParamQueryV1 defines the name of the HTTP URL parameter that specifies
    // values for the request query.
    ParamQueryV1 = "q"

    // ParamInputV1 defines the name of the HTTP URL parameter that specifies
    // values for the "input" document.
    ParamInputV1 = "input"

    // 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"

    // ParamExplainV1 defines the name of the HTTP URL parameter that indicates the
    // client wants to receive explanations in addition to the result.
    ParamExplainV1 = "explain"

    // 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"

    // ParamInstrumentV1 defines the name of the HTTP URL parameter that
    // indicates the client wants to receive instrumentation data for
    // diagnosing performance issues.
    ParamInstrumentV1 = "instrument"

    // ParamPartialV1 defines the name of the HTTP URL parameter that indicates
    // the client wants the partial evaluation optimization to be used during
    // query evaluation.
    ParamPartialV1 = "partial"

    // ParamProvenanceV1 defines the name of the HTTP URL parameter that indicates
    // the client wants build and version information in addition to the result.
    ParamProvenanceV1 = "provenance"

    // ParamWatchV1 defines the name of the HTTP URL parameter that indicates
    // the client wants to set a watch on the current query or data reference.
    ParamWatchV1 = "watch"

    // ParamBundleActivationV1 defines the name of the HTTP URL parameter that
    // indicates the client wants to include bundle activation in the results
    // of the health API.
    // Deprecated: Use ParamBundlesActivationV1 instead.
    ParamBundleActivationV1 = "bundle"

    // ParamBundlesActivationV1 defines the name of the HTTP URL parameter that
    // indicates the client wants to include bundle activation in the results
    // of the health API.
    ParamBundlesActivationV1 = "bundles"

    // ParamPluginsV1 defines the name of the HTTP URL parameter that
    // indicates the client wants to include bundle status in the results
    // of the health API.
    ParamPluginsV1 = "plugins"
)

func BadPatchOperationErr Uses

func BadPatchOperationErr(op string) error

BadPatchOperationErr returns BadRequestErr indicating the patch operation was invalid.

func BadPatchPathErr Uses

func BadPatchPathErr(path string) error

BadPatchPathErr returns BadRequestErr indicating the patch path was invalid.

func IsBadRequest Uses

func IsBadRequest(err error) bool

IsBadRequest returns true if err is a BadRequestErr.

type AdhocQueryResultSetV1 Uses

type AdhocQueryResultSetV1 []map[string]interface{}

AdhocQueryResultSetV1 models the result of a Query API query.

type BadRequestErr Uses

type BadRequestErr string

BadRequestErr represents an error condition raised if the caller passes invalid parameters.

func (BadRequestErr) Error Uses

func (err BadRequestErr) Error() string

type BindingV1 Uses

type BindingV1 struct {
    Key   *ast.Term `json:"key"`
    Value *ast.Term `json:"value"`
}

BindingV1 represents a single term binding.

func NewBindingsV1 Uses

func NewBindingsV1(locals *ast.ValueMap) (result []*BindingV1)

NewBindingsV1 returns a new BindingsV1 object.

type BindingsV1 Uses

type BindingsV1 []*BindingV1

BindingsV1 represents a set of term bindings.

type CompileRequestV1 Uses

type CompileRequestV1 struct {
    Input    *interface{} `json:"input"`
    Query    string       `json:"query"`
    Unknowns *[]string    `json:"unknowns"`
}

CompileRequestV1 models the request message for Compile API operations.

type CompileResponseV1 Uses

type CompileResponseV1 struct {
    Result      *interface{} `json:"result,omitempty"`
    Explanation TraceV1      `json:"explanation,omitempty"`
    Metrics     MetricsV1    `json:"metrics,omitempty"`
}

CompileResponseV1 models the response message for Compile API operations.

type DataRequestV1 Uses

type DataRequestV1 struct {
    Input *interface{} `json:"input"`
}

DataRequestV1 models the request message for Data API POST operations.

type DataResponseV1 Uses

type DataResponseV1 struct {
    DecisionID  string        `json:"decision_id,omitempty"`
    Provenance  *ProvenanceV1 `json:"provenance,omitempty"`
    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 Uses

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 Uses

func NewErrorV1(code, f string, a ...interface{}) *ErrorV1

NewErrorV1 returns a new ErrorV1 object.

func (*ErrorV1) Bytes Uses

func (e *ErrorV1) Bytes() []byte

Bytes marshals e with indentation for readability.

func (*ErrorV1) Error Uses

func (e *ErrorV1) Error() string

This shall only used for debugging purpose.

func (*ErrorV1) WithASTErrors Uses

func (e *ErrorV1) WithASTErrors(errors []*ast.Error) *ErrorV1

WithASTErrors updates e to include detailed AST errors.

func (*ErrorV1) WithError Uses

func (e *ErrorV1) WithError(err error) *ErrorV1

WithError updates e to include a detailed error.

type ExplainModeV1 Uses

type ExplainModeV1 string

ExplainModeV1 defines supported values for the "explain" query parameter.

const (
    ExplainOffV1   ExplainModeV1 = "off"
    ExplainFullV1  ExplainModeV1 = "full"
    ExplainNotesV1 ExplainModeV1 = "notes"
    ExplainFailsV1 ExplainModeV1 = "fails"
)

Explanation mode enumeration.

type MetricsV1 Uses

type MetricsV1 map[string]interface{}

MetricsV1 models a collection of performance metrics.

type PartialEvaluationResultV1 Uses

type PartialEvaluationResultV1 struct {
    Queries []ast.Body    `json:"queries,omitempty"`
    Support []*ast.Module `json:"support,omitempty"`
}

PartialEvaluationResultV1 represents the output of partial evaluation and is included in Compile API responses.

type PatchV1 Uses

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 PolicyDeleteResponseV1 Uses

type PolicyDeleteResponseV1 struct {
    Metrics MetricsV1 `json:"metrics,omitempty"`
}

PolicyDeleteResponseV1 models the response message for the Policy API delete operation.

type PolicyGetResponseV1 Uses

type PolicyGetResponseV1 struct {
    Result PolicyV1 `json:"result"`
}

PolicyGetResponseV1 models the response message for the Policy API get operation.

type PolicyListResponseV1 Uses

type PolicyListResponseV1 struct {
    Result []PolicyV1 `json:"result"`
}

PolicyListResponseV1 models the response message for the Policy API list operation.

type PolicyPutResponseV1 Uses

type PolicyPutResponseV1 struct {
    Metrics MetricsV1 `json:"metrics,omitempty"`
}

PolicyPutResponseV1 models the response message for the Policy API put operation.

type PolicyV1 Uses

type PolicyV1 struct {
    ID  string      `json:"id"`
    Raw string      `json:"raw"`
    AST *ast.Module `json:"ast"`
}

PolicyV1 models a policy module in OPA.

func (PolicyV1) Equal Uses

func (p PolicyV1) Equal(other PolicyV1) bool

Equal returns true if p is equal to other.

type ProvenanceBundleV1 Uses

type ProvenanceBundleV1 struct {
    Revision string `json:"revision"`
}

ProvenanceBundleV1 models a bundle at some point in time

type ProvenanceV1 Uses

type ProvenanceV1 struct {
    Version   string                        `json:"version"`
    Vcs       string                        `json:"build_commit"`
    Timestamp string                        `json:"build_timestamp"`
    Hostname  string                        `json:"build_hostname"`
    Revision  string                        `json:"revision,omitempty"` // Deprecated: Prefer `Bundles`
    Bundles   map[string]ProvenanceBundleV1 `json:"bundles,omitempty"`
}

ProvenanceV1 models a collection of build/version information.

type QueryRequestV1 Uses

type QueryRequestV1 struct {
    Query string `json:"query"`
}

QueryRequestV1 models the request message for Query API operations.

type QueryResponseV1 Uses

type QueryResponseV1 struct {
    Explanation TraceV1               `json:"explanation,omitempty"`
    Metrics     MetricsV1             `json:"metrics,omitempty"`
    Result      AdhocQueryResultSetV1 `json:"result,omitempty"`
}

QueryResponseV1 models the response message for Query API operations.

type TraceEventV1 Uses

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"`
    Message  string      `json:"message,omitempty"`
}

TraceEventV1 represents a step in the query evaluation process.

func (*TraceEventV1) UnmarshalJSON Uses

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 Uses

type TraceV1 json.RawMessage

TraceV1 models the trace result returned for queries that include the "explain" parameter.

func NewTraceV1 Uses

func NewTraceV1(trace []*topdown.Event, pretty bool) (result TraceV1, err error)

NewTraceV1 returns a new TraceV1 object.

func (TraceV1) MarshalJSON Uses

func (t TraceV1) MarshalJSON() ([]byte, error)

MarshalJSON unmarshals the TraceV1 to a JSON representation.

func (*TraceV1) UnmarshalJSON Uses

func (t *TraceV1) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the TraceV1 from a JSON representation.

type TraceV1Pretty Uses

type TraceV1Pretty []string

TraceV1Pretty models the trace result returned for queries that include the "explain" parameter. The trace is modelled as a human readable array of strings representing the evaluation of the query.

func (*TraceV1Pretty) UnmarshalJSON Uses

func (t *TraceV1Pretty) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the TraceV1Pretty from a JSON representation.

type TraceV1Raw Uses

type TraceV1Raw []TraceEventV1

TraceV1Raw 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 (*TraceV1Raw) UnmarshalJSON Uses

func (t *TraceV1Raw) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the TraceV1Raw from a JSON representation.

type WatchResponseV1 Uses

type WatchResponseV1 struct {
    Explanation TraceV1     `json:"explanation,omitempty"`
    Metrics     MetricsV1   `json:"metrics,omitempty"`
    Result      interface{} `json:"result,omitempty"`

    // The Error needs to be in the response since we've hijacked the connection
    // when writing WatchResponseV1 streams.
    Error *ErrorV1 `json:"error,omitempty"`
}

WatchResponseV1 models a message in the response stream for a watch.

Package types imports 7 packages (graph) and is imported by 28 packages. Updated 2020-02-07. Refresh now. Tools for package owners.