kong

package
v0.0.0-...-fe055a6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const KTAKongUpstreamAlgorithmConsistentHashing = "consistent-hashing"
View Source
const KTAKongUpstreamAlgorithmLeastConnections = "least-connections"
View Source
const KTAKongUpstreamAlgorithmRoundRobin = "round-robin"
View Source
const KTASixUpstreamAlgorithmConsistentHashing = "chash"
View Source
const KTASixUpstreamAlgorithmLeastConnections = "least_conn"
View Source
const KTASixUpstreamAlgorithmRoundRobin = "roundrobin"
View Source
const PluginKeyAuth = "key-auth"
View Source
const PluginProxyCache = "proxy-cache"
View Source
const PluginRateLimiting = "rate-limiting"
View Source
const PluginRateLimitingPolicyLocal = "local"
View Source
const PluginRateLimitingPolicyRedis = "redis"

Variables

This section is empty.

Functions

func AfterMigrate

func AfterMigrate(apisixConfig *apisix.Config) error

func ConvertKongRouteToA6

func ConvertKongRouteToA6(kongService Service, kongRoute Route) apisix.Routes

func DumpKong

func DumpKong(kongAddr string, fileName string) error

func GenerateApisixServiceUpstream

func GenerateApisixServiceUpstream(kongService Service, apisixConfig *apisix.Config) string

func GenerateProxyRewritePluginConfig

func GenerateProxyRewritePluginConfig(servicePath string, routerPath string, stripPath bool,
	pathHandling string) *apisix.ProxyRewrite

GenerateProxyRewritePluginConfig Generate routing and forwarding rules https://docs.konghq.com/gateway-oss/2.4.x/admin-api/#path-handling-algorithms

func KTAConversionKongConsumerPluginBasicAuthCredential

func KTAConversionKongConsumerPluginBasicAuthCredential(credential BasicAuthCredential) *apisix.BasicAuthCredential

func KTAConversionKongConsumerPluginHmacAuthCredential

func KTAConversionKongConsumerPluginHmacAuthCredential(credential HmacAuthCredential) *apisix.HmacAuthCredential

func KTAConversionKongConsumerPluginJwtSecrets

func KTAConversionKongConsumerPluginJwtSecrets(secret JwtSecret) *apisix.JwtSecrets

func KTAConversionKongConsumerPluginKeyAuthCredential

func KTAConversionKongConsumerPluginKeyAuthCredential(credential KeyAuthCredential) *apisix.KeyAuthCredential

func KTAConversionKongPluginKeyAuth

func KTAConversionKongPluginKeyAuth(kongPlugin Plugin) *apisix.KeyAuth

func KTAConversionKongPluginProxyCache

func KTAConversionKongPluginProxyCache(kongPlugin Plugin) *apisix.ProxyCache

func KTAConversionKongPluginRateLimiting

func KTAConversionKongPluginRateLimiting(kongPlugin Plugin) *apisix.LimitCount

func KTAConversionKongUpstreamTargets

func KTAConversionKongUpstreamTargets(kongTargets Targets, kongUpstreamId string) apisix.UpstreamNodes

func KTAConversionKongUpstreamTimeout

func KTAConversionKongUpstreamTimeout(kongTime uint) float32

func KTAIsKongGlobalPlugin

func KTAIsKongGlobalPlugin(kongPlugin Plugin) bool

func KTAUpdateApisixConsumerPlugin

func KTAUpdateApisixConsumerPlugin(apisixConsumer *apisix.Consumer, kongPlugin interface{})

func KTAUpdateApisixRoutePlugin

func KTAUpdateApisixRoutePlugin(apisixRoute *apisix.Route, kongPlugin *Plugin)

func KTAUpdateApisixServicePlugin

func KTAUpdateApisixServicePlugin(apisixService *apisix.Service, kongPlugin *Plugin)

func Migrate

func Migrate(kongConfig *Config) (*apisix.Config, *[]utils.YamlItem, error)

func MigrateConsumer

func MigrateConsumer(kongConfig *Config, apisixConfig *apisix.Config) error

func MigrateGlobalRules

