gokong

package module
v6.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 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

To add gokong via govendor:

govendor fetch 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 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/"

Variables

This section is empty.

Functions

func Bool added in v1.0.0

func Bool(v bool) *bool

func GetEnvVarOrDefault

func GetEnvVarOrDefault(key string, defaultValue string) string

func IdToString

func IdToString(v *Id) string

func Int added in v1.0.0

func Int(v int) *int

func String added in v1.0.0

func String(v string) *string

func StringSlice added in v1.0.0

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

func StringValueSlice added in v1.0.0

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"`
}

type CertificateClient

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

func (*CertificateClient) Create

func (certificateClient *CertificateClient) Create(certificateRequest *CertificateRequest) (*Certificate, error)

func (*CertificateClient) DeleteById

func (certificateClient *CertificateClient) DeleteById(id string) error

func (*CertificateClient) GetById

func (certificateClient *CertificateClient) GetById(id string) (*Certificate, error)

func (*CertificateClient) List

func (certificateClient *CertificateClient) List() (*Certificates, error)

func (*CertificateClient) UpdateById

func (certificateClient *CertificateClient) 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"`
}

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
}

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:"custom_id,omitempty"`
}

type ConsumerClient

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

func (*ConsumerClient) Create

func (consumerClient *ConsumerClient) Create(consumerRequest *ConsumerRequest) (*Consumer, error)

func (*ConsumerClient) CreatePluginConfig

func (consumerClient *ConsumerClient) CreatePluginConfig(consumerId string, pluginName string, pluginConfig string) (*ConsumerPluginConfig, error)

func (*ConsumerClient) DeleteById

func (consumerClient *ConsumerClient) DeleteById(id string) error

func (*ConsumerClient) DeleteByUsername

func (consumerClient *ConsumerClient) DeleteByUsername(username string) error

func (*ConsumerClient) DeletePluginConfig

func (consumerClient *ConsumerClient) DeletePluginConfig(consumerId string, pluginName string, id string) error

func (*ConsumerClient) GetById

func (consumerClient *ConsumerClient) GetById(id string) (*Consumer, error)

func (*ConsumerClient) GetByUsername

func (consumerClient *ConsumerClient) GetByUsername(username string) (*Consumer, error)

func (*ConsumerClient) GetPluginConfig

func (consumerClient *ConsumerClient) GetPluginConfig(consumerId string, pluginName string, id string) (*ConsumerPluginConfig, error)

func (*ConsumerClient) List

func (consumerClient *ConsumerClient) List() (*Consumers, error)

func (*ConsumerClient) UpdateById

func (consumerClient *ConsumerClient) UpdateById(id string, consumerRequest *ConsumerRequest) (*Consumer, error)

func (*ConsumerClient) UpdateByUsername

func (consumerClient *ConsumerClient) UpdateByUsername(username string, consumerRequest *ConsumerRequest) (*Consumer, error)

type ConsumerPluginConfig

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

type ConsumerRequest

type ConsumerRequest struct {
	Username string `json:"username,omitempty" yaml:"username,omitempty"`
	CustomId string `json:"custom_id,omitempty" yaml:"custom_id,omitempty"`
}

type Consumers

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

type Id

type Id string

func ToId

func ToId(v string) *Id

func (*Id) MarshalJSON

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

func (*Id) UnmarshalJSON

func (c *Id) UnmarshalJSON(data []byte) 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 struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *Config) *KongAdminClient

func (*KongAdminClient) Certificates

func (kongAdminClient *KongAdminClient) Certificates() *CertificateClient

func (*KongAdminClient) Consumers

func (kongAdminClient *KongAdminClient) Consumers() *ConsumerClient

func (*KongAdminClient) Plugins

func (kongAdminClient *KongAdminClient) Plugins() *PluginClient

func (*KongAdminClient) Routes

func (kongAdminClient *KongAdminClient) Routes() *RouteClient

func (*KongAdminClient) Services

func (kongAdminClient *KongAdminClient) Services() *ServiceClient

func (*KongAdminClient) Snis

func (kongAdminClient *KongAdminClient) Snis() *SnisClient

func (*KongAdminClient) Status

func (kongAdminClient *KongAdminClient) Status() *StatusClient

func (*KongAdminClient) Targets added in v1.10.0

func (kongAdminClient *KongAdminClient) Targets() *TargetClient

func (*KongAdminClient) Upstreams

func (kongAdminClient *KongAdminClient) Upstreams() *UpstreamClient

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 struct {
	// contains filtered or unexported fields
}

func (*PluginClient) Create

func (pluginClient *PluginClient) Create(pluginRequest *PluginRequest) (*Plugin, error)

func (*PluginClient) DeleteById

func (pluginClient *PluginClient) DeleteById(id string) error

func (*PluginClient) GetByConsumerId

func (pluginClient *PluginClient) GetByConsumerId(id string) (*Plugins, error)

func (*PluginClient) GetById

func (pluginClient *PluginClient) GetById(id string) (*Plugin, error)

func (*PluginClient) GetByRouteId

func (pluginClient *PluginClient) GetByRouteId(id string) (*Plugins, error)

func (*PluginClient) GetByServiceId

func (pluginClient *PluginClient) GetByServiceId(id string) (*Plugins, error)

func (*PluginClient) List

func (pluginClient *PluginClient) List(query *PluginQueryString) ([]*Plugin, error)

func (*PluginClient) UpdateById

func (pluginClient *PluginClient) UpdateById(id string, pluginRequest *PluginRequest) (*Plugin, 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"`
}

