state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgPortalAPINotConfigured              = "Portal API client not configured"
	ErrMsgAPIAPINotConfigured                 = "API client not configured"
	ErrMsgAuthStrategyAPINotConfigured        = "app auth API client not configured"
	ErrMsgAPIVersionAPINotConfigured          = "API version client not configured"
	ErrMsgAPIPublicationAPINotConfigured      = "API publication client not configured"
	ErrMsgAPIImplementationAPINotConfigured   = "API implementation client not configured"
	ErrMsgAPIDocumentAPINotConfigured         = "API document client not configured"
	ErrMsgPortalPageAPINotConfigured          = "portal page API not configured"
	ErrMsgPortalSnippetAPINotConfigured       = "portal snippet API not configured"
	ErrMsgPortalCustomizationAPINotConfigured = "portal customization API not configured"
	ErrMsgPortalCustomDomainAPINotConfigured  = "portal custom domain API not configured"
)

Standard error messages for common scenarios

Variables

This section is empty.

Functions

func IsAPIClientError

func IsAPIClientError(err error) bool

IsAPIClientError checks if an error is an API client not configured error

func IsResponseValidationError

func IsResponseValidationError(err error) bool

IsResponseValidationError checks if an error is a response validation error

func NewAPIClientNotConfiguredError

func NewAPIClientNotConfiguredError(clientType string) error

NewAPIClientNotConfiguredError creates a standard "client not configured" error

func NewResponseValidationError

func NewResponseValidationError(operation, expectedType string) error

NewResponseValidationError creates a standard response validation error

func PaginateAll

func PaginateAll[T any](ctx context.Context, lister PaginatedLister[T]) ([]T, error)

PaginateAll fetches all pages from a paginated API endpoint

func PaginateAllFiltered

func PaginateAllFiltered[T any](
	ctx context.Context, lister FilteredPaginatedLister[T], filter func(T) bool,
) ([]T, error)

PaginateAllFiltered fetches all pages from a paginated API endpoint with filtering

func ValidateAPIClient

func ValidateAPIClient(client interface{}, clientType string) error

ValidateAPIClient checks if an API client interface is configured (not nil)

func ValidateResponse

func ValidateResponse[T any](response *T, operation string) error

ValidateResponse checks if a response pointer contains non-nil data

func WrapAPIError

func WrapAPIError(err error, operation string, opts *ErrorWrapperOptions) error

WrapAPIError wraps an API error with consistent formatting and optional enhancement

Types

type API

type API struct {
	kkComps.APIResponseSchema
	NormalizedLabels map[string]string // Non-pointer labels
}

API represents a normalized API for internal use

type APIClientError

type APIClientError struct {
	ClientType string
}

APIClientError represents an error when an API client is not configured

func (*APIClientError) Error

func (e *APIClientError) Error() string

type APIDocument

type APIDocument struct {
	ID               string
	Content          string
	Title            string
	Slug             string
	Status           string
	ParentDocumentID string
}

APIDocument represents an API document for internal use

type APIImplementation

type APIImplementation struct {
	ID                string
	ImplementationURL string
	Service           *struct {
		ID             string
		ControlPlaneID string
	}
}

APIImplementation represents an API implementation for internal use

type APIPublication

type APIPublication struct {
	ID                       string
	PortalID                 string
	AuthStrategyIDs          []string
	AutoApproveRegistrations bool
	Visibility               string
}

APIPublication represents an API publication for internal use

type APIVersion

type APIVersion struct {
	ID            string
	Version       string
	PublishStatus string
	Deprecated    bool
	SunsetDate    string
}

APIVersion represents an API version for internal use

type ApplicationAuthStrategy

type ApplicationAuthStrategy struct {
	ID               string
	Name             string
	DisplayName      string
	StrategyType     string
	Configs          map[string]interface{}
	NormalizedLabels map[string]string // Non-pointer labels
}

ApplicationAuthStrategy represents a normalized auth strategy for internal use

type Cache

type Cache struct {
	// Top-level resources
	Portals                   map[string]*CachedPortal            // portalID -> portal with children
	APIs                      map[string]*CachedAPI               // apiID -> api with children
	ApplicationAuthStrategies map[string]*ApplicationAuthStrategy // strategyID -> strategy
}

