kong

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 6 Imported by: 0

README

Library to manage KongAPI admin easily

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APICreateBody

type APICreateBody struct {
	Name        string `json:"name,omitempty"`
	RequestPath string `json:"request_path,omitempty"`
	Upstream    string `json:"upstream_url,omitempty"`
	Preserve    bool   `json:"preserve_host,omitempty"`
	StripPath   bool   `json:"strip_request_path,omitempty"`
}

APICreateBody Holds data for Create API requests

type APIListResponse

type APIListResponse struct {
	Data  []APIResponse `json:"data,omitempty"`
	Next  string        `json:"next,omitempty"`
	Total int           `json:"total,omitempty"`
}

APIListResponse holds responses when getting all apis ( GET schema://server:port/apis/ )

type APIRequest added in v1.0.0

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

APIRequest holds Kong < 0.14.x API Request data

type APIResponse

type APIResponse struct {
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	RequestPath string `json:"request_path,omitempty"`
	Upstream    string `json:"upstream_url,omitempty"`
	Preserve    bool   `json:"preserve_host,omitempty"`
	Created     int64  `json:"created_at,omitempty"`
	StripPath   bool   `json:"strip_request_path,omitempty"`
}

APIResponse Holds Kong < v0.14 API Response

type BasicKeyAuth

type BasicKeyAuth struct {
	Data  []KeyAuthData `json:"data,omitempty"`
	Total int           `json:"total,omitempty"`
}

BasicKeyAuth holds holds responses when getting all basic auths for a consumer

type Client

type Client struct {
	KongVersion int
	Url         string
	// contains filtered or unexported fields
}

Client Abstraction, implements all base operations against a Kong's server via a Requist instance

func NewClient

func NewClient(base string) *Client

NewClient returns a new Client given a Kong server base url

func NewClientFromElements

func NewClientFromElements(_schema, _host, _port, _user, _pass string) *Client

NewClientFromElements returns a new Client given a Kong server elements (schema, host, port)

func NewClientFromURL

func NewClientFromURL(base *url.URL) *Client

NewClientFromURL returns a new Client given a Kong server base url in URL type

func (*Client) CheckConnection

func (k *Client) CheckConnection() error

CheckConnection check for a valid connection against a Kong server

func (*Client) CheckStatus

func (k *Client) CheckStatus() (map[string]int, error)

CheckStatus returns some metrics from KongAPI server

func (*Client) CreateAPI

func (k *Client) CreateAPI(payload APICreateBody) (*APIResponse, error)

CreateAPI create an api

func (*Client) CreateConsumer

func (k *Client) CreateConsumer(payload ConsumersCreateBody) (*ConsumersResponse, error)

CreateConsumer create a consumer

func (*Client) CreatePluginOnApi

func (k *Client) CreatePluginOnApi(api string, payload PluginsCreateBody) (*PluginsResponse, error)

CreatePluginOnApi create a plugin on an api

func (*Client) CreatePluginOnService

func (k *Client) CreatePluginOnService(service string, payload PluginsCreateBody) (*PluginsResponse, error)

CreatePluginOnService create a plugin on a service

func (*Client) CreateRouteOnService

func (k *Client) CreateRouteOnService(service string, payload RouteCreateBody) (*RouteResponse, error)

CreateRouteOnService creates a route on a given service

func (*Client) CreateService

func (k *Client) CreateService(payload ServiceCreateBody) (*ServiceResponse, error)

CreateService create a service

func (*Client) DeleteAPI

func (k *Client) DeleteAPI(api string) error

DeleteAPI delete a given api

func (*Client) DeleteConsumer

func (k *Client) DeleteConsumer(consumer string) error

DeleteConsumer deletes a given consumer

func (*Client) DeleteConsumerAcl added in v0.9.0

func (k *Client) DeleteConsumerAcl(consumer, group string) error

DeleteConsumerAcl removes a group from a consumer

func (*Client) DeleteConsumerKeyAuth added in v0.8.2

func (k *Client) DeleteConsumerKeyAuth(consumer, apikey string) error

DeleteConsumerKeyAuth remove basic auth key for a consumer

func (*Client) DeletePluginFromApi added in v0.9.2

func (k *Client) DeletePluginFromApi(api, plugin string) error

DeletePluginFromApi delete a plugin from an api

func (*Client) DeletePluginFromService added in v0.9.2

func (k *Client) DeletePluginFromService(service, plugin string) error

DeletePluginFromService delete a plugin from a service

func (*Client) DeleteRoute

func (k *Client) DeleteRoute(route string) error

DeleteRoute deletes a given route

func (*Client) DeleteRouteForService added in v0.8.0

func (k *Client) DeleteRouteForService(service, route string) error

DeleteRouteForService deletes a given route from a service

func (*Client) DeleteService

func (k *Client) DeleteService(service string) error

DeleteService deletes a given service

func (*Client) ExistAPI

func (k *Client) ExistAPI(api string) bool

ExistAPI checks if given api exist

func (*Client) ExistConsumer

func (k *Client) ExistConsumer(consumer string) bool

ExistConsumer checks if given consumer exist

func (*Client) ExistService added in v0.9.5

func (k *Client) ExistService(service string) bool

ExistService checks if a given services exists

func (*Client) GetConsumerByKey added in v0.9.0

func (k *Client) GetConsumerByKey(key string) (*ConsumersResponse, error)

GetConsumerByKey returns a consumer from its basic auth apikey

func (*Client) GetConsumerKeyAuth

func (k *Client) GetConsumerKeyAuth(consumer string) (map[string]KeyAuthData, error)

GetConsumerKeyAuth return all basic auth of a consumer

func (*Client) ListAPIs

func (k *Client) ListAPIs(api string) (map[string]APIResponse, error)

ListAPIs returns all apis if api param is empty or info for a given api

func (*Client) ListApiPlugins added in v1.0.1

func (k *Client) ListApiPlugins(api string) (map[string]PluginsResponse, error)

ListApiPlugins returns plugins for a given api

func (*Client) ListConsumer

func (k *Client) ListConsumer(consumer string) (map[string]ConsumersResponse, error)

ListConsumer returns all consumers if consumer param is empty or info for a given consumer

func (*Client) ListRoutes added in v0.9.2

func (k *Client) ListRoutes(route string) (map[string]RouteResponse, error)

ListRoutes returns all routes if service param is empty or info for a given route

func (*Client) ListServicePlugins added in v1.0.1

func (k *Client) ListServicePlugins(service string) (map[string]PluginsResponse, error)

ListServicePlugins returns plugins for a given service

func (*Client) ListServiceRoutes

func (k *Client) ListServiceRoutes(service string) (map[string]RouteResponse, error)

ListServiceRoutes returns all routes of a given service

func (*Client) ListServices

func (k *Client) ListServices(service string) (map[string]ServiceResponse, error)

ListServices returns all services if service param is empty or info for a given service

func (*Client) NewConsumerKeyAuth added in v0.9.2

func (k *Client) NewConsumerKeyAuth(consumer string) error

NewConsumerKeyAuth create a new basic auth key for a consumer

func (*Client) NewFromURL

func (k *Client) NewFromURL(base *url.URL) *Client

NewFromURL return a copy of Client changing just a base url

func (*Client) PurgeAPIs added in v1.0.1

func (k *Client) PurgeAPIs() error

PurgeAPIs flush all apis from Kong server

func (*Client) PurgeConsumers added in v1.0.1

func (k *Client) PurgeConsumers() error

PurgeConsumers flush all consumers from Kong server

func (*Client) PurgeServices added in v1.0.3

func (k *Client) PurgeServices() error

PurgeConsumers flush all consumers from Kong server

func (*Client) SetBasicAuth

func (k *Client) SetBasicAuth(username, password string)

SetBasicAuth update user and pass

func (*Client) SetConsumerAcl

func (k *Client) SetConsumerAcl(consumer, group string) error

SetConsumerAcl assign a group to a consumer

func (*Client) SetConsumerKeyAuth

func (k *Client) SetConsumerKeyAuth(consumer, apikey string) error

SetConsumerKeyAuth set a key for a consumer

func (*Client) StatusCode

func (k *Client) StatusCode() int

StatusCode returns result code from last request

func (*Client) UpdateAPI

func (k *Client) UpdateAPI(api string, payload APICreateBody) (*APIResponse, error)

UpdateAPI update a given api

func (*Client) UpdateConsumer

func (k *Client) UpdateConsumer(consumer string, payload ConsumersCreateBody) (*ConsumersResponse, error)

UpdateConsumer update a given consumer

func (*Client) UpdateRoute

func (k *Client) UpdateRoute(route string, payload RouteCreateBody) (*RouteResponse, error)

UpdateRoute updates a given route

func (*Client) UpdateRouteForService added in v0.8.0

func (k *Client) UpdateRouteForService(service, route string, payload RouteCreateBody) (*RouteResponse, error)

UpdateRouteForService updates a given route on a service

func (*Client) UpdateService

func (k *Client) UpdateService(service string, payload ServiceCreateBody) (*ServiceResponse, error)

UpdateService updates a given service

type ClusterResponse

type ClusterResponse struct {
	Hostname      string `json:"hostname,omitempty"`
	LuaVersion    string `json:"lua_version,omitempty"`
	Configuration struct {
		AdminIP                string      `json:"admin_ip,omitempty"`
		AdminListen            interface{} `json:"admin_listen,omitempty"`
		AdminPort              int         `json:"admin_port,omitempty"`
		AnonymousReports       bool        `json:"anonymous_reports,omitempty"`
		CassandraConsistency   string      `json:"cassandra_consistency,omitempty"`
		CassandraContactPoints []string    `json:"cassandra_contact_points,omitempty"`
		CassandraDataCenters   []string    `json:"cassandra_data_centers,omitempty"`
		CassandraKeyspace      string      `json:"cassandra_keyspace,omitempty"`
		CassandraPort          int         `json:"cassandra_port,omitempty"`
		CassandraReplFactor    int         `json:"cassandra_repl_factor,omitempty"`
		CassandraReplStrategy  string      `json:"cassandra_repl_strategy,omitempty"`
		CassandraSsl           bool        `json:"cassandra_ssl,omitempty"`
		CassandraSslVerify     bool        `json:"cassandra_ssl_verify,omitempty"`
		CassandraTimeout       int         `json:"cassandra_timeout,omitempty"`
		CassandraUsername      string      `json:"cassandra_username,omitempty"`
		ClusterListen          interface{} `json:"cluster_listen,omitempty"`
		ClusterListenRPC       string      `json:"cluster_listen_rpc,omitempty"`
		ClusterProfile         string      `json:"cluster_profile,omitempty"`
		ClusterTTLOnFailure    int         `json:"cluster_ttl_on_failure,omitempty"`
		Database               string      `json:"database,omitempty"`
		Dnsmasq                bool        `json:"dnsmasq,omitempty"`
		DnsmasqPid             string      `json:"dnsmasq_pid,omitempty"`
		DnsmasqPort            int         `json:"dnsmasq_port,omitempty"`
		KongConf               string      `json:"kong_conf,omitempty"`
		LogLevel               string      `json:"log_level,omitempty"`
		LuaCodeCache           string      `json:"lua_code_cache,omitempty"`
		LuaPackageCpath        string      `json:"lua_package_cpath,omitempty"`
		LuaPackagePath         string      `json:"lua_package_path,omitempty"`
		LuaSslVerifyDepth      int         `json:"lua_ssl_verify_depth,omitempty"`
		MemCacheSize           string      `json:"mem_cache_size,omitempty"`
		NginxAccLogs           string      `json:"nginx_acc_logs,omitempty"`
		NginxConf              string      `json:"nginx_conf,omitempty"`
		NginxDaemon            string      `json:"nginx_daemon,omitempty"`
		NginxErrLogs           string      `json:"nginx_err_logs,omitempty"`
		NginxKongConf          string      `json:"nginx_kong_conf,omitempty"`
		NginxOptimizations     bool        `json:"nginx_optimizations,omitempty"`
		NginxPid               string      `json:"nginx_pid,omitempty"`
		NginxWorkerProcesses   string      `json:"nginx_worker_processes,omitempty"`
		PgDatabase             string      `json:"pg_database,omitempty"`
		PgHost                 string      `json:"pg_host,omitempty"`
		PgPassword             string      `json:"pg_password,omitempty"`
		PgPort                 int         `json:"pg_port,omitempty"`
		PgSsl                  bool        `json:"pg_ssl,omitempty"`
		PgSslVerify            bool        `json:"pg_ssl_verify,omitempty"`
		PgUser                 string      `json:"pg_user,omitempty"`
		Plugins                interface{} `json:"plugins,omitempty"`
		Prefix                 string      `json:"prefix,omitempty"`
		ProxyIP                string      `json:"proxy_ip,omitempty"`
		ProxyListen            interface{} `json:"proxy_listen,omitempty"`
		ProxyListenSsl         interface{} `json:"proxy_listen_ssl,omitempty"`
		ProxyPort              int         `json:"proxy_port,omitempty"`
		ProxySslIP             string      `json:"proxy_ssl_ip,omitempty"`
		ProxySslPort           int         `json:"proxy_ssl_port,omitempty"`
		SerfEvent              string      `json:"serf_event,omitempty"`
		SerfLog                string      `json:"serf_log,omitempty"`
		SerfNodeID             string      `json:"serf_node_id,omitempty"`
		SerfPath               string      `json:"serf_path,omitempty"`
		SerfPid                string      `json:"serf_pid,omitempty"`
		Ssl                    bool        `json:"ssl,omitempty"`
		SslCert                string      `json:"ssl_cert,omitempty"`
		SslCertCsrDefault      string      `json:"ssl_cert_csr_default,omitempty"`
		SslCertDefault         string      `json:"ssl_cert_default,omitempty"`
		SslCertKey             string      `json:"ssl_cert_key,omitempty"`
		SslCertKeyDefault      string      `json:"ssl_cert_key_default,omitempty"`
	} `json:"configuration,omitempty"`
	Plugins struct {
		AvailableOnServer interface{} `json:"available_on_server,omitempty"`
		EnabledInCluster  []string    `json:"enabled_in_cluster,omitempty"`
	} `json:"plugins,omitempty"`
	Tagline string `json:"tagline,omitempty"`
	Timers  struct {
		Pending int `json:"pending,omitempty"`
		Running int `json:"running,omitempty"`
	} `json:"timers,omitempty"`
	Version string `json:"version,omitempty"`
}

ClusterResponse holds all data for the endpoint / (root)

type ClusterStatus added in v1.0.0

type ClusterStatus struct {
	Database struct {
		Reachable bool `json:"reachable,omitempty"`
	} `json:"database,omitempty"`
	Server struct {
		ConnectionsWriting  int `json:"connections_writing,omitempty"`
		TotalRequests       int `json:"total_requests,omitempty"`
		ConnectionsHandled  int `json:"connections_handled,omitempty"`
		ConnectionsAccepted int `json:"connections_accepted,omitempty"`
		ConnectionsReading  int `json:"connections_reading,omitempty"`
		ConnectionsActive   int `json:"connections_active,omitempty"`
		ConnectionsWaiting  int `json:"connections_waiting,omitempty"`
	} `json:"server,omitempty"`
}

ClusterStatus holds all data for the endpoint / (root) on Kong servers (> 0.8.3)

type ClusterStatusOld

type ClusterStatusOld struct {
	Server struct {
		ConnectionsHandled  int `json:"connections_handled"`
		ConnectionsReading  int `json:"connections_reading"`
		ConnectionsActive   int `json:"connections_active"`
		TotalRequests       int `json:"total_requests"`
		ConnectionsAccepted int `json:"connections_accepted"`
		ConnectionsWriting  int `json:"connections_writing"`
		ConnectionsWaiting  int `json:"connections_waiting"`
	} `json:"server"`
	Database struct {
		Oauth2Credentials           int `json:"oauth2_credentials"`
		JwtSecrets                  int `json:"jwt_secrets"`
		ResponseRatelimitingMetrics int `json:"response_ratelimiting_metrics"`
		KeyauthCredentials          int `json:"keyauth_credentials"`
		Oauth2AuthorizationCodes    int `json:"oauth2_authorization_codes"`
		Acls                        int `json:"acls"`
		Apis                        int `json:"apis"`
		BasicauthCredentials        int `json:"basicauth_credentials"`
		Consumers                   int `json:"consumers"`
		RatelimitingMetrics         int `json:"ratelimiting_metrics"`
		Oauth2Tokens                int `json:"oauth2_tokens"`
		Nodes                       int `json:"nodes"`
		HmacauthCredentials         int `json:"hmacauth_credentials"`
		Plugins                     int `json:"plugins"`
	} `json:"database"`
}

ClusterStatusOld holds all data for the endpoint / (root) on Kong servers (<= 0.8.3)

type ConsumerAclBody

type ConsumerAclBody struct {
	Group string `json:"group,omitempty"`
}

ConsumerAclBody used to set acl for a consumer

type ConsumerAclResponse

type ConsumerAclResponse struct {
	ID         string `json:"id,omitempty"`
	Group      string `json:"group,omitempty"`
	Created    int64  `json:"created_at,omitempty"`
	ConsumerId int64  `json:"consumer_id,omitempty"`
}

ConsumerAclResponse holds responses for a request to set acl to a consumer

type ConsumersCreateBody

type ConsumersCreateBody struct {
	Username string   `json:"username,omitempty"`
	CustomID string   `json:"custom_id,omitempty"`
	Tags     []string `json:"tags,omitempty"`
}

ConsumersCreateBody holds request body for POST/PUT/PATCH schema://server:port/consumers/

type ConsumersListResponse

type ConsumersListResponse struct {
	Data  []ConsumersResponse `json:"data,omitempty"`
	Next  string              `json:"next,omitempty"`
	Total int                 `json:"total,omitempty"`
}

ConsumersListResponse holds responses when getting all consumers ( GET schema://server:port/consumers/ )

type ConsumersResponse

type ConsumersResponse struct {
	ID        string   `json:"id,omitempty"`
	Username  string   `json:"username,omitempty"`
	CreatedAt int64    `json:"created_at,omitempty"`
	CustomID  string   `json:"custom_id"`
	Tags      []string `json:"tags"`
}

ConsumersResponse holds body response for POST/PUT/PATCH schema://server:port/consumers/

type EnabledPluginsResponse

type EnabledPluginsResponse struct {
	EnabledPlugins []string `json:"enabled_plugins"`
}

EnabledPluginsResponse used when request the plugins enabled on a Kong server

type FailureMessage

type FailureMessage struct {
	Message string `json:"message,omitempty"`
}

FailureMessage all failed request match with this datatype

type KeyAuthData

type KeyAuthData struct {
	CreatedAt  int64  `json:"created_at,omitempty"`
	ConsumerID string `json:"consumer_id,omitempty"`
	Key        string `json:"key,omitempty"`
	ID         string `json:"id,omitempty"`
}

KeyAuthData holds response when getting basic auth for a consumer

type PluginsCreateBody

type PluginsCreateBody struct {
	Name    string      `json:"name,omitempty"`
	Config  interface{} `json:"config,omitempty"`
	Enabled bool        `json:"enabled,omitempty"`
}

PluginsCreateBody used to send a request body for create plugins

type PluginsListResponse

type PluginsListResponse struct {
	Data  []PluginsResponse `json:"data,omitempty"`
	Next  string            `json:"next,omitempty"`
	Total int               `json:"total,omitempty"`
}

PluginsListResponse holds responses when getting all plugins of a consumers/apis/services or routes

type PluginsResponse

type PluginsResponse struct {
	ID        string      `json:"id"`
	Name      string      `json:"name,omitempty"`
	Enabled   bool        `json:"enabled,omitempty"`
	Created   int64       `json:"created_at,omitempty"`
	Config    interface{} `json:"config,omitempty"`
	Api       interface{} `json:"api_id,omitempty"`
	Service   interface{} `json:"service,omitempty"`
	Consumer  interface{} `json:"consumer,omitempty"`
	Route     interface{} `json:"route,omitempty"`
	Protocols interface{} `json:"protocols,omitempty"`
	Tags      interface{} `json:"tags,omitempty"`
}

PluginsResponse holds responses for a request of create or update a plugin

type RouteCreateBody

type RouteCreateBody struct {
	Name                    string   `json:"name,omitempty"`
	Protocols               []string `json:"protocols,omitempty"`
	Methods                 []string `json:"methods,omitempty"`
	Hosts                   []string `json:"hosts,omitempty"`
	Paths                   []string `json:"paths,omitempty"`
	HTTPSRedirectStatusCode int      `json:"https_redirect_status_code,omitempty"`
	RegexPriority           int      `json:"regex_priority,omitempty"`
	StripPath               bool     `json:"strip_path,omitempty"`
	PreserveHost            bool     `json:"preserve_host,omitempty"`
	Tags                    []string `json:"tags,omitempty"`
}

RouteCreateBody ...

type RouteListResponse

type RouteListResponse struct {
	Data []RouteResponse `json:"data"`
	Next string          `json:"next"`
}

RouteListResponse holds responses when getting all routes ( GET schema://server:port/routes/

or schema://server:port/services/{{SERVICE}}/routes/ )

type RouteResponse

type RouteResponse struct {
	ID                      string      `json:"id,omitempty"`
	CreatedAt               int         `json:"created_at,omitempty"`
	UpdatedAt               int         `json:"updated_at,omitempty"`
	Name                    string      `json:"name,omitempty"`
	Protocols               []string    `json:"protocols,omitempty"`
	Methods                 []string    `json:"methods,omitempty"`
	Hosts                   []string    `json:"hosts,omitempty"`
	Paths                   []string    `json:"paths,omitempty"`
	Headers                 interface{} `json:"headers,omitempty"`
	HTTPSRedirectStatusCode int         `json:"https_redirect_status_code,omitempty"`
	RegexPriority           int         `json:"regex_priority,omitempty"`
	StripPath               bool        `json:"strip_path,omitempty"`
	PreserveHost            bool        `json:"preserve_host,omitempty"`
	Tags                    []string    `json:"tags,omitempty"`
	Service                 struct {
		ID string `json:"id,omitempty"`
	} `json:"service,omitempty"`
}

RouteResponse ...

type ServiceCreateBody

type ServiceCreateBody struct {
	Name           string      `json:"name,omitempty"`
	Url            string      `json:"url,omitempty"`
	Retries        int         `json:"retries,omitempty"`
	Protocol       string      `json:"protocol,omitempty"`
	Host           string      `json:"host,omitempty"`
	Port           int         `json:"port,omitempty"`
	Path           string      `json:"path,omitempty"`
	ConnectTimeout int         `json:"connect_timeout,omitempty"`
	WriteTimeout   int         `json:"write_timeout,omitempty"`
	ReadTimeout    int         `json:"read_timeout,omitempty"`
	Tags           interface{} `json:"tags,omitempty"`
}

ServiceCreateBody used for creation of services

type ServiceListResponse

type ServiceListResponse struct {
	Data  []ServiceResponse `json:"data"`
	Next  string            `json:"next"`
	Total int               `json:"total"`
}

ServiceListResponse holds responses when getting all services ( GET schema://server:port/services/ )

type ServiceResponse

type ServiceResponse struct {
	ID                string   `json:"id,omitempty"`
	Name              string   `json:"name,omitempty"`
	CreatedAt         int      `json:"created_at,omitempty"`
	UpdatedAt         int      `json:"updated_at,omitempty"`
	Retries           int      `json:"retries,omitempty"`
	Protocol          string   `json:"protocol,omitempty"`
	Host              string   `json:"host,omitempty"`
	Port              int      `json:"port,omitempty"`
	Path              string   `json:"path,omitempty"`
	ConnectTimeout    int      `json:"connect_timeout"`
	WriteTimeout      int      `json:"write_timeout,omitempty"`
	ReadTimeout       int      `json:"read_timeout,omitempty"`
	Tags              []string `json:"tags,omitempty"`
	ClientCertificate struct {
		ID string `json:"id,omitempty"`
	} `json:"client_certificate,omitempty"`
}

ServiceResponse holds responses for Create or Update a services

Jump to

Keyboard shortcuts

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