opa_client

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

package opa_client builds a REST client that opa should already exist

Index

Constants

View Source
const (
	DefaultAddress = "http://localhost:8181"
)

Variables

View Source
var (
	// Opaque errors to reveal less details in upstream client
	ErrServiceUnavailable = types.NewErrorV1("ServiceUnavailable", "connection refused")
	ErrUnknown            = types.NewErrorV1("Unknown", "unknown error")
)
View Source
var (
	ErrUndefined = errors.New("undefined decision")
)

Functions

func GRPCError

func GRPCError(err error) error

GRPCError translates opa encodes errors to gRPC status errors

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the Clienter interface

func (*Client) Address

func (c *Client) Address() string

Address retrieves the protocol://address of server

func (*Client) CustomQuery

func (c *Client) CustomQuery(ctx context.Context, document string, reqData, resp interface{}) error

CustomQuery requests evaluation at a document of the caller's choice A non-error OPA response is decoded into resp.

func (*Client) CustomQueryBytes added in v0.0.7

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 added in v0.0.7

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) Health

func (c *Client) Health() error

func (*Client) Query

func (c *Client) Query(ctx context.Context, reqData, resp interface{}) error

Query requests evaluation of reqData against the default document: /data/system/main See CustomQuery

func (Client) String added in v0.0.3

func (c Client) String() string

String implements fmt.Stringer interface

func (*Client) UploadRegoPolicy added in v0.0.3

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

func New

func New(address string, opts ...Option) Clienter

type ErrorV1

type ErrorV1 struct {
	types.ErrorV1
	Err error
}

ErrorV1 implements missing errors.Unwrap functionality TODO: issue opened with OPA https://github.com/open-policy-agent/opa/issues/2633

func NewErrorV1

func NewErrorV1(code string, err error) *ErrorV1

NewErrorV1 returns *ErrorV1

func (*ErrorV1) Unwrap

func (e *ErrorV1) Unwrap() error

Unwrap allows embedding errors within ErrorV1

type Option

type Option func(c *Client)

func WithHTTPClient

func WithHTTPClient(cli *http.Client) Option

WithHTTPClient overrides the default http.Client to call Opa

type StreamReaderFn added in v0.0.7

type StreamReaderFn func(io.Reader) error

StreamReaderFn defines fn that accepts io.Reader parameter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL