schema

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KongToKonnectEntitiesMap = map[string]string{
	"services":              "service",
	"routes":                "route",
	"upstreams":             "upstream",
	"targets":               "target",
	"jwt_secrets":           "jwt",
	"consumers":             "consumer",
	"consumer_groups":       "consumer_group",
	"certificates":          "certificate",
	"ca_certificates":       "ca_certificate",
	"keys":                  "key",
	"key_sets":              "key-set",
	"hmacauth_credentials":  "hmac-auth",
	"basicauth_credentials": "basic-auth",
	"mtls_auth_credentials": "mtls-auth",
	"snis":                  "sni",
	"vaults":                "vault",
}

KongToKonnectEntitiesMap maps Kong Gateway entity type names to Konnect entity type names. Some entities in Konnect have different names compared to Kong Gateway.

Functions

func FetchEntitySchema

func FetchEntitySchema(
	ctx context.Context, client *kong.Client, isKonnect bool, entityType string,
) (kong.Schema, error)

FetchEntitySchema fetches the schema for a given entity type from either the Kong Gateway admin API or the Konnect API. If the schema is not found (e.g. EE-only entities), it returns (nil, nil).

func FetchPartialSchema

func FetchPartialSchema(
	ctx context.Context, client *kong.Client, partialType string,
) (map[string]interface{}, error)

FetchPartialSchema fetches the full schema for a partial by type from the Kong admin API.

func FetchPluginSchema

func FetchPluginSchema(
	ctx context.Context, client *kong.Client, pluginName string,
) (map[string]interface{}, error)

FetchPluginSchema fetches the full schema for a plugin by name from the Kong admin API.

func FetchVaultSchema

func FetchVaultSchema(
	ctx context.Context, client *kong.Client, vaultType string, isKonnect bool,
) (kong.Schema, error)

FetchVaultSchema fetches the schema for a vault by type from either the Kong Gateway admin API or the Konnect API.

func FindDefaultInReplacementPath

func FindDefaultInReplacementPath(schema gjson.Result, pathSegments []string) gjson.Result

FindDefaultInReplacementPath traverses the schema to find the default value at the specified path.

func GetDefaultsFromSchema

func GetDefaultsFromSchema(schema map[string]interface{}, cacheKey string) (map[string]interface{}, error)

GetDefaultsFromSchema parses a Kong entity schema and returns a map of field names to their default values.

If cacheKey is non-empty, results are cached and subsequent calls with the same key return the cached value. Use a key like "entityType::identifier" (e.g. "plugins::rate-limiting") to avoid collisions.

func ParseSchemaForDefaults

func ParseSchemaForDefaults(schema gjson.Result, defaultFields map[string]interface{}) map[string]interface{}

ParseSchemaForDefaults walks a gjson schema result and extracts all fields that have default values, returning a nested map of field name → default value.

It handles:

  • Simple "default" fields
  • Nested "record" type fields (recursive)
  • "shorthand_fields" with "translate_backwards" or "deprecation.replaced_with" paths
  • Konnect's "value" wrapper for credentials

func ResetDefaultsCache

func ResetDefaultsCache()

ResetDefaultsCache clears the defaults cache. This is primarily useful in tests.

Types

type Cache

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

Cache provides thread-safe caching of schemas keyed by a string identifier. It lazily fetches schemas on first access and returns cached results thereafter.

func NewCache

func NewCache(fetcher Fetcher) *Cache

NewCache creates a new schema Cache backed by the given fetcher function.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, identifier string) (map[string]interface{}, error)

Get returns the cached schema for the given identifier, fetching it on first access.

type Fetcher

type Fetcher func(ctx context.Context, identifier string) (map[string]interface{}, error)

Fetcher is a function that retrieves a schema by identifier from an external source.

type Registry

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

Registry is the central schema manager. It holds all schema caches for different entity categories (generic entities, plugins, partials, vaults) and provides a single GetSchema method that routes to the correct cache based on entity type.

Create a Registry via NewRegistry and share it across all subsystems that need schema access (dump, diff, defaulter, etc.) to avoid duplicate caches and redundant API calls.

func NewRegistry

func NewRegistry(client *kong.Client, isKonnect bool) *Registry

NewRegistry creates a new Registry backed by the given Kong client. All four caches are initialised with the appropriate fetcher functions for either Gateway or Konnect, determined by isKonnect.

func (*Registry) GetDefaults

func (r *Registry) GetDefaults(ctx context.Context, entityType, identifier string) (map[string]interface{}, error)

GetDefaults fetches the schema for the given entity type and identifier, parses it for default values, and returns them as a nested map. Results are cached by a key derived from entityType and identifier.

For most entities entityType and identifier are the same (e.g. "services"). For plugins, partials, and vaults, identifier is the specific name/type (e.g. "rate-limiting").

func (*Registry) GetEntitySchema

func (r *Registry) GetEntitySchema(ctx context.Context, entityType string) (kong.Schema, error)

GetEntitySchema is a convenience method that fetches the schema for a generic entity type (services, routes, upstreams, etc.). It is equivalent to GetSchema(ctx, entityType, entityType).

func (*Registry) GetPartialSchema

func (r *Registry) GetPartialSchema(ctx context.Context, partialType string) (map[string]interface{}, error)

GetPartialSchema is a convenience method that fetches the schema for a partial by its type.

func (*Registry) GetPluginSchema

func (r *Registry) GetPluginSchema(ctx context.Context, pluginName string) (map[string]interface{}, error)

GetPluginSchema is a convenience method that fetches the schema for a plugin by its name (e.g. "rate-limiting").

func (*Registry) GetSchema

func (r *Registry) GetSchema(ctx context.Context, entityType, identifier string) (kong.Schema, error)

GetSchema returns the schema for a given entity type and identifier. For most entities, entityType doubles as the cache key (e.g. "services"). For plugins, partials, and vaults the identifier is the specific name/type (e.g. "rate-limiting", "aws") because each has its own schema.

func (*Registry) GetVaultSchema

func (r *Registry) GetVaultSchema(ctx context.Context, vaultType string) (map[string]interface{}, error)

GetVaultSchema is a convenience method that fetches the schema for a vault by its type (e.g. "aws", "hcv").

Jump to

Keyboard shortcuts

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