httpclient

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	MartiniClient
}

API defines API client interface

type AcmeClient

type AcmeClient interface {
	// Directory returns directory response
	Directory(ctx context.Context) (map[string]string, error)
}

AcmeClient interface

type Client

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

Client represents a logical connection to a Trusty cluster, it is safe for concurrent use across multiple go-routines.

func New

func New(config *Config, initialHosts []string) (*Client, error)

New creates a new Trusty Client based on the supplied cluster members there needs to be at least one member from the cluster, starting from that the cluster membership, leader etc will be discovered. The Client is based on the supplied config, but the config is not referenced again after this [i.e. you can twiddle the config object you supply after you've created a client, and it'll make no difference to existing clients]

func (*Client) AddHeader

func (c *Client) AddHeader(header, value string) *Client

AddHeader adds additional header to the request

func (*Client) ApproveOrg

func (c *Client) ApproveOrg(ctx context.Context, token, code, action string) (*v1.OrgResponse, error)

ApproveOrg approves Org registration

func (*Client) Certificates

func (c *Client) Certificates(ctx context.Context) (*v1.CertificatesResponse, error)

Certificates returns user's Certificates

func (*Client) Config

func (c *Client) Config() *Config

Config of the client, particularly around error & retry handling

func (*Client) CreateSubscription

CreateSubscription pays for Org validation

func (*Client) CurrentHost

func (c *Client) CurrentHost() string

CurrentHost returns the cluster member that is currently being used to service requests [typically this is the leader, but is not guaranteed to be so]

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, body interface{}) (http.Header, int, error)

Delete removes the supplied resource using the current selected cluster member [typically the leader], it will decode the response payload into the supplied body parameter. it returns the HTTP status code, and an optional error for responses with status codes >= 300 it will try and convert the response into an go error. If configured, this call will wait & retry on rate limit and leader election errors path should be an absolute URI path, i.e. /foo/bar/baz

func (*Client) DeleteOrg

func (c *Client) DeleteOrg(ctx context.Context, orgID string) error

DeleteOrg deletes Org

func (*Client) Directory

func (c *Client) Directory(ctx context.Context) (map[string]string, error)

Directory returns directory response

func (*Client) FccContact

func (c *Client) FccContact(ctx context.Context, frn string) (*v1.FccContactResponse, error)

FccContact returns Fcc FRN Contact

func (*Client) FccFRN

func (c *Client) FccFRN(ctx context.Context, filerID string) (*v1.FccFrnResponse, error)

FccFRN returns Fcc FRN

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, body interface{}) (http.Header, int, error)

Get fetches the supplied resource using the current selected cluster member [typically the leader], it will decode the response payload into the supplied body parameter. it returns the HTTP status code, and an optional error for responses with status codes >= 300 it will try and convert the response into an go error. If configured, this call will wait & retry on rate limit and leader election errors path should be an absolute URI path, i.e. /foo/bar/baz

func (*Client) GetFrom

func (c *Client) GetFrom(ctx context.Context, hosts []string, path string, body interface{}) (http.Header, int, error)

GetFrom is the same as Get but makes the request to the specified host. The list of hosts in hosts are tried until one succeeds you can use CurrentMembership to find out the hosts we think are currently part of the cluster. each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444 path should be an absolute URI path, i.e. /foo/bar/baz

func (*Client) GetOrgAPIKeys

func (c *Client) GetOrgAPIKeys(ctx context.Context, orgID string) (*v1.GetOrgAPIKeysResponse, error)

GetOrgAPIKeys returns Org API keys

func (*Client) GetResponse

func (c *Client) GetResponse(ctx context.Context, path string, body io.Writer) (http.Header, int, error)

GetResponse makes a GET request to the server, path should be an absolute URI path, i.e. /foo/bar/baz the resulting HTTP body will be returned into the supplied body parameter, and the http status code returned.

func (*Client) Hosts

func (c *Client) Hosts() []string

Hosts returns the full list of all cluster members

func (*Client) ListSubscriptions

func (c *Client) ListSubscriptions(ctx context.Context) (*v1.ListSubscriptionsResponse, error)

ListSubscriptions returns user's subscriptions

func (*Client) ListSubscriptionsProducts

func (c *Client) ListSubscriptionsProducts(ctx context.Context) (*v1.SubscriptionsProductsResponse, error)

ListSubscriptionsProducts returns list of available products

func (*Client) Nonce

func (c *Client) Nonce() (string, error)

Nonce implement jose.NonceSource.

func (*Client) Org

func (c *Client) Org(ctx context.Context, id string) (*v1.OrgResponse, error)

Org returns the organization

func (*Client) OrgMemberAdd

func (c *Client) OrgMemberAdd(ctx context.Context, orgID, email, role string) (*v1.OrgMembersResponse, error)

OrgMemberAdd adds a member to an org

func (*Client) OrgMemberRemove

func (c *Client) OrgMemberRemove(ctx context.Context, orgID, memberID string) (*v1.OrgMembersResponse, error)

OrgMemberRemove removes a member from an org