func MigrateGlobalRules(kongConfig *Config, apisixConfig *apisix.Config) error

MigrateGlobalRules attention to plugin priority https://docs.konghq.com/gateway-oss/2.4.x/admin-api/#precedence

func MigratePlugins

func MigratePlugins(kongConfig *Config, apisixConfig *apisix.Config) error

MigratePlugins This function is only called when the data exported by kong config is used

func MigrateRoute

func MigrateRoute(kongConfig *Config, apisixConfig *apisix.Config) error

func MigrateService

func MigrateService(kongConfig *Config, apisixConfig *apisix.Config) error

func MigrateUpstream

func MigrateUpstream(kongConfig *Config, apisixConfig *apisix.Config) error

Types

type A6ServiceUpstreamMapping

type A6ServiceUpstreamMapping struct {
	ServiceId  string
	UpstreamId string
}

type A6UpstreamNodeHostPort

type A6UpstreamNodeHostPort struct {
	Host string
	Port int
}

func KTAFormatKongTarget

func KTAFormatKongTarget(kongTarget string) (*A6UpstreamNodeHostPort, error)

type ActiveHealthCheck

type ActiveHealthCheck struct {
	Concurrency            int       `json:"concurrency,omitempty" yaml:"concurrency,omitempty"`
	Healthy                Healthy   `json:"healthy,omitempty" yaml:"healthy,omitempty"`
	HTTPPath               string    `json:"http_path,omitempty" yaml:"http_path,omitempty"`
	HTTPSSni               string    `json:"https_sni,omitempty" yaml:"https_sni,omitempty"`
	HTTPSVerifyCertificate bool      `json:"https_verify_certificate,omitempty" yaml:"https_verify_certificate,omitempty"`
	Type                   string    `json:"type,omitempty" yaml:"type,omitempty"`
	Timeout                int       `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	Unhealthy              Unhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
}

type BasicAuthCredential

type BasicAuthCredential struct {
	ID         string `json:"id,omitempty" yaml:"id,omitempty"`
	ConsumerID string `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	Username   string `json:"username,omitempty" yaml:"username,omitempty"`
	Password   string `json:"password,omitempty" yaml:"password,omitempty"`
}

type BasicAuthCredentials

type BasicAuthCredentials []BasicAuthCredential

type CIDRPort

type CIDRPort struct {
	IP   string `json:"ip,omitempty" yaml:"ip,omitempty"`
	Port int    `json:"port,omitempty" yaml:"port,omitempty"`
}

CIDRPort is the kong cidr port definition.

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"`
	CertALT string   `json:"cert_alt,omitempty" yaml:"cert_alt,omitempty"`
	KeyALT  string   `json:"key_alt,omitempty" yaml:"key_alt,omitempty"`
	SNIs    []string `json:"snis,omitempty" yaml:"snis,omitempty"`
	Tags    []string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

Certificate is the kong certificate definition.

type Certificates

type Certificates []Certificate

type Config

type Config struct {
	Services             Services             `json:"services,omitempty" yaml:"services,omitempty"`
	Consumers            Consumers            `json:"consumers,omitempty" yaml:"consumers,omitempty"`
	Plugins              Plugins              `json:"plugins,omitempty" yaml:"plugins,omitempty"`
	Upstreams            Upstreams            `json:"upstreams,omitempty" yaml:"upstreams,omitempty"`
	Routes               Routes               `json:"routes,omitempty" yaml:"routes,omitempty"`
	Targets              Targets              `json:"targets,omitempty" yaml:"targets,omitempty"`
	KeyAuthCredentials   KeyAuthCredentials   `json:"keyauth_credentials,omitempty" yaml:"keyauth_credentials,omitempty"`
	BasicAuthCredentials BasicAuthCredentials `json:"basicauth_credentials,omitempty" yaml:"basicauth_credentials,omitempty"`
	HmacAuthCredentials  HmacAuthCredentials  `json:"hmacauth_credentials,omitempty" yaml:"hmacauth_credentials,omitempty"`
	JwtSecrets           JwtSecrets           `json:"jwt_secrets,omitempty" yaml:"jwt_secrets,omitempty"`
}