type RouteClient

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

func (*RouteClient) Create

func (routeClient *RouteClient) Create(routeRequest *RouteRequest) (*Route, error)

func (*RouteClient) DeleteById

func (routeClient *RouteClient) DeleteById(id string) error

func (*RouteClient) DeleteByName

func (routeClient *RouteClient) DeleteByName(name string) error

func (*RouteClient) GetById

func (routeClient *RouteClient) GetById(id string) (*Route, error)

func (*RouteClient) GetByName

func (routeClient *RouteClient) GetByName(name string) (*Route, error)

func (*RouteClient) GetRoutesFromServiceId

func (routeClient *RouteClient) GetRoutesFromServiceId(id string) ([]*Route, error)

func (*RouteClient) GetRoutesFromServiceName

func (routeClient *RouteClient) GetRoutesFromServiceName(name string) ([]*Route, error)

func (*RouteClient) List

func (routeClient *RouteClient) List(query *RouteQueryString) ([]*Route, error)

func (*RouteClient) UpdateById

func (routeClient *RouteClient) UpdateById(id string, routeRequest *RouteRequest) (*Route, error)

func (*RouteClient) UpdateByName

func (routeClient *RouteClient) UpdateByName(name string, routeRequest *RouteRequest) (*Route, error)

type RouteQueryString

type RouteQueryString struct {
	Offset int
	Size   int
}

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"`
}

type Routes

type Routes struct {
	Data  []*Route `json:"data" yaml:"data"`
	Total int      `json:"total" yaml:"total"`
	Next  string   `json:"next" yaml:"next"`
}

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"`
}

type ServiceClient

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

func (*ServiceClient) Create

func (serviceClient *ServiceClient) Create(serviceRequest *ServiceRequest) (*Service, error)

func (*ServiceClient) DeleteServiceById

func (serviceClient *ServiceClient) DeleteServiceById(id string) error

func (*ServiceClient) DeleteServiceByName

func (serviceClient *ServiceClient) DeleteServiceByName(name string) error

func (*ServiceClient) GetServiceById

func (serviceClient *ServiceClient) GetServiceById(id string) (*Service, error)

func (*ServiceClient) GetServiceByName

func (serviceClient *ServiceClient) GetServiceByName(name string) (*Service, error)

func (*ServiceClient) GetServiceFromRouteId

func (serviceClient *ServiceClient) GetServiceFromRouteId(id string) (*Service, error)

func (*ServiceClient) GetServices

func (serviceClient *ServiceClient) GetServices(query *ServiceQueryString) ([]*Service, error)

func (*ServiceClient) UpdateServiceById

func (serviceClient *ServiceClient) UpdateServiceById(id string, serviceRequest *ServiceRequest) (*Service, error)

func (*ServiceClient) UpdateServiceByName

func (serviceClient *ServiceClient) UpdateServiceByName(name string, serviceRequest *ServiceRequest) (*Service, error)

func (*ServiceClient) UpdateServicebyRouteId

func (serviceClient *ServiceClient) UpdateServicebyRouteId(id string, serviceRequest *ServiceRequest) (*Service, error)

type ServiceQueryString

type ServiceQueryString struct {
	Offset int
	Size   int
}

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"`
}

type Services

type Services struct {
	Data []*Service `json:"data" yaml:"data"`
	Next *string    `json:"next" yaml:"next"`
}

type Sni

