opa: github.com/open-policy-agent/opa/plugins/rest Index | Files

package rest

import "github.com/open-policy-agent/opa/plugins/rest"

Package rest implements a REST client for communicating with remote services.

Index

Package Files

aws.go rest.go rest_auth.go

func Name Uses

func Name(s string) func(*Client)

Name returns an option that overrides the service name on the client.

type Client Uses

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

Client implements an HTTP/REST client for communicating with remote services.

func New Uses

func New(config []byte, opts ...func(*Client)) (Client, error)

New returns a new Client for config.

func (Client) Do Uses

func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error)

Do executes a request using the client.

func (Client) Service Uses

func (c Client) Service() string

Service returns the name of the service this Client is configured for.

func (Client) WithBytes Uses

func (c Client) WithBytes(body []byte) Client

WithBytes returns a shallow copy of the client with the bytes set as the message body to include in the requests.

func (Client) WithHeader Uses

func (c Client) WithHeader(k, v string) Client

WithHeader returns a shallow copy of the client with a header to include the requests.

func (Client) WithJSON Uses

func (c Client) WithJSON(body interface{}) Client

WithJSON returns a shallow copy of the client with the JSON value set as the message body to include the requests. This function sets the Content-Type header.

type Config Uses

type Config struct {
    Name           string            `json:"name"`
    URL            string            `json:"url"`
    Headers        map[string]string `json:"headers"`
    AllowInsureTLS bool              `json:"allow_insecure_tls,omitempty"`
    Credentials    struct {
        Bearer    *bearerAuthPlugin     `json:"bearer,omitempty"`
        ClientTLS *clientTLSAuthPlugin  `json:"client_tls,omitempty"`
        S3Signing *awsSigningAuthPlugin `json:"s3_signing,omitempty"`
    }   `json:"credentials"`
}

Config represents configuration for a REST client.

type HTTPAuthPlugin Uses

type HTTPAuthPlugin interface {
    // implementations can assume NewClient will be called before Prepare
    NewClient(c Config) (*http.Client, error)
    Prepare(req *http.Request) error
}

An HTTPAuthPlugin represents a mechanism to construct and configure HTTP authentication for a REST service

Package rest imports 24 packages (graph) and is imported by 9 packages. Updated 2020-04-07. Refresh now. Tools for package owners.