http

package
v6.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: BSD-4-Clause Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthAPI     = "AUTHENTICATION_API"
	ScalingoAPI = "SCALINGO_API"
	DBAPI       = "DATABASES_API"
)

Variables

View Source
var ErrOTPRequired = errors.New("OTP Required")

Functions

func IsOTPRequired

func IsOTPRequired(err error) bool

IsOTPRequired tests if the authentication backend return an OTP Required error

func IsRequestFailedError

func IsRequestFailedError(err error) bool

func NewRequestFailedError

func NewRequestFailedError(res *http.Response, req *APIRequest) error

Types

type APIConfig

type APIConfig struct {
	Prefix string
}

type APIError

type APIError struct {
	Error string `json:"error"`
}

type APIRequest

type APIRequest struct {
	NoAuth      bool
	URL         string
	Method      string
	Endpoint    string
	Expected    Statuses
	Params      interface{}
	HTTPRequest *http.Request
	Token       string // Directly use a Bearer token
	Username    string // Username for the OAuth generator (nil if you use a token)
	Password    string // Password for the OAuth generator
	OTP         string // OTP value
}

func (*APIRequest) BuildQueryFromParams

func (req *APIRequest) BuildQueryFromParams() (url.Values, error)

type APITokenGenerator

type APITokenGenerator struct {
	APIToken      string
	TokensService TokensService
	// contains filtered or unexported fields
}

func NewAPITokenGenerator

func NewAPITokenGenerator(tokensService TokensService, apiToken string) *APITokenGenerator

func (*APITokenGenerator) GetAccessToken

func (t *APITokenGenerator) GetAccessToken(ctx context.Context) (string, error)

type AdddonTokenExchanger

type AdddonTokenExchanger interface {
	AddonToken(ctx context.Context, app, addonID string) (string, error)
}

type AddonTokenGenerator

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

func (*AddonTokenGenerator) GetAccessToken

func (c *AddonTokenGenerator) GetAccessToken(ctx context.Context) (string, error)

type BadRequestError

type BadRequestError struct {
	ErrMessage string `json:"error"`
	Code       string `json:"code"`
}

func (BadRequestError) Error

func (err BadRequestError) Error() string

type Client

type Client interface {
	ResourceList(ctx context.Context, resource string, payload, data interface{}) error
	ResourceAdd(ctx context.Context, resource string, payload, data interface{}) error
	ResourceGet(ctx context.Context, resource, resourceID string, payload, data interface{}) error
	ResourceUpdate(ctx context.Context, resource, resourceID string, payload, data interface{}) error
	ResourceDelete(ctx context.Context, resource, resourceID string) error

	SubresourceList(ctx context.Context, resource, resourceID, subresource string, payload, data interface{}) error
	SubresourceAdd(ctx context.Context, resource, resourceID, subresource string, payload, data interface{}) error
	SubresourceGet(ctx context.Context, resource, resourceID, subresource, id string, payload, data interface{}) error
	SubresourceUpdate(rctx context.Context, esource, resourceID, subresource, id string, payload, data interface{}) error
	SubresourceDelete(ctx context.Context, resource, resourceID, subresource, id string) error
	DoRequest(ctx context.Context, req *APIRequest, data interface{}) error
	Do(context.Context, *APIRequest) (*http.Response, error)

	TokenGenerator() TokenGenerator
	IsAuthenticatedClient() bool
	BaseURL() string
	HTTPClient() *http.Client
}

func NewClient

func NewClient(api string, cfg ClientConfig) Client

type ClientConfig

type ClientConfig struct {
	UserAgent      string
	Timeout        time.Duration
	TLSConfig      *tls.Config
	APIConfig      APIConfig
	Endpoint       string
	TokenGenerator TokenGenerator
}

type ForbiddenError

type ForbiddenError struct {
	Err  string `json:"error"`
	Code string `json:"code"`
}

func (ForbiddenError) Error

func (err ForbiddenError) Error() string

type NotFoundError

type NotFoundError struct {
	Resource string `json:"resource"`
	Err      string `json:"error"`
}

func (NotFoundError) Error

func (err NotFoundError) Error() string

type PaymentRequiredError

type PaymentRequiredError struct {
	Name       string `json:"name"`
	ErrMessage string `json:"error"`
	URL        string `json:"url"`
}

func (PaymentRequiredError) Error

func (err PaymentRequiredError) Error() string

type RequestFailedError

type RequestFailedError struct {
	Code     int
	APIError error
	Req      *APIRequest
	Message  string
}

func (*RequestFailedError) Error

func (err *RequestFailedError) Error() string

func (*RequestFailedError) String

func (err *RequestFailedError) String() string

type Statuses

type Statuses []int

func (Statuses) Contains

func (statuses Statuses) Contains(status int) bool

type TokenGenerator

type TokenGenerator interface {
	GetAccessToken(context.Context) (string, error)
}

func NewAddonTokenGenerator

func NewAddonTokenGenerator(app, addon string, exchanger AdddonTokenExchanger) TokenGenerator

type TokensService

type TokensService interface {
	TokenExchange(ctx context.Context, token string) (string, error)
}

type TooManyRequestsError added in v6.2.0

type TooManyRequestsError struct {
	ErrMessage string `json:"error"`
	Code       string `json:"code"`
}

func (TooManyRequestsError) Error added in v6.2.0

func (err TooManyRequestsError) Error() string

type UnprocessableEntity

type UnprocessableEntity struct {
	Errors map[string][]string `json:"errors"`
}

func (UnprocessableEntity) Error

func (err UnprocessableEntity) Error() string

Directories

Path Synopsis
Package httpmock is a generated GoMock package.
Package httpmock is a generated GoMock package.
Package tokensservicemock is a generated GoMock package.
Package tokensservicemock is a generated GoMock package.

Jump to

Keyboard shortcuts

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