type Sni struct {
	Name          string `json:"name,omitempty" yaml:"name,omitempty"`
	CertificateId *Id    `json:"certificate,omitempty" yaml:"certificate,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 struct {
	// contains filtered or unexported fields
}

func (*SnisClient) Create

func (snisClient *SnisClient) Create(snisRequest *SnisRequest) (*Sni, error)

func (*SnisClient) DeleteByName

func (snisClient *SnisClient) DeleteByName(name string) error

func (*SnisClient) GetByName

func (snisClient *SnisClient) GetByName(name string) (*Sni, error)

func (*SnisClient) List

func (snisClient *SnisClient) List() (*Snis, error)

func (*SnisClient) UpdateByName

func (snisClient *SnisClient) 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"`
}

type Status

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

type StatusClient

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

func (*StatusClient) Get

func (statusClient *StatusClient) Get() (*Status, error)

type Target added in v1.10.0

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"`
}

type TargetClient added in v1.10.0

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

func (*TargetClient) CreateFromUpstreamId added in v1.10.0

func (targetClient *TargetClient) CreateFromUpstreamId(id string, targetRequest *TargetRequest) (*Target, error)

func (*TargetClient) CreateFromUpstreamName added in v1.10.0

func (targetClient *TargetClient) CreateFromUpstreamName(name string, targetRequest *TargetRequest) (*Target, error)

func (*TargetClient) DeleteFromUpstreamByHostPort added in v1.10.0

func (targetClient *TargetClient) DeleteFromUpstreamByHostPort(upstreamNameOrId string, hostPort string) error

func (*TargetClient) DeleteFromUpstreamById added in v1.10.0

func (targetClient *TargetClient) DeleteFromUpstreamById(upstreamNameOrId string, id string) error

func (*TargetClient) GetTargetsFromUpstreamId added in v1.10.0

func (targetClient *TargetClient) GetTargetsFromUpstreamId(id string) ([]*Target, error)

func (*TargetClient) GetTargetsFromUpstreamName added in v1.10.0

func (targetClient *TargetClient) GetTargetsFromUpstreamName(name string) ([]*Target, error)

func (*TargetClient) GetTargetsWithHealthFromUpstreamId added in v1.10.0

func (targetClient *TargetClient) GetTargetsWithHealthFromUpstreamId(id string) ([]*Target, error)

func (*TargetClient) GetTargetsWithHealthFromUpstreamName added in v1.10.0

func (targetClient *TargetClient) GetTargetsWithHealthFromUpstreamName(name string) ([]*Target, error)

func (*TargetClient) SetTargetFromUpstreamByHostPortAsHealthy added in v1.10.0

func (targetClient *TargetClient) SetTargetFromUpstreamByHostPortAsHealthy(upstreamNameOrId string, hostPort string) error

func (*TargetClient) SetTargetFromUpstreamByHostPortAsUnhealthy added in v1.10.0

func (targetClient *TargetClient) SetTargetFromUpstreamByHostPortAsUnhealthy(upstreamNameOrId string, hostPort string) error

func (*TargetClient) SetTargetFromUpstreamByIdAsHealthy added in v1.10.0

func (targetClient *TargetClient) SetTargetFromUpstreamByIdAsHealthy(upstreamNameOrId string, id string) error

func (*TargetClient) SetTargetFromUpstreamByIdAsUnhealthy added in v1.10.0

func (targetClient *TargetClient) SetTargetFromUpstreamByIdAsUnhealthy(upstreamNameOrId string, id string) error

type TargetRequest added in v1.10.0

type TargetRequest struct {
	Target string `json:"target" yaml:"target"`
	Weight int    `json:"weight" yaml:"weight"`
}

type Targets added in v1.10.0

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
}

type UpstreamClient

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

func (*UpstreamClient) Create

func (upstreamClient *UpstreamClient) Create(upstreamRequest *UpstreamRequest) (*Upstream, error)

func (*UpstreamClient) DeleteById

func (upstreamClient *UpstreamClient) DeleteById(id string) error

func (*UpstreamClient) DeleteByName

func (upstreamClient *UpstreamClient) DeleteByName(name string) error

func (*UpstreamClient) GetById

func (upstreamClient *UpstreamClient) GetById(id string) (*Upstream, error)

func (*UpstreamClient) GetByName

func (upstreamClient *UpstreamClient) GetByName(name string) (*Upstream, error)

func (*UpstreamClient) List

func (upstreamClient *UpstreamClient) List() (*Upstreams, error)

func (*UpstreamClient) UpdateById

func (upstreamClient *UpstreamClient) UpdateById(id string, upstreamRequest *UpstreamRequest) (*Upstream, error)

func (*UpstreamClient) UpdateByName

func (upstreamClient *UpstreamClient) UpdateByName(name 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"`
}

type Upstreams

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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