Cache represents cached Konnect state with hierarchical structure

func NewCache

func NewCache() *Cache

NewCache creates an initialized cache

type CachedAPI

type CachedAPI struct {
	API

	// Child resources
	Versions        map[string]*APIVersion        // versionID -> version
	Publications    map[string]*APIPublication    // portalID -> publication (one per portal)
	Implementations map[string]*APIImplementation // implementationID -> implementation
	Documents       map[string]*CachedAPIDocument // documentID -> document (with nested children)
}

CachedAPI represents an API with all its child resources

type CachedAPIDocument

type CachedAPIDocument struct {
	APIDocument

	// Child documents indexed by ID
	Children map[string]*CachedAPIDocument // documentID -> child document
}

CachedAPIDocument represents a document with its children

type CachedPortal

type CachedPortal struct {
	Portal

	// Child resources
	Pages         map[string]*CachedPortalPage // pageID -> page (with nested children)
	Customization *PortalCustomization         // singleton
	CustomDomain  *PortalCustomDomain          // singleton
	Snippets      map[string]*PortalSnippet    // snippetID -> snippet
}

CachedPortal represents a portal with all its child resources

func (*CachedPortal) FindPageBySlugPath

func (p *CachedPortal) FindPageBySlugPath(slugPath string) *CachedPortalPage

FindPageBySlugPath finds a page by its full slug path

func (*CachedPortal) GetPortalPage

func (p *CachedPortal) GetPortalPage(pageID string) *CachedPortalPage

GetPortalPage finds a page anywhere in the portal hierarchy

type CachedPortalPage

type CachedPortalPage struct {
	PortalPage

	// Child pages indexed by ID
	Children map[string]*CachedPortalPage // pageID -> child page
}

CachedPortalPage represents a page with its children

func (*CachedPortalPage) GetDescendant

func (p *CachedPortalPage) GetDescendant(pageID string) *CachedPortalPage

GetDescendant finds a descendant page by ID

type Client

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

Client wraps Konnect SDK for state management

func NewClient

func NewClient(config ClientConfig) *Client

NewClient creates a new state client with the provided configuration

func (*Client) CreateAPI

func (c *Client) CreateAPI(
	ctx context.Context,
	api kkComps.CreateAPIRequest,
	namespace string,
) (*kkComps.APIResponseSchema, error)

CreateAPI creates a new API with management labels

func (*Client) CreateAPIDocument

func (c *Client) CreateAPIDocument(
	ctx context.Context, apiID string, document kkComps.CreateAPIDocumentRequest,
) (*kkComps.APIDocumentResponse, error)

CreateAPIDocument creates a new API document

func (*Client) CreateAPIImplementation

func (c *Client) CreateAPIImplementation(
	_ context.Context, _ string, _ interface{},
) (*kkComps.APIImplementationResponse, error)

CreateAPIImplementation creates a new API implementation Note: This is a placeholder - SDK doesn't support implementation creation yet

func (*Client) CreateAPIPublication

func (c *Client) CreateAPIPublication(
	ctx context.Context, apiID string, portalID string, publication kkComps.APIPublication,
) (*kkComps.APIPublicationResponse, error)

CreateAPIPublication creates a new API publication

func (*Client) CreateAPIVersion

func (c *Client) CreateAPIVersion(
	ctx context.Context, apiID string, version kkComps.CreateAPIVersionRequest,
) (*kkComps.APIVersionResponse, error)

CreateAPIVersion creates a new API version

func (*Client) CreateApplicationAuthStrategy

func (c *Client) CreateApplicationAuthStrategy(
	ctx context.Context,
	authStrategy kkComps.CreateAppAuthStrategyRequest,
	_ string,
) (*kkOps.CreateAppAuthStrategyResponse, error)

CreateApplicationAuthStrategy creates a new application auth strategy with management labels

func (*Client) CreatePortal

func (c *Client) CreatePortal(
	ctx context.Context,
	portal kkComps.CreatePortal,
	namespace string,
) (*kkComps.PortalResponse, error)

CreatePortal creates a new portal with management labels

func (*Client) CreatePortalCustomDomain

