Documentation ¶
Overview ¶
package opa_client builds a REST client that opa should already exist
Index ¶
- Constants
- Variables
- func GRPCError(err error) error
- type Client
- func (c *Client) Address() string
- func (c *Client) CustomQuery(ctx context.Context, document string, reqData, resp interface{}) error
- func (c *Client) CustomQueryBytes(ctx context.Context, document string, reqData interface{}) ([]byte, error)
- func (c *Client) CustomQueryStream(ctx context.Context, document string, postReqBody []byte, ...) error
- func (c *Client) Health() error
- func (c *Client) Query(ctx context.Context, reqData, resp interface{}) error
- func (c Client) String() string
- func (c *Client) UploadRegoPolicy(ctx context.Context, policyID string, policyRego []byte, resp interface{}) error
- type Clienter
- type ErrorV1
- type Option
- type StreamReaderFn
Constants ¶
const (
DefaultAddress = "http://localhost:8181"
)
Variables ¶
var ( // Opaque errors to reveal less details in upstream client ErrUnknown = types.NewErrorV1("Unknown", "unknown error") )
var (
ErrUndefined = errors.New("undefined decision")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the Clienter interface
func (*Client) CustomQuery ¶
CustomQuery requests evaluation at a document of the caller's choice A non-error OPA response is decoded into resp.
func (*Client) CustomQueryBytes ¶
func (c *Client) CustomQueryBytes(ctx context.Context, document string, reqData interface{}) ([]byte, error)
CustomQueryBytes requests evaluation at a document of the caller's choice If non-error OPA response, returns OPA response bytes.
func (*Client) CustomQueryStream ¶
func (c *Client) CustomQueryStream(ctx context.Context, document string, postReqBody []byte, respRdrFn StreamReaderFn) error
CustomQueryStream requests evaluation at a document of the caller's choice StreamReaderFn is supplied to directly read/parse from non-error OPA response stream.
https://www.openpolicyagent.org/docs/latest/rest-api/#query-api
func (*Client) Query ¶
Query requests evaluation of reqData against the default document: /data/system/main See CustomQuery
func (*Client) UploadRegoPolicy ¶
func (c *Client) UploadRegoPolicy(ctx context.Context, policyID string, policyRego []byte, resp interface{}) error
UploadRegoPolicy creates/updates an OPA policy. Intended for unit-testing.
https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-update-a-policy
type Clienter ¶
type Clienter interface { Address() string CustomQueryStream(ctx context.Context, document string, postReqBody []byte, respRdrFn StreamReaderFn) error CustomQueryBytes(ctx context.Context, document string, reqData interface{}) ([]byte, error) CustomQuery(ctx context.Context, document string, reqData, resp interface{}) error Health() error Query(ctx context.Context, reqData, resp interface{}) error }
Clienter is the opa client interface
FIXME: this interface is incomplete and may change implement at your own discretion
type ErrorV1 ¶
ErrorV1 implements missing errors.Unwrap functionality TODO: issue opened with OPA https://github.com/open-policy-agent/opa/issues/2633
type Option ¶
type Option func(c *Client)
func WithHTTPClient ¶
WithHTTPClient overrides the default http.Client to call Opa
type StreamReaderFn ¶
StreamReaderFn defines fn that accepts io.Reader parameter