rest

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthPluginLookup added in v0.44.0

func AuthPluginLookup(l func(string) HTTPAuthPlugin) func(*Client)

AuthPluginLookup assigns a function to lookup an HTTPAuthPlugin to a new Client. It's intended to be used when creating a Client using New(). Usually this is passed the plugins.AuthPlugin func, which retrieves a registered HTTPAuthPlugin from the plugin manager.

func DefaultRoundTripperClient added in v0.44.0

func DefaultRoundTripperClient(t *tls.Config, timeout int64) *http.Client

DefaultRoundTripperClient is a reasonable set of defaults for HTTP auth plugins

func DefaultTLSConfig added in v0.44.0

func DefaultTLSConfig(c Config) (*tls.Config, error)

DefaultTLSConfig defines standard TLS configurations based on the Config

func Logger added in v0.44.0

func Logger(l logging.Logger) func(*Client)

Logger assigns a logger to the client

func Name added in v0.10.1

func Name(s string) func(*Client)

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

Types

type AccessToken added in v0.44.0

type AccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
	TokenType   string `json:"token_type"`
}

AccessToken holds a GCP access token.

type Client

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

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

func New

func New(config []byte, keys map[string]*keys.Config, opts ...func(*Client)) (Client, error)

New returns a new Client for config.

func (Client) Config added in v0.44.0

func (c Client) Config() *Config

Config returns this Client's configuration

func (Client) Do

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

Do executes a request using the client.

func (Client) Logger added in v0.44.0

func (c Client) Logger() logging.Logger

Logger returns the logger assigned to the Client

func (Client) LoggerFields added in v0.44.0

func (c Client) LoggerFields() map[string]interface{}

LoggerFields returns the fields used for log statements used by Client

func (Client) Service

func (c Client) Service() string

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

func (Client) SetResponseHeaderTimeout added in v0.44.0

func (c Client) SetResponseHeaderTimeout(timeout *int64) Client

SetResponseHeaderTimeout sets the "ResponseHeaderTimeout" in the http client's Transport

func (Client) WithBytes

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

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

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

type Config struct {
	Name                         string            `json:"name"`
	URL                          string            `json:"url"`
	Headers                      map[string]string `json:"headers"`
	AllowInsecureTLS             bool              `json:"allow_insecure_tls,omitempty"`
	ResponseHeaderTimeoutSeconds *int64            `json:"response_header_timeout_seconds,omitempty"`
	TLS                          *serverTLSConfig  `json:"tls,omitempty"`
	Credentials                  struct {
		Bearer               *bearerAuthPlugin                  `json:"bearer,omitempty"`
		OAuth2               *oauth2ClientCredentialsAuthPlugin `json:"oauth2,omitempty"`
		ClientTLS            *clientTLSAuthPlugin               `json:"client_tls,omitempty"`
		S3Signing            *awsSigningAuthPlugin              `json:"s3_signing,omitempty"`
		GCPMetadata          *gcpMetadataAuthPlugin             `json:"gcp_metadata,omitempty"`
		AzureManagedIdentity *azureManagedIdentitiesAuthPlugin  `json:"azure_managed_identity,omitempty"`
		Plugin               *string                            `json:"plugin,omitempty"`
	} `json:"credentials"`
	Type string `json:"type,omitempty"`
	// contains filtered or unexported fields
}

Config represents configuration for a REST client.

func (*Config) Equal added in v0.44.0

func (c *Config) Equal(other *Config) bool

Equal returns true if this client config is equal to the other.

type HTTPAuthPlugin added in v0.12.0

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

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

Jump to

Keyboard shortcuts

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