func (c *Client) CreatePortalCustomDomain(
	ctx context.Context,
	portalID string,
	req kkComps.CreatePortalCustomDomainRequest,
) error

CreatePortalCustomDomain creates a custom domain for a portal

func (*Client) CreatePortalPage

func (c *Client) CreatePortalPage(
	ctx context.Context,
	portalID string,
	req kkComps.CreatePortalPageRequest,
) (string, error)

CreatePortalPage creates a new page in a portal

func (*Client) CreatePortalSnippet

func (c *Client) CreatePortalSnippet(
	ctx context.Context,
	portalID string,
	req kkComps.CreatePortalSnippetRequest,
) (string, error)

CreatePortalSnippet creates a new snippet in a portal

func (*Client) DeleteAPI

func (c *Client) DeleteAPI(ctx context.Context, id string) error

DeleteAPI deletes an API by ID

func (*Client) DeleteAPIDocument

func (c *Client) DeleteAPIDocument(ctx context.Context, apiID, documentID string) error

DeleteAPIDocument deletes an API document

func (*Client) DeleteAPIImplementation

func (c *Client) DeleteAPIImplementation(_ context.Context, _, _ string) error

DeleteAPIImplementation deletes an API implementation Note: This is a placeholder - SDK doesn't support implementation deletion yet

func (*Client) DeleteAPIPublication

func (c *Client) DeleteAPIPublication(ctx context.Context, apiID, portalID string) error

DeleteAPIPublication deletes an API publication

func (*Client) DeleteAPIVersion

func (c *Client) DeleteAPIVersion(ctx context.Context, apiID string, versionID string) error

DeleteAPIVersion deletes an API version

func (*Client) DeleteApplicationAuthStrategy

func (c *Client) DeleteApplicationAuthStrategy(ctx context.Context, id string) error

DeleteApplicationAuthStrategy deletes an auth strategy by ID

func (*Client) DeletePortal

func (c *Client) DeletePortal(ctx context.Context, id string, force bool) error

DeletePortal deletes a portal by ID

func (*Client) DeletePortalCustomDomain

func (c *Client) DeletePortalCustomDomain(ctx context.Context, portalID string) error

DeletePortalCustomDomain deletes a portal custom domain

func (*Client) DeletePortalPage

func (c *Client) DeletePortalPage(ctx context.Context, portalID string, pageID string) error

DeletePortalPage deletes a page from a portal

func (*Client) DeletePortalSnippet

func (c *Client) DeletePortalSnippet(ctx context.Context, portalID string, snippetID string) error

DeletePortalSnippet deletes a snippet from a portal

func (*Client) GetAPIByFilter

func (c *Client) GetAPIByFilter(ctx context.Context, filter string) (*API, error)

GetAPIByFilter finds a managed API using a filter expression

func (*Client) GetAPIByID

func (c *Client) GetAPIByID(ctx context.Context, id string) (*API, error)

GetAPIByID finds an API by ID (for fallback during protection changes)

func (*Client) GetAPIByName

func (c *Client) GetAPIByName(ctx context.Context, name string) (*API, error)

GetAPIByName finds a managed API by name

func (*Client) GetAPIByRef

func (c *Client) GetAPIByRef(ctx context.Context, ref string) (*API, error)

GetAPIByRef finds a managed API by declarative ref (stored in labels) TODO: This will be replaced by filtered lookup in Phase 2

func (*Client) GetAPIDocument

func (c *Client) GetAPIDocument(ctx context.Context, apiID, documentID string) (*APIDocument, error)

GetAPIDocument retrieves a single API document with full content

func (*Client) GetAuthStrategyByFilter

func (c *Client) GetAuthStrategyByFilter(ctx context.Context, filter string) (*ApplicationAuthStrategy, error)

GetAuthStrategyByFilter finds a managed auth strategy using a filter expression

func (*Client) GetAuthStrategyByName

func (c *Client) GetAuthStrategyByName(ctx context.Context, name string) (*ApplicationAuthStrategy, error)

GetAuthStrategyByName finds a managed auth strategy by name

func (*Client) GetPortalByFilter

func (c *Client) GetPortalByFilter(ctx context.Context, filter string) (*Portal, error)

GetPortalByFilter finds a managed portal using a filter expression

