client

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

client package contains the primiteves to create a new http client for connecting to Mia-Platform Console using the connection options passed to it.

It also manage the authentication, renewal and re authentication if necessary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAuthProvider

func RegisterAuthProvider(ap AuthProviderCreator) error

Types

type APIClient

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

APIClient wrap an http.Client that can connect to Mia-Platform Console

func APIClientForConfig

func APIClientForConfig(config *Config) (*APIClient, error)

APIClientForConfig create a APIClient with config

func (*APIClient) Delete added in v0.8.0

func (c *APIClient) Delete() *Request

Delete return a new Request object for a DELETE http request

func (*APIClient) Get

func (c *APIClient) Get() *Request

Get return a new Request object for a GET http request

func (*APIClient) HTTPClient added in v0.6.1

func (c *APIClient) HTTPClient() *http.Client

func (*APIClient) Patch added in v0.11.0

func (c *APIClient) Patch() *Request

func (*APIClient) Post

func (c *APIClient) Post() *Request

Post return a new Request object for a POST http request

func (*APIClient) Put added in v0.13.0

func (c *APIClient) Put() *Request

Put return a new Request object for a Put http request

type AuthCacheReadWriter

type AuthCacheReadWriter interface {
	ReadJWTToken() *oauth2.Token
	WriteJWTToken(*oauth2.Token)
}

type AuthConfig

type AuthConfig struct {
	ClientID          string
	ClientSecret      string
	JWTKeyID          string
	JWTPrivateKeyData string
}

AuthConfig contains settings for settign up authentication for the http requests

type AuthProvider

type AuthProvider interface {
	// Wrap allow the AuthProvider to add authorization functionality on
	// a modified RoundTripper and to add the appropriate Authorization header to the request
	Wrap(http.RoundTripper) http.RoundTripper
}

type AuthProviderCreator

type AuthProviderCreator func(*Config, AuthCacheReadWriter, AuthConfig) AuthProvider

AuthProviderCreator is a function that return an AuthProvider

type Config

type Config struct {
	// Host must be a host string, a host:port pair, or a URL to the base of the server.
	// If a URL is given then the (optional) Path of that URL represents a prefix that must
	// be appended to all request URIs used to access the server. This allows a frontend
	// proxy to easily relocate all of the server endpoints.
	Host string

	// TLSClientConfig contains settings to enable transport layer security
	TLSClientConfig

	// UserAgent is an optional field that specifies the caller of this request.
	UserAgent string

	// Transport add a custom transport instead of creating a new one. Wrappers will be added to it
	Transport http.RoundTripper

	// AuthConfig contains settings for settign up authentication for the http requests
	AuthConfig

	// AuthCacheReadWriter provides access to authorization cache
	AuthCacheReadWriter

	// CompanyID contains the company id that can be used for filtering requests
	CompanyID string

	// ProjectID contains the project id that can be used for filtering requests
	ProjectID string

	// Environment contains the environment scope that can be used for filtering requests
	Environment string

	// The maximum length of time to wait before giving up on a server request. A value of zero means no timeout.
	Timeout time.Duration
}

Config holds the common attributes that can be passed to a client on initialization

type Interface

type Interface interface {
	Delete() *Request
	Get() *Request
	Post() *Request
	Patch() *Request
	HTTPClient() *http.Client
}

Interface captures the set of operations for interacting with REST apis

type Request

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

Request wrap the http.Request configuration providing functions for configure it in an easier and contained way

func NewRequest

func NewRequest(client *APIClient) *Request

NewRequest creates a new request helper object for calling Mia-Platform Console API

func (*Request) APIPath

func (r *Request) APIPath(apiPath string) *Request

APIPath set the apiPath for the request, if apiPath cannot be parse as a valid path an error can be found with the Error function. It will be ensured that the path will always end with /.

func (*Request) Body

func (r *Request) Body(bodyBytes []byte) *Request

Body set the body of the request if no error has been found in the request construction

func (*Request) Do

func (r *Request) Do(ctx context.Context) (*Response, error)

Do execute the http.Request in the provided context

func (*Request) Error

func (r *Request) Error() error

Error return any error encountered constructing the request, if any.

func (*Request) SetHeader

func (r *Request) SetHeader(key, value string) *Request

SetHeader add the passed value for the header key, if the key aldready exists, it will be removed

func (*Request) SetParam

func (r *Request) SetParam(key string, values ...string) *Request

SetParam set the HTTP query params key to value if no error has been found in the request construction

func (*Request) SetVerb

func (r *Request) SetVerb(verb string) *Request

SetVerb set the HTTP verb for the request

func (*Request) Stream added in v0.9.0

func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error)

Stream return directly the buffer of the response for streaming it

func (*Request) URL

func (r *Request) URL() *url.URL

URL return the url that will be used by the http.Request in this moment

type Response

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

Response wrap an http.Response and provide functions to operate safely on it

func (*Response) Error

func (r *Response) Error() error

Error return the error found in the response

func (*Response) ParseResponse

func (r *Response) ParseResponse(obj interface{}) error

ParseResponse will parse the underlying body inside the obj passed

func (*Response) RawRequest

func (r *Response) RawRequest() *http.Request

RawRequest return the original request if you need to access things not exposed by the other functions

func (*Response) StatusCode

func (r *Response) StatusCode() int

Error return the response status code

type ResponseError

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

ResponseError represent an error from an api call

func (*ResponseError) Error

func (r *ResponseError) Error() string

Error return the message of the api call error

type TLSClientConfig

type TLSClientConfig struct {
	// Server should be accessed without verifying the TLS certificate. For testing only.
	Insecure bool

	// Trusted root certificates for server
	CAFile string
}

TLSClientConfig contains settings to enable transport layer security

Jump to

Keyboard shortcuts

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