func ReadYaml

func ReadYaml(yamlPath string) (*Config, error)

type Configuration

type Configuration map[string]interface{}

Configuration is the kong plugin config definition.

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"`
	KeyAuthCredentials   KeyAuthCredentials   `json:"keyauth_credentials,omitempty" yaml:"keyauth_credentials,omitempty"`
	BasicAuthCredentials BasicAuthCredentials `json:"basicauth_credentials,omitempty" yaml:"basicauth_credentials,omitempty"`
	HmacAuthCredentials  HmacAuthCredentials  `json:"hmacauth_credentials,omitempty" yaml:"hmacauth_credentials,omitempty"`
	JwtSecrets           JwtSecrets           `json:"jwt_secrets,omitempty" yaml:"jwt_secrets,omitempty"`
}

Consumer is the kong consumer definition.

type Consumers

type Consumers []Consumer

type HealthCheck

type HealthCheck struct {
	Active    ActiveHealthCheck  `json:"active,omitempty" yaml:"active,omitempty"`
	Passive   PassiveHealthCheck `json:"passive,omitempty" yaml:"passive,omitempty"`
	Threshold float64            `json:"threshold,omitempty" yaml:"threshold,omitempty"`
}

type Healthy

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

type HmacAuthCredential

type HmacAuthCredential struct {
	ID         string `json:"id,omitempty" yaml:"id,omitempty"`
	ConsumerID string `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	Username   string `json:"username,omitempty" yaml:"username,omitempty"`
	Secret     string `json:"secret,omitempty" yaml:"secret,omitempty"`
}

type HmacAuthCredentials

type HmacAuthCredentials []HmacAuthCredential

type JwtSecret

type JwtSecret struct {
	ID         string `json:"id,omitempty" yaml:"id,omitempty"`
	ConsumerID string `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	Algorithm  string `json:"algorithm,omitempty" yaml:"algorithm,omitempty"`
	Key        string `json:"key,omitempty" yaml:"key,omitempty"`
	Secret     string `json:"secret,omitempty" yaml:"secret,omitempty"`
}

type JwtSecrets

type JwtSecrets []JwtSecret

type KeyAuth

type KeyAuth struct {
	Anonymous       string   `yaml:"anonymous"`
	HideCredentials bool     `yaml:"hide_credentials"`
	KeyInBody       bool     `yaml:"key_in_body"`
	KeyInHeader     bool     `yaml:"key_in_header"`
	KeyInQuery      bool     `yaml:"key_in_query"`
	KeyNames        []string `yaml:"key_names"`
	RunOnPreflight  bool     `yaml:"run_on_preflight"`
}

type KeyAuthCredential

