gokong

package module
v6.0.3 Latest Latest
Warning

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

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

README

Build Status

GoKong

A kong go client fully tested with no mocks!!

IMPORTANT

GoKong has now been updated to support kong v1.0.0. This is a breaking change release is not compatible with any versions <1.0.0. The good news is the guys over at Kong have stated that they are not going to make any breaking changes now (following semver). If you need a version of gokong that supports Kong <1.0.0 then use the branch kong-pre-1.0.0.

GoKong

GoKong is a easy to use api client for kong. The difference with the gokong library is all of its tests are written against a real running kong running inside a docker container, yep that's right you won't see a horrible mock anywhere!!

Supported Kong Versions

As per travis build:

KONG_VERSION=1.0.0

Importing

To add gokong via go get:

go get github.com/kevholditch/gokong

Usage

Import gokong

import (
  "github.com/kevholditch/gokong"
)

To create a default config for use with the client:

config := gokong.NewDefaultConfig()

NewDefaultConfig creates a config with the host address set to the value of the env variable KONG_ADMIN_ADDR. If the env variable is not set then the address is defaulted to http://localhost:8001.

There are a number of options you can set via config either by explicitly setting them when creating a config instance or by simply using the NewDefaultConfig method and using env variables. Below is a table of the fields, the env variables that can be used to set them and their default values if you do not provide one via an env variable:

Config property Env variable Default if not set Use
HostAddress KONG_ADMIN_ADDR http://localhost:8001 The url of the kong admin api
Username KONG_ADMIN_USERNAME not set Username for the kong admin api
Password KONG_ADMIN_PASSWORD not set Password for the kong admin api
InsecureSkipVerify TLS_SKIP_VERIFY false Whether to skip tls certificate verification for the kong api when using https
ApiKey KONG_API_KEY not set The api key you have used to lock down the kong admin api (via key-auth plugin)
AdminToken KONG_ADMIN_TOKEN not set The api key you have used to lock down the kong admin api (Enterprise Edition )

You can of course create your own config with the address set to whatever you want:

config := gokong.Config{HostAddress:"http://localhost:1234"}

Also you can apply Username and Password for admin-api Basic Auth:

config := gokong.Config{HostAddress:"http://localhost:1234",Username:"adminuser",Password:"yoursecret"}

If you need to ignore TLS verification, you can set InsecureSkipVerify:

config := gokong.Config{InsecureSkipVerify: true}

This might be needed if your Kong installation is using a self-signed certificate, or if you are proxying to the Kong admin port.

Getting the status of the kong server:

kongClient := gokong.NewClient(gokong.NewDefaultConfig())
status, err := kongClient.Status().Get()

Gokong is fluent so we can combine the above two lines into one:

status, err := gokong.NewClient(gokong.NewDefaultConfig()).Status().Get()

Consumers

Create a new Consumer (for more information on the Consumer Fields see the Kong documentation):

consumerRequest := &gokong.ConsumerRequest{
  Username: "User1",
  CustomId: "SomeId",
}

consumer, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().Create(consumerRequest)

Get a Consumer by id:

consumer, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().GetById("e8ccbf13-a662-45be-9b6a-b549cc739c18")

Get a Consumer by username:

consumer, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().GetByUsername("User1")

List all Consumers:

consumers, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().List()

Delete a Consumer by id:

err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().DeleteById("7c8741b7-3cf5-4d90-8674-b34153efbcd6")

Delete a Consumer by username:

err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().DeleteByUsername("User1")

Update a Consumer by id:

consumerRequest := &gokong.ConsumerRequest{
  Username: "User1",
  CustomId: "SomeId",
}

updatedConsumer, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().UpdateById("44a37c3d-a252-4968-ab55-58c41b0289c2", consumerRequest)

Update a Consumer by username:

consumerRequest := &gokong.ConsumerRequest{
  Username: "User2",
  CustomId: "SomeId",
}

updatedConsumer, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().UpdateByUsername("User2", consumerRequest)

Plugins

Create a new Plugin to be applied to all Services, Routes and Consumers do not set ServiceId, RouteId or ConsumerId. Not all plugins can be configured in this way (for more information on the Plugin Fields see the Kong documentation):

pluginRequest := &gokong.PluginRequest{
  Name: "request-size-limiting",
  Config: map[string]interface{}{
    "allowed_payload_size": 128,
  },
}

createdPlugin, err := gokong.NewClient(gokong.NewDefaultConfig()).Plugins().Create(pluginRequest)

Create a new Plugin for a single Consumer (only set ConsumerId), Not all plugins can be configured in this way (for more information on the Plugin Fields see the Kong documentation):

client := gokong.NewClient(gokong.NewDefaultConfig())

consumerRequest := &gokong.ConsumerRequest{
  Username: "User1",
  CustomId: "test",
}

createdConsumer, err := client.Consumers().Create(consumerRequest)

pluginRequest := &gokong.PluginRequest{
  Name: "response-ratelimiting",
  ConsumerId: createdConsumer.Id,
  Config: map[string]interface{}{
    "limits.sms.minute": 20,
  },
}

createdPlugin, err := client.Plugins().Create(pluginRequest)

Create a new Plugin for a single Service (only set ServiceId), Not all plugins can be configured in this way (for more information on the Plugin Fields see the Kong documentation):

client := gokong.NewClient(gokong.NewDefaultConfig())

serviceRequest := &gokong.ServiceRequest{
  Name:     String("service"),
  Protocol: String("http"),
  Host:     String("example.com"),
}

