client

package
v0.0.0-...-374a2f1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2016 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleResponse

func HandleResponse(c *Client, resp *http.Response, pretty bool)

HandleResponse logs the response details and exits the process with a status computed from the response status code. The mapping of response status code to exit status is as follows:

401: 1
402 to 500 (other than 403 and 404): 2
403: 3
404: 4
500+: 5

func WSRead

func WSRead(ws *websocket.Conn)

WSRead reads from a websocket and print the read messages to STDOUT.

func WSWrite

func WSWrite(ws *websocket.Conn)

WSWrite sends STDIN lines to a websocket server.

Types

type APIKeySigner

type APIKeySigner struct {
	// Header is the name of the HTTP header that contains the API key.
	Header string
	// Key stores the actual key.
	Key string
	// Format is the format used to render the key, defaults to "Bearer %s"
	Format string
}

APIKeySigner implements API Key auth.

func (*APIKeySigner) RegisterFlags

func (s *APIKeySigner) RegisterFlags(app *cobra.Command)

RegisterFlags adds the "--key" and "--key-header" flags to the client tool.

func (*APIKeySigner) Sign

func (s *APIKeySigner) Sign(ctx context.Context, req *http.Request) error

Sign adds the API key header to the request.

type BasicSigner

type BasicSigner struct {
	// Username is the basic auth user.
	Username string
	// Password is err guess what? the basic auth password.
	Password string
}

BasicSigner implements basic auth.

func (*BasicSigner) RegisterFlags

func (s *BasicSigner) RegisterFlags(app *cobra.Command)

RegisterFlags adds the "--user" and "--pass" flags to the client tool.

func (*BasicSigner) Sign

func (s *BasicSigner) Sign(ctx context.Context, req *http.Request) error

Sign adds the basic auth header to the request.

type Client

type Client struct {
	// Client is the underlying http client.
	*http.Client
	// Scheme overrides the default action scheme.
	Scheme string
	// Host is the service hostname.
	Host string
	// UserAgent is the user agent set in requests made by the client.
	UserAgent string
	// Dump indicates whether to dump request response.
	Dump bool
}

Client is the common client data structure for all goa service clients.

func New

func New(c *http.Client) *Client

New creates a new API client that wraps c. If c is nil the returned client wraps the default http client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do wraps the underlying http client Do method and adds logging. The logger should be in the context.

type JWTSigner

type JWTSigner struct {
	// Header is the name of the HTTP header which contains the JWT.
	// The default is "Authentication"
	Header string
	// Format represents the format used to render the JWT.
	// The default is "Bearer %s"
	Format string
	// Token stores the actual JWT.
	Token string
}

JWTSigner implements JSON Web Token auth.

func (*JWTSigner) RegisterFlags

func (s *JWTSigner) RegisterFlags(app *cobra.Command)

RegisterFlags adds the "--jwt" flag to the client tool.

func (*JWTSigner) Sign

func (s *JWTSigner) Sign(ctx context.Context, req *http.Request) error

Sign adds the JWT auth header.

type OAuth2Signer

type OAuth2Signer struct {
	// RefreshURLFormat is a format that generates the refresh access token URL given a
	// refresh token.
	RefreshURLFormat string
	// RefreshToken contains the OAuth3 refresh token from which access tokens are
	// created.
	RefreshToken string
	// contains filtered or unexported fields
}

OAuth2Signer enables the use of OAuth2 refresh tokens. It takes care of creating access tokens given a refresh token and a refresh URL as defined in RFC 6749. Note that this signer does not concern itself with generating the initial refresh token, this has to be done prior to using the client. Also it assumes the response of the refresh request response is JSON encoded and of the form:

{
	"access_token":"2YotnFZFEjr1zCsicMWpAA",
	"expires_in":3600,
	"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA"
}

where the "expires_in" and "refresh_token" properties are optional and additional properties are ignored. If the response contains a "expires_in" property then the signer takes care of making refresh requests prior to the token expiration.

func (*OAuth2Signer) Refresh

func (s *OAuth2Signer) Refresh(ctx context.Context) error

Refresh makes a OAuth2 refresh access token request.

func (*OAuth2Signer) RegisterFlags

func (s *OAuth2Signer) RegisterFlags(app *cobra.Command)

RegisterFlags adds the "--refreshURL" and "--refreshToken" flags to the client tool.

func (*OAuth2Signer) Sign

func (s *OAuth2Signer) Sign(ctx context.Context, req *http.Request) error

Sign refreshes the access token if needed and adds the OAuth header.

type Signer

type Signer interface {
	// Sign adds required headers, cookies etc.
	Sign(context.Context, *http.Request) error
	// RegisterFlags registers the command line flags that defines the values used to
	// initialize the signer.
	RegisterFlags(cmd *cobra.Command)
}

Signer is the common interface implemented by all signers.

Jump to

Keyboard shortcuts

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