universal_client

package
v0.6.1-nightly.d39e3dd Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("Resource not found")

ErrNotFound is returned when an api call returns 404

View Source
var ErrTODO = errors.New("TODO: This feature is not implemented yet")

ErrTODO is returned when a feature is not yet implemented

Functions

func AddHeaders

func AddHeaders(q map[string]string) func(*http.Request)

func AddQuery

func AddQuery(q map[string]string) func(*http.Request)

AddQuery call back for adding url queries

func Do

func Do(r *http.Request) (*http.Response, error)

func Error

func Error(res *http.Response) error

Error dumps whole response plus body and return it as an error

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound returns nil if err is ErrNotFound

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is ErrNotFound

func IsTODO

func IsTODO(err error) bool

func JSON

func JSON(res *http.Response, o interface{}) error

func RunRequestKase

func RunRequestKase(t *testing.T, e environmet.Env, fn func(Client) error, kase ...Kase)

RunRequestKase this helps check if we are sending a correct request. This assumes fn will only perform a single API call, this ignores the response it only validates we are sending correct path/method/headers

func SetHeaders

func SetHeaders(q map[string]string) func(*http.Request)

Types

type Client

type Client struct {
	Env           environmet.Env
	Log           logr.Logger
	BeforeRequest func(*http.Request)
	Do            func(*http.Request) (*http.Response, error)
}

func (Client) Call

func (c Client) Call(method, url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func (Client) Delete

func (c Client) Delete(url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func (Client) Environment

func (c Client) Environment() environmet.Env

func (Client) Get

func (c Client) Get(url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func (Client) JSON

func (c Client) JSON(method, url string, body interface{}, fn ...func(*http.Request)) (*http.Response, error)

func (Client) Post

func (c Client) Post(url string, body io.Reader, fn ...func(*http.Request)) (*http.Response, error)

func (Client) PostJSON

func (c Client) PostJSON(url string, body interface{}, fn ...func(*http.Request)) (*http.Response, error)

func (Client) PutJSON

func (c Client) PutJSON(url string, body interface{}, fn ...func(*http.Request)) (*http.Response, error)

func (Client) Request

func (c Client) Request(method, url string, body io.Reader) (*http.Request, error)

type Kase

type Kase struct {
	Name     string
	Request  RequestKase
	Response *ResponseKase
}

Kase a single test case for an API call.

type RequestKase

type RequestKase struct {
	Path     string
	Method   string
	Headers  map[string]string
	Callback func(*testing.T, *http.Request)
}

type ResponseKase

type ResponseKase struct {
	Headers  map[string]string
	Body     string
	Callback func(*testing.T, *http.Response)
}

type UniversalApi

type UniversalApi interface {
	Get(ctx context.Context, apiID string) (*v1.APIDefinitionSpec, error)
	All(ctx context.Context) ([]v1.APIDefinitionSpec, error)
	Create(ctx context.Context, spec *v1.APIDefinitionSpec) error
	Update(ctx context.Context, def *v1.APIDefinitionSpec) error
	Delete(ctx context.Context, id string) error
}

type UniversalCertificate

type UniversalCertificate interface {
	All(ctx context.Context) ([]string, error)
	Upload(ctx context.Context, key []byte, crt []byte) (id string, err error)
	Delete(ctx context.Context, id string) error
	// Exists returns true if a certificate with id exists
	Exists(ctx context.Context, id string) bool
}

type UniversalClient

type UniversalClient interface {
	Environment() environmet.Env
	HotReload() error
	Api() UniversalApi
	SecurityPolicy() UniversalSecurityPolicy
	Certificate() UniversalCertificate
}

type UniversalSecurityPolicy

type UniversalSecurityPolicy interface {
	All(ctx context.Context) ([]tykv1alpha1.SecurityPolicySpec, error)
	// Get retruns the policy with the given id.
	Get(ctx context.Context, id string) (*tykv1alpha1.SecurityPolicySpec, error)
	// Create creates a new def and updates id and other fields. It is up to the
	// caller to update any fields that will be set after the policy has been
	// created for instance _id
	Create(ctx context.Context, def *tykv1alpha1.SecurityPolicySpec) error
	// Update this will update an existing policy
	Update(ctx context.Context, def *tykv1alpha1.SecurityPolicySpec) error
	//Delete deletes policy id id
	Delete(ctx context.Context, id string) error
}

Jump to

Keyboard shortcuts

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