type KeyAuthCredential struct {
	ID         string `json:"id,omitempty" yaml:"id,omitempty"`
	ConsumerID string `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	Key        string `json:"key,omitempty" yaml:"key,omitempty"`
}

type KeyAuthCredentials

type KeyAuthCredentials []KeyAuthCredential

type PassiveHealthCheck

type PassiveHealthCheck struct {
	Healthy   Healthy   `json:"healthy,omitempty" yaml:"healthy,omitempty"`
	Type      string    `json:"type,omitempty" yaml:"type,omitempty"`
	Unhealthy Unhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
}

type Plugin

type Plugin struct {
	ID         string        `json:"id,omitempty" yaml:"id,omitempty"`
	Name       string        `json:"name,omitempty" yaml:"name,omitempty"`
	RouteID    string        `json:"route,omitempty" yaml:"route,omitempty"`
	ServiceID  string        `json:"service,omitempty" yaml:"service,omitempty"`
	ConsumerID string        `json:"consumer,omitempty" yaml:"consumer,omitempty"`
	Config     Configuration `json:"config,omitempty" yaml:"config,omitempty"`
	Protocols  []string      `json:"protocols,omitempty" yaml:"protocols,omitempty"`
	Enabled    bool          `json:"enabled,omitempty" yaml:"enabled,omitempty"`
	Tags       []string      `json:"tags,omitempty" yaml:"tags,omitempty"`
}

Plugin is the kong plugin definition.

type Plugins

type Plugins []Plugin

type ProxyCache

type ProxyCache struct {
	CacheControl    bool             `yaml:"cache_control"`
	CacheTTL        int              `yaml:"cache_ttl"`
	ContentType     []string         `yaml:"content_type"`
	Memory          ProxyCacheMemory `yaml:"memory"`
	RequestMethod   []string         `yaml:"request_method"`
	ResponseCode    []int            `yaml:"response_code"`
	StorageTTL      int              `yaml:"storage_ttl"`
	Strategy        string           `yaml:"strategy"`
	VaryHeaders     []string         `yaml:"vary_headers"`
	VaryQueryParams []string         `yaml:"vary_query_params"`
}

type ProxyCacheMemory

type ProxyCacheMemory struct {
	DictionaryName string `yaml:"dictionary_name"`
}

type RateLimiting

type RateLimiting struct {
	Day               int    `yaml:"day"`
	FaultTolerant     bool   `yaml:"fault_tolerant"`
	HeaderName        string `yaml:"header_name"`
	HideClientHeaders bool   `yaml:"hide_client_headers"`
	Hour              int    `yaml:"hour"`
	LimitBy           string `yaml:"limit_by"`
	Minute            int    `yaml:"minute"`
	Month             int    `yaml:"month"`
	Path              string `yaml:"path"`
	Policy            string `yaml:"policy"`
	RedisDatabase     int    `yaml:"redis_database"`
	RedisHost         string `yaml:"redis_host"`
	RedisPassword     string `yaml:"redis_password"`
	RedisPort         int    `yaml:"redis_port"`
	RedisTimeout      int    `yaml:"redis_timeout"`
	Second            int    `yaml:"second"`
	Year              int    `yaml:"year"`
}

type Route

type Route struct {
	ID                      string              `json:"id,omitempty" yaml:"id,omitempty"`
	Name                    string              `json:"name,omitempty" yaml:"name,omitempty"`
	Protocols               []string            `json:"protocols,omitempty" yaml:"protocols,omitempty"`
	Methods                 []string            `json:"methods,omitempty" yaml:"methods,omitempty"`
	Hosts                   []string            `json:"hosts,omitempty" yaml:"hosts,omitempty"`
	Paths                   []string            `json:"paths,omitempty" yaml:"paths,omitempty"`
	Headers                 map[string][]string `json:"headers,omitempty" yaml:"headers,omitempty"`
	HTTPSRedirectStatusCode int                 `json:"https_redirect_status_code,omitempty" yaml:"https_redirect_status_code,omitempty"`
	RegexPriority           uint                `json:"regex_priority,omitempty" yaml:"regex_priority,omitempty"`
	StripPath               bool                `json:"strip_path" yaml:"strip_path"`
	PathHandling            string              `json:"path_handling,omitempty" yaml:"path_handling,omitempty"`
	PreserveHost            bool                `json:"preserve_host,omitempty" yaml:"preserve_host,omitempty"`
	RequestBuffering        bool                `json:"request_buffering,omitempty" yaml:"request_buffering,omitempty"`
	ResponseBuffering       bool                `json:"response_buffering,omitempty" yaml:"response_buffering,omitempty"`
	SNIs                    []string            `json:"snis,omitempty" yaml:"snis,omitempty"`
	Sources                 []CIDRPort          `json:"sources,omitempty" yaml:"sources,omitempty"`
	Destinations            []CIDRPort          `json:"destinations,omitempty" yaml:"destinations,omitempty"`
	Tags                    []string            `json:"tags,omitempty" yaml:"tags,omitempty"`
	ServiceID               string              `json:"service,omitempty" yaml:"service,omitempty"`
	Plugins                 Plugins             `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}

Route is the kong route definition.

type Routes

type Routes []Route

type SNI

type SNI struct {
	ID          string      `json:"id,omitempty" yaml:"id,omitempty"`
	Name        string      `json:"name,omitempty" yaml:"name,omitempty"`
	Certificate Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
	Tags        []string    `json:"tags,omitempty" yaml:"tags,omitempty"`
}

