universal_client

package
v0.6.1-nightly.3b89c61 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: MPL-2.0 Imports: 17 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 CreateOrUpdateWebhook

func CreateOrUpdateWebhook(c UniversalClient, spec *tykv1alpha1.WebhookSpec) error

func Do

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

func DoReload

func DoReload(c UniversalClient, fn func(u UniversalClient) error) error

DoReload call HotReload if fn returns nil

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(apiID string) (*v1.APIDefinitionSpec, error)
	All() ([]v1.APIDefinitionSpec, error)
	Create(spec *v1.APIDefinitionSpec) error
	Update(def *v1.APIDefinitionSpec) error
	Delete(id string) error
}

type UniversalCertificate

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

type UniversalClient

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

type UniversalOrganization

type UniversalOrganization interface {
	GetID() string
}

type UniversalSecurityPolicy

type UniversalSecurityPolicy interface {
	All() ([]tykv1alpha1.SecurityPolicySpec, error)
	// Get retruns the policy with the given id.
	Get(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(def *tykv1alpha1.SecurityPolicySpec) error
	// Update this will update an existing policy
	Update(def *tykv1alpha1.SecurityPolicySpec) error
	//Delete deletes policy id id
	Delete(id string) error
}

type UniversalWebhook

type UniversalWebhook interface {
	All() ([]tykv1alpha1.WebhookSpec, error)
	Get(id string) (*tykv1alpha1.WebhookSpec, error)
	Create(*tykv1alpha1.WebhookSpec) error
	Update(def *tykv1alpha1.WebhookSpec) error
	Delete(id string) error
}

Jump to

Keyboard shortcuts

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