func (*Client) GetPortalByName

func (c *Client) GetPortalByName(ctx context.Context, name string) (*Portal, error)

GetPortalByName finds a managed portal by name

func (*Client) GetPortalCustomization

func (c *Client) GetPortalCustomization(
	ctx context.Context,
	portalID string,
) (*kkComps.PortalCustomization, error)

GetPortalCustomization fetches the current customization for a portal

func (*Client) GetPortalPage

func (c *Client) GetPortalPage(ctx context.Context, portalID string, pageID string) (*PortalPage, error)

GetPortalPage fetches a single portal page with full details including content

func (*Client) GetPortalSnippet

func (c *Client) GetPortalSnippet(ctx context.Context, portalID string, snippetID string) (*PortalSnippet, error)

GetPortalSnippet fetches a single portal snippet with full details including content

func (*Client) ListAPIDocuments

func (c *Client) ListAPIDocuments(ctx context.Context, apiID string) ([]APIDocument, error)

ListAPIDocuments returns all documents for an API

func (*Client) ListAPIImplementations

func (c *Client) ListAPIImplementations(ctx context.Context, apiID string) ([]APIImplementation, error)

ListAPIImplementations returns all implementations for an API

func (*Client) ListAPIPublications

func (c *Client) ListAPIPublications(ctx context.Context, apiID string) ([]APIPublication, error)

ListAPIPublications returns all publications for an API

func (*Client) ListAPIVersions

func (c *Client) ListAPIVersions(ctx context.Context, apiID string) ([]APIVersion, error)

ListAPIVersions returns all versions for an API

func (*Client) ListAllAPIs

func (c *Client) ListAllAPIs(ctx context.Context) ([]API, error)

ListAllAPIs returns all APIs without managed filtering (for fallback lookups)

func (*Client) ListManagedAPIs

func (c *Client) ListManagedAPIs(ctx context.Context, namespaces []string) ([]API, error)

ListManagedAPIs returns all KONGCTL-managed APIs in the specified namespaces If namespaces is empty, no resources are returned (breaking change from previous behavior) To get all managed resources across all namespaces, pass []string{"*"}

func (*Client) ListManagedAuthStrategies

func (c *Client) ListManagedAuthStrategies(
	ctx context.Context, namespaces []string,
) ([]ApplicationAuthStrategy, error)

ListManagedAuthStrategies returns all KONGCTL-managed auth strategies in the specified namespaces If namespaces is empty, no resources are returned (breaking change from previous behavior) To get all managed resources across all namespaces, pass []string{"*"}

func (*Client) ListManagedPortalPages

func (c *Client) ListManagedPortalPages(ctx context.Context, portalID string) ([]PortalPage, error)

ListManagedPortalPages returns all KONGCTL-managed portal pages for a portal

func (*Client) ListManagedPortals

func (c *Client) ListManagedPortals(ctx context.Context, namespaces []string) ([]Portal, error)

ListManagedPortals returns all KONGCTL-managed portals in the specified namespaces If namespaces is empty, no resources are returned (breaking change from previous behavior) To get all managed resources across all namespaces, pass []string{"*"}

func (*Client) ListPortalSnippets

func (c *Client) ListPortalSnippets(ctx context.Context, portalID string) ([]PortalSnippet, error)

ListPortalSnippets returns all snippets for a portal

func (*Client) UpdateAPI

UpdateAPI updates an existing API with new management labels

func (*Client) UpdateAPIDocument

func (c *Client) UpdateAPIDocument(
	ctx context.Context, apiID, documentID string, document kkComps.APIDocument,
) (*kkComps.APIDocumentResponse, error)

UpdateAPIDocument updates an existing API document

func (*Client) UpdateApplicationAuthStrategy

func (c *Client) UpdateApplicationAuthStrategy(
	ctx context.Context,
	id string,
	authStrategy kkComps.UpdateAppAuthStrategyRequest,
	_ string,
) (*kkOps.UpdateAppAuthStrategyResponse, error)

UpdateApplicationAuthStrategy updates an existing auth strategy with new management labels

func (*Client) UpdatePortal

func (c *Client) UpdatePortal(
	ctx context.Context,
	id string,
	portal kkComps.UpdatePortal,
	_ string,
) (*kkComps.PortalResponse, error)

