Documentation ¶
Overview ¶
Package rest implements a REST client for communicating with remote services.
Index ¶
- func AuthPluginLookup(l AuthPluginLookupFunc) func(*Client)
- func DefaultRoundTripperClient(t *tls.Config, timeout int64) *http.Client
- func DefaultTLSConfig(c Config) (*tls.Config, error)
- func Logger(l logging.Logger) func(*Client)
- func Name(s string) func(*Client)
- type AccessToken
- type AuthPluginLookupFunc
- type Client
- func (c Client) AuthPluginLookup() AuthPluginLookupFunc
- func (c Client) Config() *Config
- func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error)
- func (c Client) Logger() logging.Logger
- func (c Client) LoggerFields() map[string]interface{}
- func (c Client) Service() string
- func (c Client) SetResponseHeaderTimeout(timeout *int64) Client
- func (c Client) WithBytes(body []byte) Client
- func (c Client) WithHeader(k, v string) Client
- func (c Client) WithJSON(body interface{}) Client
- type Config
- type HTTPAuthPlugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthPluginLookup ¶ added in v0.26.0
func AuthPluginLookup(l AuthPluginLookupFunc) 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.26.0
DefaultRoundTripperClient is a reasonable set of defaults for HTTP auth plugins
func DefaultTLSConfig ¶ added in v0.26.0
DefaultTLSConfig defines standard TLS configurations based on the Config
Types ¶
type AccessToken ¶ added in v0.25.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 AuthPluginLookupFunc ¶ added in v0.52.0
type AuthPluginLookupFunc func(name string) HTTPAuthPlugin
An AuthPluginLookupFunc can lookup auth plugins by their name.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements an HTTP/REST client for communicating with remote services.
func (Client) AuthPluginLookup ¶ added in v0.52.0
func (c Client) AuthPluginLookup() AuthPluginLookupFunc
AuthPluginLookup returns the lookup function to find a custom registered auth plugin by its name.
func (Client) LoggerFields ¶ added in v0.37.0
LoggerFields returns the fields used for log statements used by Client
func (Client) SetResponseHeaderTimeout ¶ added in v0.29.0
SetResponseHeaderTimeout sets the "ResponseHeaderTimeout" in the http client's Transport
func (Client) WithBytes ¶
WithBytes returns a shallow copy of the client with the bytes set as the message body to include in the requests.
func (Client) WithHeader ¶
WithHeader returns a shallow copy of the client with a header to include the requests.
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) AuthPlugin ¶ added in v0.52.0
func (c *Config) AuthPlugin(lookup AuthPluginLookupFunc) (HTTPAuthPlugin, error)
AuthPlugin should be used to get an authentication method from the config.
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