opa

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package opa provides client make requests to the Open Policy Agent API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	InitializePolicy(policy string) ClientError
	EvaluatePolicy(policy string, input []byte) (*EvaluatePolicyResponse, error)
}

Client is an interface for sending requests to the OPA API

func NewClient

func NewClient(logger *zap.Logger, host string, explainQuery bool) Client

NewClient OpaClient constructor

type ClientError

type ClientError interface {
	error
	Type() ClientErrorType
	CausedBy() error
}

ClientError interface for errors created by client

func NewClientError

func NewClientError(message string, errorType ClientErrorType, causedBy error) ClientError

NewClientError constructor

type ClientErrorType

type ClientErrorType string

ClientErrorType defines error types

const (
	OpaClientErrorTypeGetPolicy      ClientErrorType = "Get Policy"
	OpaClientErrorTypePolicyNotFound ClientErrorType = "Policy Not Found"
	OpaClientErrorTypePublishPolicy  ClientErrorType = "Publish Policy"
	OpaClientErrorTypeHTTP           ClientErrorType = "HTTP Error"
	OpaClientErrorTypeBadResponse    ClientErrorType = "Bad Response"
)

OpaClientErrorType constants

type EvaluatePolicyResponse

type EvaluatePolicyResponse struct {
	Result      *EvaluatePolicyResult `json:"result"`
	Explanation *[]string             `json:"explanation"`
}

EvaluatePolicyResponse OPA evaluate policy response

type EvaluatePolicyResult

type EvaluatePolicyResult struct {
	Pass       bool                       `json:"pass"`
	Violations []*EvaluatePolicyViolation `json:"violations"`
}

EvaluatePolicyResult OPA evaluate policy result

type EvaluatePolicyViolation

type EvaluatePolicyViolation struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Message     string `json:"message"`
	Link        string `json:"link"`
	Pass        bool   `json:"pass"`
}

EvaluatePolicyViolation OPA evaulate policy violation

type EvalutePolicyRequest

type EvalutePolicyRequest struct {
	Input json.RawMessage `json:"input"`
}

EvalutePolicyRequest OPA evalute policy request

type PolicyViolation

type PolicyViolation struct {
	Conditions []byte
}

PolicyViolation Rego rule conditions

func (*PolicyViolation) Write

func (v *PolicyViolation) Write(w io.Writer)

Write Rego rule to IO writer

Jump to

Keyboard shortcuts

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