keystone

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exhaust

func Exhaust(resp *http.Response)

Exhaust reads the response body until completion, and closes it.

func GetJSON

func GetJSON(client HTTPClient, headers http.Header, path *url.URL, data interface{}, allowUnknownFields bool) error

GetJSON is a convenience wrapper for Query(client, http.MethodGet, ...) TODO: Add a variant with pagination support

func GetPaginatedJSON added in v0.2.8

func GetPaginatedJSON(client HTTPClient, headers http.Header, path *url.URL, p Paginator, allowUnknownFields bool, maximum int) error

GetPaginatedJSON is a convenience wrapper for Query(client, http.MethodGet, ...)

func PostJSON

func PostJSON(client HTTPClient, headers http.Header, path *url.URL, data interface{}) (http.Header, []byte, error)

PostJSON is a convenience wrapper for Update(client, http.MethodPost, ...)

func PutJSON added in v0.3.2

func PutJSON(client HTTPClient, headers http.Header, path *url.URL, data interface{}) (http.Header, []byte, error)

PutJSON is a convenience wrapper for Update(client, http.MethodPut, ...)

func Query

func Query(client HTTPClient, method string, headers http.Header, path *url.URL, data interface{}, allowUnknownFields bool) (http.Header, error)

Query performs an HTTP request without payload, loads the result into `data`

func Update

func Update(client HTTPClient, method string, headers http.Header, path *url.URL, data interface{}) (http.Header, []byte, error)

Update performs an HTTP request with JSON payload, returns headers.

Types

type Backoff added in v0.3.7

type Backoff interface {
	KeepTrying(retries int) (bool, time.Duration)
}

Backoff controls retry policy

type DecodeError

type DecodeError struct {
	Type interface{}
	Data json.RawMessage
	Err  error
}

DecodeError returned when failed to decode json data

func (DecodeError) Error

func (d DecodeError) Error() string

Error implements error

func (DecodeError) Unwrap

func (d DecodeError) Unwrap() error

Unwrap implements errors.Unwrap

type ExponentialBackoff added in v0.3.7

type ExponentialBackoff struct {
	MaxRetries   int
	InitialDelay time.Duration
	DelayFactor  float64
	MaxDelay     time.Duration
}

ExponentialBackoff performs exponential backoff

func (ExponentialBackoff) KeepTrying added in v0.3.7

func (l ExponentialBackoff) KeepTrying(retries int) (bool, time.Duration)

KeepTrying implements Retry

type HTTPClient added in v0.3.3

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient encapsulates the funcionality required from *http.Client.

type Keystone

type Keystone struct {
	URL               *url.URL
	Username, Service string
}

Keystone manages Requests to the Identity Manager

func New

func New(keystoneURL string, username, service string) (*Keystone, error)

New Keystone client instance

func (*Keystone) Domains added in v0.5.1

func (k *Keystone) Domains(client HTTPClient, headers http.Header, enabled bool) ([]fiware.Domain, error)

func (*Keystone) Headers

func (o *Keystone) Headers(subservice, token string) http.Header

Headers returns the authentication headers for a subservice

func (*Keystone) Login

func (o *Keystone) Login(client HTTPClient, password string, retries Backoff) (string, string, error)

Login into the Context Broker, get a session token

func (*Keystone) Projects added in v0.2.6

func (k *Keystone) Projects(client HTTPClient, headers http.Header) ([]fiware.Project, error)

type LinealBackoff added in v0.3.7

type LinealBackoff struct {
	MaxRetries int
	Delay      time.Duration
}

LinealBackoff performs lineal backoff

func (LinealBackoff) KeepTrying added in v0.3.7

func (l LinealBackoff) KeepTrying(retries int) (bool, time.Duration)

KeepTrying implements Retry

type NetError

type NetError struct {
	Req         http.Request
	StatusCode  int
	RespHeaders http.Header
	Resp        []byte
	Err         error
}

NetError describes an error performing a request

func (NetError) Error

func (n NetError) Error() string

Error implements error

func (NetError) Unwrap

func (n NetError) Unwrap() error

Unwrap implements errors.Unwrap

type Paginator added in v0.2.8

type Paginator interface {
	Append(item json.RawMessage, allowUnknownFields bool) error
}

type SlicePaginator added in v0.4.3

type SlicePaginator[T any] struct {
	Slice []T
}

SlicePaginator is a generic type of Paginator based on a slice

func NewPaginator added in v0.4.3

func NewPaginator[T any](slice []T) *SlicePaginator[T]

NewPaginator creates a new paginator backed by the given slice

func (*SlicePaginator[T]) Append added in v0.4.3

func (s *SlicePaginator[T]) Append(raw json.RawMessage, allowUnknownFields bool) error

Append implements Paginator

Jump to

Keyboard shortcuts

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