Documentation
¶
Index ¶
- Constants
- type APIError
- type Client
- func (c *Client) DataCreateOrOverride(ctx context.Context, path string, data map[string]interface{}) error
- func (c *Client) DataDelete(ctx context.Context, path string) error
- func (c *Client) DataGet(ctx context.Context, path string) (*types.DataResponseV1, error)
- func (c *Client) DataGetWithInput(ctx context.Context, path string, input map[string]interface{}) (*types.DataResponseV1, error)
- func (c *Client) DataUpdate(ctx context.Context, path string, data map[string]interface{}) error
- func (c *Client) PolicyCreateOrUpdate(ctx context.Context, id string, policy []byte) (*types.PolicyPutResponseV1, error)
- func (c *Client) PolicyDelete(ctx context.Context, id string) (*types.PolicyDeleteResponseV1, error)
- func (c *Client) PolicyGet(ctx context.Context, id string) (*types.PolicyGetResponseV1, error)
- func (c *Client) PolicyList(ctx context.Context) (*types.PolicyListResponseV1, error)
- func (c *Client) QueryAdHoc(ctx context.Context, path string, opt QueryAdHocOptions) (*types.QueryResponseV1, error)
- func (c *Client) QuerySimple(ctx context.Context, path string, input map[string]interface{}) ([]byte, error)
- type ClientOptionFunc
- type DataService
- func (ds *DataService) CreateOrOverride(ctx context.Context, p string, data map[string]interface{}) error
- func (ds *DataService) Delete(ctx context.Context, p string) error
- func (ds *DataService) Get(ctx context.Context, p string) (*types.DataResponseV1, error)
- func (ds *DataService) GetWithInput(ctx context.Context, p string, i map[string]interface{}) (*types.DataResponseV1, error)
- func (ds *DataService) Update(ctx context.Context, p string, data map[string]interface{}) error
- type Location
- type PolicyService
- func (ps *PolicyService) CreateOrUpdate(ctx context.Context, id string, policy []byte) (*types.PolicyPutResponseV1, error)
- func (ps *PolicyService) Delete(ctx context.Context, id string) (*types.PolicyDeleteResponseV1, error)
- func (ps *PolicyService) Get(ctx context.Context, id string) (*types.PolicyGetResponseV1, error)
- func (ps *PolicyService) List(ctx context.Context) (*types.PolicyListResponseV1, error)
- type QueryAdHocOptions
- type QueryService
- type Service
Constants ¶
const (
DefaultURL = "http://localhost:8181"
)
Defaults
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { Code string `json:"code"` Message string `json:"message"` Errors []APIError `json:"errors,omitempty"` Location Location `json:"location,omitempty"` Details []string `json:"details,omitempty"` }
APIError models an error response sent to the client. We cannot use directly the type they define as it uses the `Errors []error` so it cannot be marshaled back to the type it was before
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main struct to connect and use OPA
func NewClient ¶
func NewClient(opts ...ClientOptionFunc) (*Client, error)
NewClient initializes a new client that can be configured with the opts
func (*Client) DataCreateOrOverride ¶
func (c *Client) DataCreateOrOverride(ctx context.Context, path string, data map[string]interface{}) error
DataCreateOrOverride creates or replaces the given data on the path p https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-overwrite-a-document
func (*Client) DataDelete ¶
DataDelete deletes the data on the given path p https://www.openpolicyagent.org/docs/latest/rest-api/#delete-a-document
func (*Client) DataGet ¶
DataGet get's the data on the given path p https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document
func (*Client) DataGetWithInput ¶
func (c *Client) DataGetWithInput(ctx context.Context, path string, input map[string]interface{}) (*types.DataResponseV1, error)
DataGetWithInput get's the data on the given path p with the input i https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input
func (*Client) DataUpdate ¶
DataUpdate updates the data on the given path p. Can be used to do partial updates by using the path to specify the element https://www.openpolicyagent.org/docs/latest/rest-api/#patch-a-document
func (*Client) PolicyCreateOrUpdate ¶
func (c *Client) PolicyCreateOrUpdate(ctx context.Context, id string, policy []byte) (*types.PolicyPutResponseV1, error)
PolicyCreateOrUpdate creates or updates the policy with the give id and the content policy https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-update-a-policy
func (*Client) PolicyDelete ¶
func (c *Client) PolicyDelete(ctx context.Context, id string) (*types.PolicyDeleteResponseV1, error)
PolicyDelete deletes the policy with the given id https://www.openpolicyagent.org/docs/latest/rest-api/#delete-a-policy
func (*Client) PolicyGet ¶
PolicyGet returns the policy with the given id https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-policy
func (*Client) PolicyList ¶
PolicyList returns all the policies https://www.openpolicyagent.org/docs/latest/rest-api/#list-policies
func (*Client) QueryAdHoc ¶
func (c *Client) QueryAdHoc(ctx context.Context, path string, opt QueryAdHocOptions) (*types.QueryResponseV1, error)
QueryAdHoc makes a AdHoc query to the path p with the give opt https://www.openpolicyagent.org/docs/latest/rest-api/#execute-an-ad-hoc-query
func (*Client) QuerySimple ¶
func (c *Client) QuerySimple(ctx context.Context, path string, input map[string]interface{}) ([]byte, error)
QuerySimple makes a simple query to the path p with the give input https://www.openpolicyagent.org/docs/latest/rest-api/#execute-a-simple-query
type ClientOptionFunc ¶
ClientOptionFunc is a type used to configure the Client on initialization time
func SetClient ¶
func SetClient(client *http.Client) ClientOptionFunc
SetClient sets the http client used to make the requests to OPA
func SetToken ¶
func SetToken(token string) ClientOptionFunc
SetToken sets the token to use on the requests
type DataService ¶
type DataService struct {
// contains filtered or unexported fields
}
DataService is the services in charge of the Data interactions
func NewDataService ¶
func NewDataService(c *Client) *DataService
NewDataService initializes a new DataService
func (*DataService) CreateOrOverride ¶
func (ds *DataService) CreateOrOverride(ctx context.Context, p string, data map[string]interface{}) error
CreateOrOverride creates or replaces the given data on the path p https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-overwrite-a-document
func (*DataService) Delete ¶
func (ds *DataService) Delete(ctx context.Context, p string) error
Delete deletes the data on the given path p https://www.openpolicyagent.org/docs/latest/rest-api/#delete-a-document
func (*DataService) Get ¶
func (ds *DataService) Get(ctx context.Context, p string) (*types.DataResponseV1, error)
Get get's the data on the given path p https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document
func (*DataService) GetWithInput ¶
func (ds *DataService) GetWithInput(ctx context.Context, p string, i map[string]interface{}) (*types.DataResponseV1, error)
GetWithInput get's the data on the given path p with the input i https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input
func (*DataService) Update ¶
Update updates the data on the given path p. Can be used to do partial updates by using the path to specify the element https://www.openpolicyagent.org/docs/latest/rest-api/#patch-a-document
type Location ¶
type Location struct { Text []byte `json:"-"` // The original text fragment from the source. File string `json:"file"` // The name of the source file (which may be empty). Row int `json:"row"` // The line in the source. Col int `json:"col"` // The column in the row. Offset int `json:"-"` // The byte offset for the location in the source. }
Location records a position in source code
type PolicyService ¶
type PolicyService struct {
// contains filtered or unexported fields
}
PolicyService is the service in charge of the Policy interactions
func NewPolicyService ¶
func NewPolicyService(c *Client) *PolicyService
NewPolicyService initializes a new PolicyService
func (*PolicyService) CreateOrUpdate ¶
func (ps *PolicyService) CreateOrUpdate(ctx context.Context, id string, policy []byte) (*types.PolicyPutResponseV1, error)
CreateOrUpdate creates or updates the policy with the give id and the content policy https://www.openpolicyagent.org/docs/latest/rest-api/#create-or-update-a-policy
func (*PolicyService) Delete ¶
func (ps *PolicyService) Delete(ctx context.Context, id string) (*types.PolicyDeleteResponseV1, error)
Delete deletes the policy with the given id https://www.openpolicyagent.org/docs/latest/rest-api/#delete-a-policy
func (*PolicyService) Get ¶
func (ps *PolicyService) Get(ctx context.Context, id string) (*types.PolicyGetResponseV1, error)
Get returns the policy with the given id https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-policy
func (*PolicyService) List ¶
func (ps *PolicyService) List(ctx context.Context) (*types.PolicyListResponseV1, error)
List returns all the policies https://www.openpolicyagent.org/docs/latest/rest-api/#list-policies
type QueryAdHocOptions ¶
type QueryAdHocOptions struct { Query string `json:"query,omitempty"` Input map[string]interface{} `json:"input,omitempty"` Unknowns []string `json:"unknowns,omitempty"` }
QueryAdHocOptions are the options available to the AdHoc
type QueryService ¶
type QueryService struct {
// contains filtered or unexported fields
}
QueryService is the service in charge of making Queries
func NewQueryService ¶
func NewQueryService(c *Client) *QueryService
NewQueryService initializes a new QueryService
func (*QueryService) AdHoc ¶
func (qs *QueryService) AdHoc(ctx context.Context, p string, opt QueryAdHocOptions) (*types.QueryResponseV1, error)
AdHoc makes a AdHoc query to the path p with the give opt https://www.openpolicyagent.org/docs/latest/rest-api/#execute-an-ad-hoc-query
func (*QueryService) Simple ¶
func (qs *QueryService) Simple(ctx context.Context, p string, input map[string]interface{}) ([]byte, error)
Simple makes a simple query to the path p with the give input https://www.openpolicyagent.org/docs/latest/rest-api/#execute-a-simple-query
type Service ¶
type Service interface { PolicyCreateOrUpdate(ctx context.Context, id string, policy []byte) (*types.PolicyPutResponseV1, error) PolicyList(ctx context.Context) (*types.PolicyListResponseV1, error) PolicyGet(ctx context.Context, id string) (*types.PolicyGetResponseV1, error) PolicyDelete(ctx context.Context, id string) (*types.PolicyDeleteResponseV1, error) DataCreateOrOverride(ctx context.Context, path string, data map[string]interface{}) error DataGet(ctx context.Context, path string) (*types.DataResponseV1, error) DataGetWithInput(ctx context.Context, path string, input map[string]interface{}) (*types.DataResponseV1, error) DataUpdate(ctx context.Context, path string, data map[string]interface{}) error DataDelete(ctx context.Context, path string) error QuerySimple(ctx context.Context, path string, input map[string]interface{}) ([]byte, error) QueryAdHoc(ctx context.Context, path string, opt QueryAdHocOptions) (*types.QueryResponseV1, error) }
Service is the main interface that we support of OPA