func (*Client) OrgMembers

func (c *Client) OrgMembers(ctx context.Context, orgID string) (*v1.OrgMembersResponse, error)

OrgMembers returns org members

func (*Client) Orgs

func (c *Client) Orgs(ctx context.Context) (*v1.OrgsResponse, error)

Orgs returns user's Orgs

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body []byte, responseBody interface{}) (http.Header, int, error)

Post makes an HTTP POST to the supplied path. The HTTP response will be decoded into reponseBody, and the status code (and potentially an error) returned. It'll try and map errors (statusCode >= 300) into a go error, waits & retries for rate limiting errors will be applied based on the client config. path should be an absolute URI path, i.e. /foo/bar/baz

func (*Client) PostRequest

func (c *Client) PostRequest(ctx context.Context, path string, requestBody interface{}, responseBody interface{}) (http.Header, int, error)

PostRequest makes an HTTP POST to the supplied path, serializing requestBody to json and sending that as the HTTP body. the HTTP response will be decoded into reponseBody, and the status code (and potentially an error) returned. It'll try and map errors (statusCode >= 300) into a go error, waits & retries for rate limiting errors will be applied based on the client config. path should be an absolute URI path, i.e. /foo/bar/baz

func (*Client) PostRequestTo

func (c *Client) PostRequestTo(ctx context.Context, hosts []string, path string, requestBody interface{}, responseBody interface{}) (http.Header, int, error)

PostRequestTo is the same as Post, but to the specified host. [the supplied hosts are tried in order until one succeeds, or we run out] each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444 path should be an absolute URI path, i.e. /foo/bar/baz if set, the callers identity will be passed to Trusty via the X-Trusty-Identity header

func (*Client) PostTo

func (c *Client) PostTo(ctx context.Context, hosts []string, path string, body []byte, responseBody interface{}) (http.Header, int, error)

PostTo is the same as Post, but to the specified host. [the supplied hosts are tried in order until one succeeds, or we run out] each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444 path should be an absolute URI path, i.e. /foo/bar/baz if set, the callers identity will be passed to Trusty via the X-Trusty-Identity header

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context) (*v1.AuthTokenRefreshResponse, error)

RefreshToken returns AuthTokenRefreshResponse

func (*Client) RegisterOrg

func (c *Client) RegisterOrg(ctx context.Context, filerID string) (*v1.OrgResponse, error)

RegisterOrg starts Org registration flow

func (*Client) Retriable

func (c *Client) Retriable() *retriable.Client

Retriable returns retriable http client

func (*Client) SearchCorps

func (c *Client) SearchCorps(ctx context.Context, name, jurisdiction string) (*v1.SearchOpenCorporatesResponse, error)

SearchCorps returns SearchOpenCorporatesResponse

func (*Client) SearchOrgs

func (c *Client) SearchOrgs(ctx context.Context, frn, regID string) (*v1.OrgsResponse, error)

SearchOrgs returns OrgsResponse

func (*Client) ValidateOrg

func (c *Client) ValidateOrg(ctx context.Context, orgID string) (*v1.ValidateOrgResponse, error)

ValidateOrg validates Org registration

func (*Client) WithAuthorization

func (c *Client) WithAuthorization() *Client

WithAuthorization sets Authorization token

func (*Client) WithHeaders

func (c *Client) WithHeaders(headers map[string]string) *Client

WithHeaders adds additional headers to the request

func (*Client) WithNonce

func (c *Client) WithNonce(noncePath string) *Client

WithNonce allows to specify a Nonce path

func (*Client) WithPolicy

func (c *Client) WithPolicy(r *retriable.Policy) *Client

WithPolicy changes the retry policy

type Config

type Config struct {

	// TLS contains all the TLS/HTTPS configuration, at a minimum Certificates should be set to the client cert
	// [a client cert is required to communicate with Keydi]
	TLS *tls.Config `json:"-"`
}

Config of the client, particularly around error & retry handling

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config populated with recommended defaults

type GenericHTTP