UpdatePortal updates an existing portal with new management labels

func (*Client) UpdatePortalCustomDomain

func (c *Client) UpdatePortalCustomDomain(
	ctx context.Context,
	portalID string,
	req kkComps.UpdatePortalCustomDomainRequest,
) error

UpdatePortalCustomDomain updates a portal custom domain

func (*Client) UpdatePortalCustomization

func (c *Client) UpdatePortalCustomization(
	ctx context.Context,
	portalID string,
	customization kkComps.PortalCustomization,
) error

UpdatePortalCustomization updates portal customization settings

func (*Client) UpdatePortalPage

func (c *Client) UpdatePortalPage(
	ctx context.Context,
	portalID string,
	pageID string,
	req kkComps.UpdatePortalPageRequest,
) error

UpdatePortalPage updates an existing page in a portal

func (*Client) UpdatePortalSnippet

func (c *Client) UpdatePortalSnippet(
	ctx context.Context,
	portalID string,
	snippetID string,
	req kkComps.UpdatePortalSnippetRequest,
) error

UpdatePortalSnippet updates an existing snippet in a portal

type ClientConfig

type ClientConfig struct {
	// Core APIs
	PortalAPI  helpers.PortalAPI
	APIAPI     helpers.APIAPI
	AppAuthAPI helpers.AppAuthStrategiesAPI

	// Portal child resource APIs
	PortalPageAPI          helpers.PortalPageAPI
	PortalCustomizationAPI helpers.PortalCustomizationAPI
	PortalCustomDomainAPI  helpers.PortalCustomDomainAPI
	PortalSnippetAPI       helpers.PortalSnippetAPI

	// API child resource APIs
	APIVersionAPI        helpers.APIVersionAPI
	APIPublicationAPI    helpers.APIPublicationAPI
	APIImplementationAPI helpers.APIImplementationAPI
	APIDocumentAPI       helpers.APIDocumentAPI
}

ClientConfig contains all the API interfaces needed by the state client

type ErrorWrapperOptions

type ErrorWrapperOptions struct {
	ResourceType string
	ResourceName string
	Namespace    string
	StatusCode   int
	UseEnhanced  bool // Whether to use enhanced error with context
}

ErrorWrapperOptions configures how API errors are wrapped

type FilteredPaginatedLister

type FilteredPaginatedLister[T any] func(
	ctx context.Context, pageSize, pageNumber int64, filter func(T) bool,
) ([]T, *PageMeta, error)

FilteredPaginatedLister wraps a PaginatedLister with additional filtering logic

type PageMeta

type PageMeta struct {
	Total float64
}

PageMeta contains pagination metadata from API responses

type PaginatedLister

type PaginatedLister[T any] func(ctx context.Context, pageSize, pageNumber int64) ([]T, *PageMeta, error)

PaginatedLister is a function type that can fetch a page of results

type Portal

type Portal struct {
	kkComps.Portal
	NormalizedLabels map[string]string // Non-pointer labels
}

Portal represents a normalized portal for internal use

type PortalCustomDomain

type PortalCustomDomain struct {
}

PortalCustomDomain represents portal custom domain (placeholder for missing type)

type PortalCustomization

type PortalCustomization struct {
}

PortalCustomization represents portal customization (placeholder for missing type)

type PortalPage

type PortalPage struct {
	ID               string
	Slug             string
	Title            string
	Content          string // Will be empty from list, populated from fetch
	Description      string
	Visibility       string
	Status           string
	ParentPageID     string
	NormalizedLabels map[string]string
}

PortalPage represents a portal page for internal use

type PortalSnippet

type PortalSnippet struct {
	ID               string
	Name             string
	Title            string
	Content          string // Will be empty from list, populated from fetch
	Description      string
	Visibility       string
	Status           string
	NormalizedLabels map[string]string
}

PortalSnippet represents portal snippet

type ResponseValidationError

type ResponseValidationError struct {
	Operation    string
	ExpectedType string
}

ResponseValidationError represents an error when API response is missing expected data

func (*ResponseValidationError) Error

func (e *ResponseValidationError) Error() string

Jump to

Keyboard shortcuts

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