createdService, err := client.Services().Create(serviceRequest)

pluginRequest := &gokong.PluginRequest{
  Name: "response-ratelimiting",
  ServiceId: gokong.ToId(*createdService.Id),
  Config: map[string]interface{}{
    "limits.sms.minute": 20,
  },
}

createdPlugin, err := client.Plugins().Create(pluginRequest)

Create a new Plugin for a single Route (only set RouteId), Not all plugins can be configured in this way (for more information on the Plugin Fields see the Kong documentation):

client := gokong.NewClient(gokong.NewDefaultConfig())

serviceRequest := &gokong.ServiceRequest{
  Name:     String("service"),
  Protocol: String("http"),
  Host:     String("example.com"),
}

createdService, err := client.Services().Create(serviceRequest)

routeRequest := &gokong.RouteRequest{
  Protocols:    StringSlice([]string{"http"}),
  Methods:      StringSlice([]string{"GET"}),
  Hosts:        StringSlice([]string{"example.com"}),
  Paths:        StringSlice([]string{"/"}),
  StripPath:    Bool(true),
  PreserveHost: Bool(false),
  Service:      &gokong.RouteServiceObject{Id: *createdService.Id},
}

createdRoute, err := client.Routes().Create(routeRequest)

pluginRequest := &gokong.PluginRequest{
  Name: "response-ratelimiting",
  RouteId: gokong.ToId(*createdRoute.Id),
  Config: map[string]interface{}{
    "limits.sms.minute": 20,
  },
}

createdPlugin, err := client.Plugins().Create(pluginRequest)

Get a plugin by id:

plugin, err := gokong.NewClient(gokong.NewDefaultConfig()).Plugins().GetById("04bda233-d035-4b8a-8cf2-a53f3dd990f3")

List all plugins:

plugins, err := gokong.NewClient(gokong.NewDefaultConfig()).Plugins().List(&PluginQueryString{})

Delete a plugin by id:

err := gokong.NewClient(gokong.NewDefaultConfig()).Plugins().DeleteById("f2bbbab8-3e6f-4d9d-bada-d486600b3b4c")

Update a plugin by id:

updatePluginRequest := &gokong.PluginRequest{
  Name:       "response-ratelimiting",
  ConsumerId: createdConsumer.Id,
  Config: map[string]interface{}{
    "limits.sms.minute": 20,
  },
}

updatedPlugin, err := gokong.NewClient(gokong.NewDefaultConfig()).Plugins().UpdateById("70692eed-2293-486d-b992-db44a6459360", updatePluginRequest)

Configure a plugin for a Consumer

