kong

package
v0.0.0-...-5bf65c3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound provides the error when a kong object can't be retrieved.
	ErrNotFound = errors.New("Failed to find the specified kong object")
)

Functions

This section is empty.

Types

type API

type API struct {
	ID                     string   `json:"id,omitempty"`
	Name                   string   `json:"name"`
	Hosts                  []string `json:"hosts,omitempty"`
	URIs                   []string `json:"uris,omitempty"`
	UpstreamURL            string   `json:"upstream_url"`
	StripURI               *bool    `json:"strip_uri,omitempty"`
	Methods                []string `json:"methods,omitempty"`
	PreserveHost           *bool    `json:"preserve_host,omitempty"`
	Retries                int64    `json:"retries,omitempty"`
	UpstreamConnectTimeout int64    `json:"upstream_connect_timeout,omitempty"`
	UpstreamSendTimeout    int64    `json:"upstream_send_timeout,omitempty"`
	UpstreamReadTimeout    int64    `json:"upstream_read_timeout,omitempty"`
	HTTPSOnly              *bool    `json:"https_only,omitempty"`
	HTTPIfTerminated       *bool    `json:"http_if_terminated,omitempty"`
}

API represents a subset of the kong API object which provide the properties this integration utilises.

type Client

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

Client provides a client for interacting with the kong API gateway application.

func NewClient

func NewClient(host string, port string, scheme string) *Client

NewClient creates a new instance of the kong client.

func (*Client) APIHasPlugin

func (c *Client) APIHasPlugin(apiName string, pluginName string) (bool, error)

APIHasPlugin lets us know whether the provided API has an instance of the provided plugin type.

func (*Client) AddPlugin

func (c *Client) AddPlugin(apiName string, plugin *Plugin) error

AddPlugin deals with adding the provided plugin definition to the specified API.

func (*Client) CreateAPI

func (c *Client) CreateAPI(api *API) (*API, error)

CreateAPI creates a new API in kong.

func (*Client) CreateTarget

func (c *Client) CreateTarget(upstreamNameOrId string, target *Target) (*Target, error)

CreateTarget deals with adding a new target to an existing upstream.

func (*Client) CreateUpstream

func (c *Client) CreateUpstream(upstream *Upstream) (*Upstream, error)

CreateUpstream deals with creating a new upstream object which can be referenced by an API as an upstream URL.

func (*Client) DeleteAPI

func (c *Client) DeleteAPI(nameOrID string) error

DeleteAPI deals with removing the specified API.

func (*Client) DeleteUpstream

func (c *Client) DeleteUpstream(nameOrId string) error

DeleteUpstream deals with removing the upstream object with the specified name or ID.

func (*Client) DisableTarget

func (c *Client) DisableTarget(upstreamNameOrId string, targetHost string) (*Target, error)

DisableTarget creates a new target with the specified host with a weight of 0.

func (*Client) EnableTarget

func (c *Client) EnableTarget(upstreamNameOrId string, targetHost string) (*Target, error)

EnableTarget creates a new upstream with the weight set to 10 so the load balancer takes the upstream target into account. (Upstreams use history for targets so the latest created target gets used)

func (*Client) GetAPI

func (c *Client) GetAPI(nameOrID string) (*API, error)

GetAPI retrieves an API by it's name or id.

func (*Client) GetPlugin

func (c *Client) GetPlugin(pluginID string) (*Plugin, error)

GetPlugin retrieves the plugin with the provided ID.

func (*Client) GetUpstream

func (c *Client) GetUpstream(nameOrId string) (*Upstream, error)

GetUpstream deals with retrieving the upstream with the specified name or ID.

func (*Client) ListApiPlugins

func (c *Client) ListApiPlugins(apiName string) (*PluginList, error)

func (*Client) ListTargets

func (c *Client) ListTargets(upstreamNameOrId string) (*TargetList, error)

ListTargets lists out all the targets for a specified upstream.

func (*Client) RemovePlugin

func (c *Client) RemovePlugin(apiName string, pluginName string) error

RemovePlugin deals with removing the specified plugin from the specified API. This handles managing the current issue with Kong that it's docs say you can use the plugin name in a DELETE request but it is not the case. This retrieves the list of plugins and finds the one with the provided plugin name and gets the ID that way to prevent us having to manage some sort of data store in this app.

func (*Client) UpdateAPI

func (c *Client) UpdateAPI(api *API) (*API, error)

UpdateAPI deals with updating the provided API assuming an API exists with the provided ID or name if it doesn't exist.

func (*Client) UpdatePlugin

func (c *Client) UpdatePlugin(apiName string, plugin *Plugin) error

UpdatePlugin deals with updating an existing plugin with a new definition. The provided plugin definition is expected to be without specific created instance information such as Created, ID and APIID. We must resolve the UUID from the API + plugin name combination as the kong endpoint for updating plugins do not support plugin names as the path parameter eventhough the docs say otherwise.

func (*Client) UpdateUpstream

func (c *Client) UpdateUpstream(upstream *Upstream) (*Upstream, error)

UpdateUpstream deals with updating the specified upstream.

type Plugin

type Plugin struct {
	ID      string                 `json:"id,omitempty"`
	APIID   string                 `json:"api_id,omitempty"`
	Name    string                 `json:"name"`
	Config  map[string]interface{} `json:"config"`
	Enabled *bool                  `json:"enabled,omitempty"`
	Created int                    `json:"created_at,omitempty"`
}

Plugin provides the data structure for a Plugin object to be attached to APIs.

type PluginList

type PluginList struct {
	Total int       `json:"total"`
	Data  []*Plugin `json:"data"`
}

PluginList represents the data structure returned from kong when making a request to retrieve a list of plugins.

type Target

type Target struct {
	ID         string `json:"id,omitempty"`
	Target     string `json:"target"`
	Weight     int    `json:"weight"`
	UpstreamID string `json:"upstream_id,omitempty"`
	Created    int    `json:"created_at,omitempty"`
}

Target provides the kong Target object to be used in upstreams.

type TargetList

type TargetList struct {
	Total int       `json:"total"`
	Data  []*Target `json:"data"`
}

TargetList provides the data structure for a list of upstream targets.

type Upstream

type Upstream struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name"`
}

Upstream provides a subset of the kong Upstream object. We only care about the name, maybe in the future it will be worth supporting the other properties.

Jump to

Keyboard shortcuts

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