client

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 9 Imported by: 9

Documentation

Index

Constants

View Source
const (
	DefaultUserAgent = "cloudit/1.0.0"
)

DefaultUserAgent is the default User-Agent string set in the request header.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClouditEngine

type ClouditEngine string

ClouditEngine is type of cloud service in cloudit

const (
	IAM ClouditEngine = "iam"
	ACE ClouditEngine = "ace"
	DNA ClouditEngine = "dna"
)

type RequestOpts

type RequestOpts struct {
	// JSONBody, if provided, will be encoded as JSON and used as the body of the HTTP request. The
	// content type of the request will default to "application/json" unless overridden by MoreHeaders.
	// It's an error to specify both a JSONBody and a RawBody.
	JSONBody interface{}
	// RawBody contains an io.ReadSeeker that will be consumed by the request directly. No content-type
	// will be set unless one is provided explicitly by MoreHeaders.
	RawBody io.ReadSeeker

	// JSONResponse, if provided, will be populated with the contents of the response body parsed as
	// JSON.
	JSONResponse interface{}
	// OkCodes contains a list of numeric HTTP status codes that should be interpreted as success. If
	// the response has a different code, an error will be returned.
	OkCodes []int

	// MoreHeaders specifies additional HTTP headers to be provide on the request. If a header is
	// provided with a blank value (""), that header will be *omitted* instead: use this to suppress
	// the default Accept header or an inferred Content-Type, for example.
	MoreHeaders map[string]string
}

RequestOpts customizes the behavior of the provider.Request() method.

type RestClient

type RestClient struct {
	// IdentityBase is the base URL used for a particular provider's identity
	// service - it will be used when issuing authenticatation requests. It
	// should point to the root resource of the identity service, not a specific
	// identity version.
	IdentityBase string

	// IdentityEndpoint is the identity endpoint. This may be a specific version
	// of the identity service. If this is the case, this endpoint is used rather
	// than querying versions first.
	IdentityEndpoint string

	// ClouditVersion
	ClouditVersion string

	// TenantId for Cloudit User
	TenantID string

	// TokenID is the ID of the most recently issued valid token.
	TokenID string

	// HTTPClient allows users to interject arbitrary http, https, or other transit behaviors.
	HTTPClient http.Client

	// UserAgent represents the User-Agent header in the HTTP request.
	UserAgent UserAgent

	// ReauthFunc is the function used to re-authenticate the user if the request
	// fails with a 401 HTTP response code. This a needed because there may be multiple
	// authentication functions for different Identity service versions.
	ReauthFunc func() error
}

func (*RestClient) AuthenticatedHeaders

func (client *RestClient) AuthenticatedHeaders() map[string]string

AuthenticatedHeaders returns a map of HTTP headers that are common for all authenticated service requests.

func (*RestClient) CreateRequestBaseURL

func (client *RestClient) CreateRequestBaseURL(engine ClouditEngine, parts ...string) string

func (*RestClient) Delete

func (client *RestClient) Delete(url string, opts *RequestOpts) (*http.Response, error)

func (*RestClient) Get

func (client *RestClient) Get(url string, JSONResponse *interface{}, opts *RequestOpts) (*http.Response, error)

func (*RestClient) Patch

func (client *RestClient) Patch(url string, JSONBody interface{}, JSONResponse *interface{}, opts *RequestOpts) (*http.Response, error)

func (*RestClient) Post

func (client *RestClient) Post(url string, body interface{}, JSONResponse *interface{}, opts *RequestOpts) (*http.Response, error)

func (*RestClient) Put

func (client *RestClient) Put(url string, body interface{}, JSONResponse *interface{}, opts *RequestOpts) (*http.Response, error)

func (*RestClient) Request

func (client *RestClient) Request(method, url string, options RequestOpts) (*http.Response, error)

Request performs an HTTP request using the RestClient's current HTTPClient. An authentication header will automatically be provided.

type Result

type Result struct {
	// Body is the payload of the HTTP response from the server. In most cases,
	// this will be the deserialized JSON structure.
	Body interface{}

	// Header contains the HTTP header structure from the original response.
	Header http.Header

	// Err is an error that occurred during the operation. It's deferred until
	// extraction to make it easier to chain the Extract call.
	Err error
}

func (Result) ExtractInto

func (r Result) ExtractInto(to interface{}) error

type UnexpectedResponseCodeError

type UnexpectedResponseCodeError struct {
	URL      string
	Method   string
	Expected []int
	Actual   int
	Body     []byte
}

UnexpectedResponseCodeError is returned by the Request method when a response code other than those listed in OkCodes is encountered.

func (*UnexpectedResponseCodeError) Error

func (err *UnexpectedResponseCodeError) Error() string

type UserAgent

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

UserAgent represents a User-Agent header.

func (*UserAgent) Join

func (ua *UserAgent) Join() string

Join concatenates all the user-defined User-Agend strings with the default

func (*UserAgent) Prepend

func (ua *UserAgent) Prepend(s ...string)

Prepend prepends a user-defined string to the default User-Agent string. Users may pass in one or more strings to prepend.

Directories

Path Synopsis
ace
nic
dna
iam

Jump to

Keyboard shortcuts

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