SNI is the kong sni definition.

type SNIs

type SNIs []SNI

type Service

type Service struct {
	ID                string      `json:"id,omitempty" yaml:"id,omitempty"`
	Name              string      `json:"name,omitempty" yaml:"name,omitempty"`
	Retries           uint        `json:"retries,omitempty" yaml:"retries,omitempty"`
	Protocol          string      `json:"protocol,omitempty" yaml:"protocol,omitempty"`
	Host              string      `json:"host,omitempty" yaml:"host,omitempty"`
	Path              string      `json:"path,omitempty" yaml:"path,omitempty"`
	Port              int         `json:"port,omitempty" yaml:"port,omitempty"`
	ConnectTimeout    uint        `json:"connect_timeout,omitempty" yaml:"connect_timeout,omitempty"`
	ReadTimeout       uint        `json:"read_timeout,omitempty" yaml:"read_timeout,omitempty"`
	WriteTimeout      uint        `json:"write_timeout,omitempty" yaml:"write_timeout,omitempty"`
	Tags              []string    `json:"tags,omitempty" yaml:"tags,omitempty"`
	ClientCertificate Certificate `json:"client_certificate,omitempty" yaml:"client_certificate,omitempty"`
	TLSVerify         bool        `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
	TLSVerifyDepth    int         `json:"tls_verify_depth,omitempty" yaml:"tls_verify_depth,omitempty"`
	CACertificates    []string    `json:"ca_certificates,omitempty" yaml:"ca_certificates,omitempty"`
	URL               string      `json:"url,omitempty" yaml:"url,omitempty"`
	Routes            Routes      `json:"routes,omitempty" yaml:"routes,omitempty"`
	Plugins           Plugins     `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}

Service is the kong service definition.

func FindKongServiceByHost

func FindKongServiceByHost(kongServices *Services, serviceHost string) (*Service, error)

func FindKongServiceById

func FindKongServiceById(kongServices *Services, serviceID string) (*Service, error)

type Services

type Services []Service

type Target

type Target struct {
	ID         string   `json:"id,omitempty" yaml:"id,omitempty"`
	Target     string   `json:"target,omitempty" yaml:"target,omitempty"`
	UpstreamID string   `json:"upstream,omitempty" yaml:"upstream,omitempty"`
	Weight     int      `json:"weight,omitempty" yaml:"weight,omitempty"`
	Tags       []string `json:"tags,omitempty" yaml:"tags,omitempty"`
}

type Targets

type Targets []Target

type Unhealthy

type Unhealthy struct {
	HTTPFailures int   `json:"http_failures,omitempty" yaml:"http_failures,omitempty"`
	HTTPStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
	TCPFailures  int   `json:"tcp_failures,omitempty" yaml:"tcp_failures,omitempty"`
	Timeouts     int   `json:"timeouts,omitempty" yaml:"timeouts,omitempty"`
	Interval     int   `json:"interval,omitempty" yaml:"interval,omitempty"`
}

type Upstream

type Upstream struct {
	ID                 string      `json:"id,omitempty" yaml:"id,omitempty"`
	Name               string      `json:"name,omitempty" yaml:"name,omitempty"`
	Algorithm          string      `json:"algorithm,omitempty" yaml:"algorithm,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"`
	Slots              int         `json:"slots,omitempty" yaml:"slots,omitempty"`
	HealthChecks       HealthCheck `json:"healthchecks,omitempty" yaml:"healthchecks,omitempty"`
	Tags               []string    `json:"tags,omitempty" yaml:"tags,omitempty"`
	HostHeader         string      `json:"host_header,omitempty" yaml:"host_header,omitempty"`
	ClientCertificate  Certificate `json:"client_certificate,omitempty" yaml:"client_certificate,omitempty"`
	Targets            Targets     `json:"targets,omitempty" yaml:"targets,omitempty"`
}

Upstream is the kong upstream definition.

type Upstreams

type Upstreams []Upstream

Jump to

Keyboard shortcuts

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