type GenericHTTP interface {
	// Context returns the current context
	Context() context.Context

	// WithContext sets new context
	WithContext(ctx context.Context) *Client

	// Get makes a GET request to he CurrentHost, path should be an absolute URI path, i.e. /foo/bar/baz
	// the resulting HTTP body will be decoded into the supplied body parameter, and the
	// http status code returned.
	Get(ctx context.Context, path string, body interface{}) (http.Header, int, error)

	// GetResponse makes a GET request to the server, path should be an absolute URI path, i.e. /foo/bar/baz
	// the resulting HTTP body will be returned into the supplied body parameter, and the
	// http status code returned.
	GetResponse(ctx context.Context, path string, body io.Writer) (http.Header, int, error)

	// GetFrom is the same as Get but makes the request to the specified host.
	// The list of hosts in hosts are tried until one succeeds
	// you can use CurrentMembership to find out the hosts we think are currently
	// part of the cluster.
	// each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444
	// path should be an absolute URI path, i.e. /foo/bar/baz
	GetFrom(ctx context.Context, hosts []string, path string, body interface{}) (http.Header, int, error)

	// PostRequest makes an HTTP POST to the supplied path, serializing requestBody to json and sending
	// that as the HTTP body. the HTTP response will be decoded into reponseBody, and the status
	// code (and potentially an error) returned. It'll try and map errors (statusCode >= 300)
	// into a go error, waits & retries for rate limiting errors will be applied based on the
	// client config.
	// path should be an absolute URI path, i.e. /foo/bar/baz
	PostRequest(ctx context.Context, path string, requestBody interface{}, responseBody interface{}) (http.Header, int, error)

	// PostRequestTo is the same as Post, but to the specified host. [the supplied hosts are
	// tried in order until one succeeds, or we run out]
	// each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444
	// path should be an absolute URI path, i.e. /foo/bar/baz
	// if set, the callers identity will be passed to Trusty via the X-Trusty-Identity header
	PostRequestTo(ctx context.Context, hosts []string, path string, requestBody interface{}, responseBody interface{}) (http.Header, int, error)

	// Post makes an HTTP POST to the supplied path.
	// The HTTP response will be decoded into reponseBody, and the status
	// code (and potentially an error) returned. It'll try and map errors (statusCode >= 300)
	// into a go error, waits & retries for rate limiting errors will be applied based on the
	// client config.
	// path should be an absolute URI path, i.e. /foo/bar/baz
	Post(ctx context.Context, path string, body []byte, responseBody interface{}) (http.Header, int, error)

	// PostTo is the same as Post, but to the specified host. [the supplied hosts are
	// tried in order until one succeeds, or we run out]
	// each host should include all the protocol/host/port preamble, e.g. http://foo.bar:3444
	// path should be an absolute URI path, i.e. /foo/bar/baz
	// if set, the callers identity will be passed to Trusty via the X-Trusty-Identity header
	PostTo(ctx context.Context, hosts []string, path string, body []byte, responseBody interface{}) (http.Header, int, error)

	// Delete makes a DELETE request to the CurrentHost, path should be an absolute URI path, i.e. /foo/bar/baz
	// the resulting HTTP body will be decoded into the supplied body parameter, and the
	// http status code returned.
	Delete(ctx context.Context, path string, body interface{}) (http.Header, int, error)
}

GenericHTTP defines a number of generalized HTTP request handling wrappers

type MartiniClient

type MartiniClient interface {
	// SearchCorps returns SearchOpenCorporatesResponse
	SearchCorps(ctx context.Context, name, jurisdiction string) (*v1.SearchOpenCorporatesResponse, error)
	// SearchOrgs returns OrgsResponse
	SearchOrgs(ctx context.Context, frn, regID string) (*v1.OrgsResponse, error)
	// Orgs returns user's Orgs
	Orgs(ctx context.Context) (*v1.OrgsResponse, error)
	// Org returns the organization
	Org(ctx context.Context, id string) (*v1.OrgResponse, error)
	// OrgMembers returns org members
	OrgMembers(ctx context.Context, orgID string) (*v1.OrgMembersResponse, error)
	// OrgMemberAdd adds a member to the org
	OrgMemberAdd(ctx context.Context, orgID, email, role string) (*v1.OrgMembersResponse, error)
	// OrgMemberRemove removes the member from the org
	OrgMemberRemove(ctx context.Context, orgID, memberID string) (*v1.OrgMembersResponse, error)
	// Certificates returns user's Certificates
	Certificates(ctx context.Context) (*v1.CertificatesResponse, error)
	// FccFRN returns Fcc FRN
	FccFRN(ctx context.Context, filerID string) (*v1.FccFrnResponse, error)
	// FccContact returns Fcc FRN Contact
	FccContact(ctx context.Context, frn string) (*v1.FccContactResponse, error)
	// RegisterOrg starts Org registration flow
	RegisterOrg(ctx context.Context, filerID string) (*v1.OrgResponse, error)
	// ApproveOrg approves Org registration
	ApproveOrg(ctx context.Context, token, code, action string) (*v1.OrgResponse, error)
	// ValidateOrg validates Org registration
	ValidateOrg(ctx context.Context, orgID string) (*v1.ValidateOrgResponse, error)
	// DeleteOrg deletes Org
	DeleteOrg(ctx context.Context, orgID string) error
	// GetOrgAPIKeys returns Org API keys
	GetOrgAPIKeys(ctx context.Context, orgID string) (*v1.GetOrgAPIKeysResponse, error)
	// CreateSubscription pays for Org validation
	CreateSubscription(ctx context.Context, req *v1.CreateSubscriptionRequest) (*v1.CreateSubscriptionResponse, error)
	// ListSubscriptions returns user's subscriptions
	ListSubscriptions(ctx context.Context) (*v1.ListSubscriptionsResponse, error)
	// ListSubscriptionsProducts returns list of available products
	ListSubscriptionsProducts(ctx context.Context) (*v1.SubscriptionsProductsResponse, error)
}

MartiniClient client interface

Jump to

Keyboard shortcuts

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