To configure a plugin for a consumer you can use the CreatePluginConfig, GetPluginConfig and DeletePluginConfig methods on the Consumers endpoint. Some plugins require configuration for a consumer for example the [jwt plugin[(https://getkong.org/plugins/jwt/#create-a-jwt-credential).

Create a plugin config for a consumer:

createdPluginConfig, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().CreatePluginConfig("f6539872-d8c5-4d6c-a2f2-923760329e4e", "jwt", "{\"key\": \"a36c3049b36249a3c9f8891cb127243c\"}")

Get a plugin config for a consumer by plugin config id:

pluginConfig, err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().GetPluginConfig("58c5229-dc92-4632-91c1-f34d9b84db0b", "jwt", "22700b52-ba59-428e-b03b-ba429b1e775e")

Delete a plugin config for a consumer by plugin config id:

err := gokong.NewClient(gokong.NewDefaultConfig()).Consumers().DeletePluginConfig("3958a860-ceac-4a6c-9bbb-ff8d69a585d2", "jwt", "bde04c3a-46bb-45c9-9006-e8af20d04342")

Certificates

Create a Certificate (for more information on the Certificate Fields see the Kong documentation):

certificateRequest := &gokong.CertificateRequest{
  Cert: gokong.String("public key --- 123"),
  Key:  gokong.String("private key --- 456"),
}

createdCertificate, err := gokong.NewClient(gokong.NewDefaultConfig()).Certificates().Create(certificateRequest)

Get a Certificate by id:

certificate, err := gokong.NewClient(gokong.NewDefaultConfig()).Certificates().GetById("0408cbd4-e856-4565-bc11-066326de9231")

List all certificates:

certificates, err := gokong.NewClient(gokong.NewDefaultConfig()).Certificates().List()

Delete a Certificate:

err := gokong.NewClient(gokong.NewDefaultConfig()).Certificates().DeleteById("db884cf2-9dd7-4e33-9ef5-628165076a42")

Update a Certificate:

updateCertificateRequest := &gokong.CertificateRequest{
  Cert: gokong.String("public key --- 789"),
  Key:  gokong.String("private key --- 111"),
}

updatedCertificate, err := gokong.NewClient(gokong.NewDefaultConfig()).Certificates().UpdateById("1dc11281-30a6-4fb9-aec2-c6ff33445375", updateCertificateRequest)

Routes

Create a Route (for more information on the Route Fields see the Kong documentation):

serviceRequest := &gokong.ServiceRequest{
  Name:     gokong.String("service-name" + uuid.NewV4().String()),
  Protocol: gokong.String("http"),
  Host:     gokong.String("foo.com"),
}

client := gokong.NewClient(NewDefaultConfig())

createdService, err := client.Services().Create(serviceRequest)

routeRequest := &gokong.RouteRequest{
  Protocols:    gokong.StringSlice([]string{"http"}),
  Methods:      gokong.StringSlice([]string{"GET"}),
  Hosts:        gokong.StringSlice([]string{"foo.com"}),
  StripPath:    gokong.Bool(true),
  PreserveHost: gokong.Bool(true),
  Service:      gokong.ToId(*createdService.Id),
  Paths:        gokong.StringSlice([]string{"/bar"})
}

createdRoute, err := client.Routes().Create(routeRequest)

To create a tcp route:

routeRequest := &gokong.RouteRequest{
		Protocols:    gokong.StringSlice([]string{"tcp"}),
		StripPath:    gokong.Bool(true),
		PreserveHost: gokong.Bool(true),
		Snis:         gokong.StringSlice([]string{"example.com"}),
		Sources:      gokong.IpPortSliceSlice([]gokong.IpPort{{Ip: gokong.String("192.168.1.1"), Port: gokong.Int(80)}, {Ip: gokong.String("192.168.1.2"), Port: gokong.Int(81)}}),
		Destinations: gokong.IpPortSliceSlice([]gokong.IpPort{{Ip: gokong.String("172.10.1.1"), Port: gokong.Int(83)}, {Ip: gokong.String("172.10.1.2"), Port: nil}}),
		Service:      gokong.ToId(*createdService.Id),
	}

Get a route by ID:

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().GetById(createdRoute.Id)

Get a route by Name:

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().GetByName(createdRoute.Name)

List all routes:

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().List(&gokong.RouteQueryString{})

Get routes from service ID or Name:

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().GetRoutesFromServiceId(createdService.Id)

Update a route:

routeRequest := &gokong.RouteRequest{
  Protocols:    gokong.StringSlice([]string{"http"}),
  Methods:      gokong.StringSlice([]string{"GET"}),
  Hosts:        gokong.StringSlice([]string{"foo.com"}),
  Paths:        gokong.StringSlice([]string{"/bar"}),
  StripPath:    gokong.Bool(true),
  PreserveHost: gokong.Bool(true),
  Service:      gokong.ToId(*createdService.Id),
}

createdRoute, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().Create(routeRequest)

routeRequest.Paths = gokong.StringSlice([]string{"/qux"})
updatedRoute, err := gokong.NewClient(gokong.NewDefaultConfig()).Routes().UpdateRoute(*createdRoute.Id, routeRequest)

Delete a route by ID:

client.Routes().DeleteById(createdRoute.Id)

Delete a route by Name:

client.Routes().DeleteByName(createdRoute.Id)

Services

Create an Service (for more information on the Service Fields see the Kong documentation):

serviceRequest := &gokong.ServiceRequest{
		Name:     gokong.String("service-name-0"),
		Protocol: gokong.String("http"),
		Host:     gokong.String("foo.com"),
	}

	client := gokong.NewClient(gokong.NewDefaultConfig())

	createdService, err := client.Services().Create(serviceRequest)

Get information about a service with the service ID or Name

serviceRequest := &gokong.ServiceRequest{
		Name:     gokong.String("service-name-0"),
    Protocol: gokong.String("http"),
    Host:     gokong.String("foo.com")
	}

client := gokong.NewClient(gokong.NewDefaultConfig())

createdService, err := client.Services().Create(serviceRequest)

resultFromId, err := client.Services().GetServiceById(createdService.Id)

resultFromName, err := client.Services().GetServiceByName(createdService.Id)

Get information about a service with the route ID

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Services().GetServiceRouteId(routeInformation.Id)

Get many services information

result, err := gokong.NewClient(gokong.NewDefaultConfig()).Services().GetServices(&gokong.ServiceQueryString{
	Size: 500
	Offset: 300
})

Update a service with the service ID or Name

serviceRequest := &gokong.ServiceRequest{
  Name:     gokong.String("service-name-0"),
  Protocol: gokong.String("http"),
  Host:     gokong.String("foo.com"),
}

client := gokong.NewClient(gokong.NewDefaultConfig())

createdService, err := client.Services().Create(serviceRequest)

serviceRequest.Host = gokong.String("bar.io")
updatedService, err := client.Services().UpdateServiceById(createdService.Id, serviceRequest)
result, err := client.Services().GetServiceById(createdService.Id)

Update a service by the route ID

serviceRequest := &gokong.ServiceRequest{
  Name:     gokong.String("service-name-0"),
  Protocol: gokong.String("http"),
  Host:     gokong.String("foo.com"),
}

client := gokong.NewClient(gokong.NewDefaultConfig())

createdService, err := client.Services().Create(serviceRequest)

serviceRequest.Host = "bar.io"
updatedService, err := client.Services().UpdateServiceById(createdService.Id, serviceRequest)
result, err := client.Services().UpdateServicebyRouteId(routeInformation.Id)

Delete a service

err = client.Services().DeleteServiceById(createdService.Id)

SNIs

Create an SNI (for more information on the Sni Fields see the Kong documentation):

client := gokong.NewClient(gokong.NewDefaultConfig())

certificateRequest := &gokong.CertificateRequest{
  Cert: "public key --- 123",
  Key:  "private key --- 111",
}

certificate, err := client.Certificates().Create(certificateRequest)

snisRequest := &gokong.SnisRequest{
  Name:             "example.com",
  SslCertificateId: certificate.Id,
}

sni, err := client.Snis().Create(snisRequest)

Get an SNI by name:

sni, err := client.Snis().GetByName("example.com")

List all SNIs:

snis, err := client.Snis().List()

Delete an SNI by name:

err := client.Snis().DeleteByName("example.com")

Update an SNI by name:

updateSniRequest := &gokong.SnisRequest{
  Name:             "example.com",
  SslCertificateId: "a9797703-3ae6-44a9-9f0a-4ebb5d7f301f",
}

updatedSni, err := client.Snis().UpdateByName("example.com", updateSniRequest)

Upstreams

Create an Upstream (for more information on the Upstream Fields see the Kong documentation):

upstreamRequest := &gokong.UpstreamRequest{
  Name: "test-upstream",
  Slots: 10,
}

createdUpstream, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().Create(upstreamRequest)

Get an Upstream by id:

upstream, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().GetById("3705d962-caa8-4d0b-b291-4f0e85fe227a")

Get an Upstream by name:

upstream, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().GetByName("test-upstream")

List all Upstreams:

upstreams, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().List()

List all Upstreams with a filter:

upstreams, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().ListFiltered(&gokong.UpstreamFilter{Name:"test-upstream", Slots:10})

Delete an Upstream by id:

err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().DeleteById("3a46b122-47ee-4c5d-b2de-49be84a672e6")

Delete an Upstream by name:

err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().DeleteById("3a46b122-47ee-4c5d-b2de-49be84a672e6")

Delete an Upstream by id:

err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().DeleteByName("test-upstream")

Update an Upstream by id:

updateUpstreamRequest := &gokong.UpstreamRequest{
  Name: "test-upstream",
  Slots: 10,
}

updatedUpstream, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().UpdateById("3a46b122-47ee-4c5d-b2de-49be84a672e6", updateUpstreamRequest)

Update an Upstream by name:

updateUpstreamRequest := &gokong.UpstreamRequest{
  Name: "test-upstream",
  Slots: 10,
}

updatedUpstream, err := gokong.NewClient(gokong.NewDefaultConfig()).Upstreams().UpdateByName("test-upstream", updateUpstreamRequest)

Targets

Create a target for an upstream (for more information on the Target Fields see the Kong documentation):

targetRequest := &gokong.TargetRequest{
  Target:				"foo.com:443",
  Weight:				100,
}
createdTarget, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().CreateFromUpstreamId("upstreamId", targetRequest)

List all targets for an upstream

targets, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().GetTargetsFromUpstreamId("upstreamId")

Delete a target from an upstream

targets, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().DeleteFromUpstreamById("upstreamId")

Set target as healthy

targets, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().SetTargetFromUpstreamByIdAsHealthy("upstreamId")

Set target as unhealthy

targets, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().SetTargetFromUpstreamByIdAsUnhealthy("upstreamId")

List all targets for an upstream (including health status)

targets, err := gokong.NewClient(gokong.NewDefaultConfig()).Targets().GetTargetsWithHealthFromUpstreamName(upstreamId)

Notes: Target methods listed above are overloaded in the same fashion as other objects exposed by this library. For parameters:

  • upstream - either name of id can be used
  • target - either id or target name (host:port) can be used

Contributing

I would love to get contributions to the project so please feel free to submit a PR. To setup your dev station you need go and docker installed.

Once you have cloned the repository the make command will build the code and run all of the tests. If they all pass then you are good to go!

If when you run the make command you get the following error:

gofmt needs running on the following files:

Then all you need to do is run make goimports this will reformat all of the code (I know awesome)!!

Documentation

Index

Constants

View Source
const CertificatesPath = "/certificates/"
View Source
const ConsumersPath = "/consumers/"
View Source
const EnvKongAdminHostAddress = "KONG_ADMIN_ADDR"
View Source
const EnvKongAdminPassword = "KONG_ADMIN_PASSWORD"
View Source
const EnvKongAdminToken = "KONG_ADMIN_TOKEN"
View Source
const EnvKongAdminUsername = "KONG_ADMIN_USERNAME"
View Source
const EnvKongApiKey = "KONG_API_KEY"
View Source
const EnvKongTLSSkipVerify = "TLS_SKIP_VERIFY"
View Source
const EnvKongWorkspace = "KONG_ADMIN_WORKSPACE"
View Source
const PluginsPath = "/plugins/"
View Source
const RoutesPath = "/routes/"
View Source
const ServicesPath = "/services/"
View Source
const SnisPath = "/snis/"
View Source
const TargetsPath = "/upstreams/%s/targets"
View Source
const UpstreamsPath = "/upstreams/"
View Source
const WorkspacesPath = "/workspaces/"

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

func GetEnvVarOrDefault

func GetEnvVarOrDefault(key string, defaultValue string) string

func IdToString

func IdToString(v *Id) string

func Int

func Int(v int) *int

func NewClient

func NewClient(config *Config) *kongAdminClient

func String

func String(v string) *string

func StringSlice

func StringSlice(src []string) []*string

func StringValueSlice

func StringValueSlice(src []*string) []string

Types

type ActiveHealthy

type ActiveHealthy struct {
	HttpStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
	Interval     int   `json:"interval" yaml:"interval"`
	Successes    int   `json:"successes" yaml:"successes"`
}

type ActiveUnhealthy

type ActiveUnhealthy struct {
	HttpFailures int   `json:"http_failures" yaml:"http_failures"`
	HttpStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
	Interval     int   `json:"interval" yaml:"interval"`
	TcpFailures  int   `json:"tcp_failures" yaml:"tcp_failures"`
	Timeouts     int   `json:"timeouts" yaml:"timeouts"`
}

type Certificate

type Certificate struct {
	Id   *string   `json:"id,omitempty" yaml:"id,omitempty"`
	Cert *string   `json:"cert,omitempty" yaml:"cert,omitempty"`
	Key  *string   `json:"key,omitempty" yaml:"key,omitempty"`
	Tags []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type CertificateClient

type CertificateClient interface {
	GetById(id string) (*Certificate, error)
	Create(certificateRequest *CertificateRequest) (*Certificate, error)
	DeleteById(id string) error
	List() (*Certificates, error)
	UpdateById(id string, certificateRequest *CertificateRequest) (*Certificate, error)
}

type CertificateRequest

type CertificateRequest struct {
	Cert *string   `json:"cert,omitempty" yaml:"cert,omitempty"`
	Key  *string   `json:"key,omitempty" yaml:"key,omitempty"`
	Tags []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Certificates

type Certificates struct {
	Results []*Certificate `json:"data,omitempty" yaml:"data,omitempty"`
	Total   int            `json:"total,omitempty" yaml:"total,omitempty"`
}

type Config

type Config struct {
	HostAddress        string
	Username           string
	Password           string
	InsecureSkipVerify bool
	ApiKey             string
	AdminToken         string
	Workspace          string
}

func NewDefaultConfig

func NewDefaultConfig() *Config

type Consumer

type Consumer struct {
	Id       string    `json:"id,omitempty" yaml:"id,omitempty"`
	CustomId string    `json:"custom_id,omitempty" yaml:"custom_id,omitempty"`
	Username string    `json:"username,omitempty" yaml:"username,omitempty"`
	Tags     []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type ConsumerClient

type ConsumerClient interface {
	GetByUsername(username string) (*Consumer, error)
	GetById(id string) (*Consumer, error)
	Create(consumerRequest *ConsumerRequest) (*Consumer, error)
	List(query *ConsumerQueryString) ([]*Consumer, error)
	DeleteByUsername(username string) error
	DeleteById(id string) error
	UpdateByUsername(username string, consumerRequest *ConsumerRequest) (*Consumer, error)
	UpdateById(id string, consumerRequest *ConsumerRequest) (*Consumer, error)
	CreatePluginConfig(consumerId string, pluginName string, pluginConfig string) (*ConsumerPluginConfig, error)
	GetPluginConfig(consumerId string, pluginName string, id string) (*ConsumerPluginConfig, error)
	GetPluginConfigs(consumerId string, pluginName string) ([]map[string]interface{}, error)
	DeletePluginConfig(consumerId string, pluginName string, id string) error
}

type ConsumerPluginConfig

type ConsumerPluginConfig struct {
	Id   string `json:"id,omitempty" yaml:"id,omitempty"`
	Body string
}

type ConsumerPluginConfigs

type ConsumerPluginConfigs struct {
	Data   []map[string]interface{} `json:"data,omitempty" yaml:"data,omitempty"`
	Next   string                   `json:"next,omitempty" yaml:"next,omitempty"`
	Offset string                   `json:"offset,omitempty" yaml:"offset,omitempty"`
}

type ConsumerQueryString

type ConsumerQueryString struct {
	Offset string `json:"offset,omitempty"`
	Size   int    `json:"size"`
}

type ConsumerRequest

type ConsumerRequest struct {
	Username string    `json:"username,omitempty" yaml:"username,omitempty"`
	CustomId string    `json:"custom_id,omitempty" yaml:"custom_id,omitempty"`
	Tags     []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Consumers

type Consumers struct {
	Data   []*Consumer `json:"data,omitempty" yaml:"data,omitempty"`
	Next   string      `json:"next,omitempty" yaml:"next,omitempty"`
	Offset string      `json:"offset,omitempty" yaml:"offset,omitempty"`
}

type Id

type Id string

func ToId

func ToId(v string) *Id

func (*Id) MarshalJSON

func (c *Id) MarshalJSON() ([]byte, error)

func (*Id) MarshalYAML

func (c *Id) MarshalYAML() (interface{}, error)

func (*Id) UnmarshalJSON

func (c *Id) UnmarshalJSON(data []byte) error

func (*Id) UnmarshalYAML

func (c *Id) UnmarshalYAML(unmarshal func(interface{}) error) error

type IpPort

type IpPort struct {
	Ip   *string `json:"ip" yaml:"ip"`
	Port *int    `json:"port" yaml:"port"`
}

func IpPortSliceSlice

func IpPortSliceSlice(src []IpPort) []*IpPort

type KongAdminClient

type KongAdminClient interface {
	Status() StatusClient
	Consumers() ConsumerClient
	Plugins() PluginClient
	Certificates() CertificateClient
	Snis() SnisClient
	Upstreams() UpstreamClient
	Routes() RouteClient
	Services() ServiceClient
	Targets() TargetClient
	Workspaces() WorkspaceClient
}

type PassiveHealthy

type PassiveHealthy struct {
	HttpStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
	Successes    int   `json:"successes" yaml:"successes"`
}

type PassiveUnhealthy

type PassiveUnhealthy struct {
	HttpFailures int   `json:"http_failures" yaml:"http_failures"`
	HttpStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
	TcpFailures  int   `json:"tcp_failures" yaml:"tcp_failures"`
	Timeouts     int   `json:"timeouts" yaml:"timeouts"`
}

type Plugin

type Plugin struct {
	Id         string                 `json:"id" yaml:"id"`
	Name       string                 `json:"name" yaml:"name"`
	ConsumerId *Id                    `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	ServiceId  *Id                    `json:"service,omitempty" yaml:"service,omitempty"`
	RouteId    *Id                    `json:"route,omitempty" yaml:"route,omitempty"`
	RunOn      string                 `json:"run_on,omitempty" yaml:"run_on,omitempty"`
	Config     map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
	Enabled    bool                   `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

type PluginClient

type PluginClient interface {
	GetById(id string) (*Plugin, error)
	List(query *PluginQueryString) ([]*Plugin, error)
	Create(pluginRequest *PluginRequest) (*Plugin, error)
	UpdateById(id string, pluginRequest *PluginRequest) (*Plugin, error)
	DeleteById(id string) error
	GetByConsumerId(id string) (*Plugins, error)
	GetByRouteId(id string) (*Plugins, error)
	GetByServiceId(id string) (*Plugins, error)
}

type PluginQueryString

type PluginQueryString struct {
	Offset string `json:"offset,omitempty" yaml:"offset,omitempty"`
	Size   int    `json:"size" yaml:"size,omitempty"`
}

type PluginRequest

type PluginRequest struct {
	Name       string                 `json:"name" yaml:"name"`
	ConsumerId *Id                    `json:"consumer" yaml:"consumer"`
	ServiceId  *Id                    `json:"service" yaml:"service"`
	RouteId    *Id                    `json:"route" yaml:"route"`
	RunOn      string                 `json:"run_on,omitempty" yaml:"run_on,omitempty"`
	Config     map[string]interface{} `json:"config,omitempty" yaml:"config,omitempty"`
	Enabled    *bool                  `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

type Plugins

type Plugins struct {
	Data   []*Plugin `json:"data" yaml:"data,omitempty"`
	Next   *string   `json:"next" yaml:"next,omitempty"`
	Offset string    `json:"offset,omitempty" yaml:"offset,omitempty"`
}

type Route

type Route struct {
	Id            *string   `json:"id" yaml:"id"`
	Name          *string   `json:"name" yaml:"name"`
	CreatedAt     *int      `json:"created_at" yaml:"created_at"`
	UpdatedAt     *int      `json:"updated_at" yaml:"updated_at"`
	Protocols     []*string `json:"protocols" yaml:"protocols"`
	Methods       []*string `json:"methods" yaml:"methods"`
	Hosts         []*string `json:"hosts" yaml:"hosts"`
	Paths         []*string `json:"paths" yaml:"paths"`
	RegexPriority *int      `json:"regex_priority" yaml:"regex_priority"`
	StripPath     *bool     `json:"strip_path" yaml:"strip_path"`
	PreserveHost  *bool     `json:"preserve_host" yaml:"preserve_host"`
	Snis          []*string `json:"snis" yaml:"snis"`
	Sources       []*IpPort `json:"sources" yaml:"sources"`
	Destinations  []*IpPort `json:"destinations" yaml:"destinations"`
	Service       *Id       `json:"service" yaml:"service"`
	Tags          []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type RouteClient

type RouteClient interface {
	GetByName(name string) (*Route, error)
	GetById(id string) (*Route, error)
	Create(routeRequest *RouteRequest) (*Route, error)
	List(query *RouteQueryString) ([]*Route, error)
	GetRoutesFromServiceName(name string) ([]*Route, error)
	GetRoutesFromServiceId(id string) ([]*Route, error)
	UpdateByName(name string, routeRequest *RouteRequest) (*Route, error)
	UpdateById(id string, routeRequest *RouteRequest) (*Route, error)
	DeleteByName(name string) error
	DeleteById(id string) error
}

type RouteQueryString

type RouteQueryString struct {
	Offset string `json:"offset,omitempty"`
	Size   int    `json:"size"`
}

type RouteRequest

type RouteRequest struct {
	Name          *string   `json:"name" yaml:"name"`
	Protocols     []*string `json:"protocols" yaml:"protocols"`
	Methods       []*string `json:"methods" yaml:"methods"`
	Hosts         []*string `json:"hosts" yaml:"hosts"`
	Paths         []*string `json:"paths" yaml:"paths"`
	RegexPriority *int      `json:"regex_priority" yaml:"regex_priority"`
	StripPath     *bool     `json:"strip_path" yaml:"strip_path"`
	PreserveHost  *bool     `json:"preserve_host" yaml:"preserve_host"`
	Snis          []*string `json:"snis" yaml:"snis"`
	Sources       []*IpPort `json:"sources" yaml:"sources"`
	Destinations  []*IpPort `json:"destinations" yaml:"destinations"`
	Service       *Id       `json:"service" yaml:"service"`
	Tags          []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Routes

type Routes struct {
	Data   []*Route `json:"data" yaml:"data"`
	Next   *string  `json:"next" yaml:"next"`
	Offset string   `json:"offset,omitempty" yaml:"offset,omitempty"`
}

type Service

type Service struct {
	Id             *string   `json:"id" yaml:"id"`
	CreatedAt      *int      `json:"created_at" yaml:"created_at"`
	UpdatedAt      *int      `json:"updated_at" yaml:"updated_at"`
	Protocol       *string   `json:"protocol" yaml:"protocol"`
	Host           *string   `json:"host" yaml:"host"`
	Port           *int      `json:"port" yaml:"port"`
	Path           *string   `json:"path" yaml:"path"`
	Name           *string   `json:"name" yaml:"name"`
	Retries        *int      `json:"retries" yaml:"retries"`
	ConnectTimeout *int      `json:"connect_timeout" yaml:"connect_timeout"`
	WriteTimeout   *int      `json:"write_timeout" yaml:"write_timeout"`
	ReadTimeout    *int      `json:"read_timeout" yaml:"read_timeout"`
	Url            *string   `json:"url" yaml:"url"`
	Tags           []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type ServiceClient

type ServiceClient interface {
	Create(serviceRequest *ServiceRequest) (*Service, error)
	GetServiceByName(name string) (*Service, error)
	GetServiceById(id string) (*Service, error)
	GetServiceFromRouteId(id string) (*Service, error)
	GetServices(query *ServiceQueryString) ([]*Service, error)
	UpdateServiceByName(name string, serviceRequest *ServiceRequest) (*Service, error)
	UpdateServiceById(id string, serviceRequest *ServiceRequest) (*Service, error)
	UpdateServicebyRouteId(id string, serviceRequest *ServiceRequest) (*Service, error)
	DeleteServiceByName(name string) error
	DeleteServiceById(id string) error
}

type ServiceQueryString

type ServiceQueryString struct {
	Offset string `json:"offset,omitempty"`
	Size   int    `json:"size"`
}

type ServiceRequest

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

type Services

type Services struct {
	Data   []*Service `json:"data" yaml:"data"`
	Next   *string    `json:"next" yaml:"mext"`
	Offset string     `json:"offset,omitempty" yaml:"offset,omitempty"`
}

type Sni

type Sni struct {
	Name          string    `json:"name,omitempty" yaml:"name,omitempty"`
	CertificateId *Id       `json:"certificate,omitempty" yaml:"certificate,omitempty"`
	Tags          []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Snis

type Snis struct {
	Results []*Sni `json:"data,omitempty" yaml:"data,omitempty"`
	Total   int    `json:"total,omitempty" yaml:"total,omitempty"`
}

type SnisClient

type SnisClient interface {
	Create(snisRequest *SnisRequest) (*Sni, error)
	GetByName(name string) (*Sni, error)
	List() (*Snis, error)
	DeleteByName(name string) error
	UpdateByName(name string, snisRequest *SnisRequest) (*Sni, error)
}

type SnisRequest

type SnisRequest struct {
	Name          string    `json:"name,omitempty" yaml:"name,omitempty"`
	CertificateId *Id       `json:"certificate,omitempty" yaml:"certificate,omitempty"`
	Tags          []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Status

type Status struct {
	Server   serverStatus   `json:"server" yaml:"server"`
	Database databaseStatus `json:"database" yaml:"database"`
}

type StatusClient

type StatusClient interface {
	Get() (*Status, error)
}

type Target

type Target struct {
	Id        *string   `json:"id,omitempty" yaml:"id,omitempty"`
	CreatedAt *float32  `json:"created_at" yaml:"created_at"`
	Target    *string   `json:"target" yaml:"target"`
	Weight    *int      `json:"weight" yaml:"weight"`
	Upstream  *Id       `json:"upstream" yaml:"upstream"`
	Health    *string   `json:"health" yaml:"health"`
	Tags      []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type TargetClient

type TargetClient interface {
	CreateFromUpstreamName(name string, targetRequest *TargetRequest) (*Target, error)
	CreateFromUpstreamId(id string, targetRequest *TargetRequest) (*Target, error)
	GetTargetsFromUpstreamName(name string) ([]*Target, error)
	GetTargetsFromUpstreamId(id string) ([]*Target, error)
	DeleteFromUpstreamByHostPort(upstreamNameOrId string, hostPort string) error
	DeleteFromUpstreamById(upstreamNameOrId string, id string) error
	SetTargetFromUpstreamByHostPortAsHealthy(upstreamNameOrId string, hostPort string) error
	SetTargetFromUpstreamByIdAsHealthy(upstreamNameOrId string, id string) error
	SetTargetFromUpstreamByHostPortAsUnhealthy(upstreamNameOrId string, hostPort string) error
	SetTargetFromUpstreamByIdAsUnhealthy(upstreamNameOrId string, id string) error
	GetTargetsWithHealthFromUpstreamName(name string) ([]*Target, error)
	GetTargetsWithHealthFromUpstreamId(id string) ([]*Target, error)
}

type TargetRequest

type TargetRequest struct {
	Target string    `json:"target" yaml:"target"`
	Weight int       `json:"weight" yaml:"weight"`
	Tags   []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Targets

type Targets struct {
	Data   []*Target `json:"data" yaml:"data"`
	Total  int       `json:"total,omitempty" yaml:"total,omitempty"`
	Next   string    `json:"next,omitempty" yaml:"next,omitempty"`
	NodeId string    `json:"node_id,omitempty" yaml:"node_id,omitempty"`
}

type Upstream

type Upstream struct {
	Id string `json:"id,omitempty" yaml:"id,omitempty"`
	UpstreamRequest
	Tags []*string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type UpstreamClient

type UpstreamClient interface {
	GetByName(name string) (*Upstream, error)
	GetById(id string) (*Upstream, error)
	Create(upstreamRequest *UpstreamRequest) (*Upstream, error)
	DeleteByName(name string) error
	DeleteById(id string) error
	List() (*Upstreams, error)
	UpdateByName(name string, upstreamRequest *UpstreamRequest) (*Upstream, error)
	UpdateById(id string, upstreamRequest *UpstreamRequest) (*Upstream, error)
}

type UpstreamHealthCheck

type UpstreamHealthCheck struct {
	Active  *UpstreamHealthCheckActive  `json:"active,omitempty" yaml:"active,omitempty"`
	Passive *UpstreamHealthCheckPassive `json:"passive,omitempty" yaml:"passive,omitempty"`
}

type UpstreamHealthCheckActive

type UpstreamHealthCheckActive struct {
	Type                   string           `json:"type,omitempty" yaml:"type,omitempty"`
	Concurrency            int              `json:"concurrency,omitempty" yaml:"concurrency,omitempty"`
	Healthy                *ActiveHealthy   `json:"healthy,omitempty" yaml:"healthy,omitempty"`
	HttpPath               string           `json:"http_path,omitempty" yaml:"http_path,omitempty"`
	HttpsVerifyCertificate bool             `json:"https_verify_certificate" yaml:"https_verify_certificate"`
	HttpsSni               *string          `json:"https_sni,omitempty" yaml:"https_sni,omitempty"`
	Timeout                int              `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	Unhealthy              *ActiveUnhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
}

type UpstreamHealthCheckPassive

type UpstreamHealthCheckPassive struct {
	Type      string            `json:"type,omitempty" yaml:"type,omitempty"`
	Healthy   *PassiveHealthy   `json:"healthy,omitempty yaml:"healthy,omitempty"`
	Unhealthy *PassiveUnhealthy `json:"unhealthy,omitempty yaml:"unhealthy,omitempty"`
}

type UpstreamRequest

type UpstreamRequest struct {
	Name               string               `json:"name" yaml:"name"`
	Slots              int                  `json:"slots,omitempty" yaml:"slots,omitempty"`
	HashOn             string               `json:"hash_on,omitempty" yaml:"hash_on,omitempty"`
	HashFallback       string               `json:"hash_fallback,omitempty" yaml:"hash_fallback,omitempty"`
	HashOnHeader       string               `json:"hash_on_header,omitempty" yaml:"hash_on_header,omitempty"`
	HashFallbackHeader string               `json:"hash_fallback_header,omitempty" yaml:"hash_fallback_header,omitempty"`
	HashOnCookie       string               `json:"hash_on_cookie,omitempty" yaml:"hash_on_cookie,omitempty"`
	HashOnCookiePath   string               `json:"hash_on_cookie_path,omitempty" yaml:"hash_on_cookie_path,omitempty"`
	HealthChecks       *UpstreamHealthCheck `json:"healthchecks,omitempty" yaml:"healthchecks,omitempty"`
	Tags               []*string            `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Upstreams

type Upstreams struct {
	Results []*Upstream `json:"data,omitempty" yaml:"data,omitempty"`
	Next    string      `json:"next,omitempty" yaml:"next,omitempty"`
}

type Workspace

type Workspace struct {
	Id      *string     `json:"id" yaml:"id"`
	Name    *string     `json:"name" yaml:"name"`
	Comment *string     `json:"comment" yaml:"comment"`
	Config  interface{} `json:"config,omitempty" yaml:"config,omitempty"`
	Meta    interface{} `json:"meta,omitempty" yaml:"meta,omitempty"`
}

type WorkspaceClient

type WorkspaceClient interface {
	GetByName(name string) (*Workspace, error)
	Get(id string) (*Workspace, error)
	List(query *WorkspaceQueryString) ([]*Workspace, error)
	Create(workspaceRequest *WorkspaceRequest) (*Workspace, error)
	Update(workspaceRequest *WorkspaceRequest) (*Workspace, error)
	Delete() error
	ListEntities() ([]*WorkspaceEntity, error)
	DeleteMultipleEntitiesFromWorkspace(entityIds []string) error
}

type WorkspaceEntities

type WorkspaceEntities struct {
	Data  []*WorkspaceEntity `json:"data" yaml:"data,omitempty"`
	Total int                `json:"total,omitempty" yaml:"total,omitempty"`
}

type WorkspaceEntitiesRequest

type WorkspaceEntitiesRequest struct {
	Entities *string `json:"entities" yaml:"entities"`
}

type WorkspaceEntity

type WorkspaceEntity struct {
	WorkspaceId      *string `json:"workspace_id" yaml:"workspace_id"`
	WorkspaceName    *string `json:"workspace_name" yaml:"workspace_name"`
	EntityId         *string `json:"entity_id" yaml:"entity_id"`
	EntityType       *string `json:"entity_type" yaml:"entity_type"`
	UniqueFieldName  *string `json:"unique_field_name" yaml:"unique_field_name"`
	UniqueFieldValue *string `json:"unique_field_value" yaml:"unique_field_value"`
}

type WorkspaceQueryString

type WorkspaceQueryString struct {
	Offset *string `json:"offset,omitempty" yaml:"offset,omitempty"`
	Size   int     `json:"size" yaml:"size,omitempty"`
}

type WorkspaceRequest

type WorkspaceRequest struct {
	Name    *string `json:"name" yaml:"name"`
	Comment *string `json:"comment" yaml:"comment"`
}

type Workspaces

type Workspaces struct {
	Data   []*Workspace `json:"data" yaml:"data,omitempty"`
	Next   *string      `json:"next" yaml:"next,omitempty"`
	Offset string       `json:"offset,omitempty" yaml:"offset,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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