sdk

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sdk provides helper APIs for Go-based kongctl extensions.

Index

Constants

View Source
const (
	// ContextEnvName is the environment variable that points to the extension
	// runtime context file written by the parent kongctl process.
	ContextEnvName = "KONGCTL_EXTENSION_CONTEXT"

	// KonnectPATEnvName carries a transient parent PAT for child extension
	// processes. The runtime context file itself never stores secrets.
	KonnectPATEnvName = "KONGCTL_EXTENSION_KONNECT_PAT" // #nosec G101
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DispatchSessionContext

type DispatchSessionContext struct {
	ID                string   `json:"id"`
	ContributionStack []string `json:"contribution_stack"`
	Depth             int      `json:"depth"`
	MaxDepth          int      `json:"max_depth"`
}

type HostContext

type HostContext struct {
	KongctlPath    string `json:"kongctl_path"`
	KongctlVersion string `json:"kongctl_version"`
}

type InvocationContext

type InvocationContext struct {
	OriginalArgs  []string `json:"original_args"`
	RemainingArgs []string `json:"remaining_args"`
}

type JQContext

type JQContext struct {
	Expression string `json:"expression,omitempty"`
	RawOutput  bool   `json:"raw_output,omitempty"`
	Color      string `json:"color,omitempty"`
	ColorTheme string `json:"color_theme,omitempty"`
}

type MatchedCommandPath

type MatchedCommandPath struct {
	ID          string   `json:"id"`
	ExtensionID string   `json:"extension_id"`
	Path        []string `json:"path"`
}

type Output

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

Output renders extension output using the parent kongctl output settings.

func (Output) Render

func (o Output) Render(display any, raw ...any) error

Render writes display in text mode and raw in structured modes. When raw is omitted, display is used for both text and structured output.

func (Output) WithWriter

func (o Output) WithWriter(w io.Writer) Output

WithWriter returns a copy of the renderer that writes to w.

type OutputContext

type OutputContext struct {
	Format     string    `json:"format"`
	ColorTheme string    `json:"color_theme,omitempty"`
	JQ         JQContext `json:"jq,omitempty"`
}

type ResolvedContext

type ResolvedContext struct {
	Profile          string `json:"profile"`
	BaseURL          string `json:"base_url"`
	Output           string `json:"output"`
	LogLevel         string `json:"log_level"`
	ColorTheme       string `json:"color_theme,omitempty"`
	ConfigFile       string `json:"config_file"`
	ExtensionDataDir string `json:"extension_data_dir"`
	AuthMode         string `json:"auth_mode"`
	AuthSource       string `json:"auth_source"`
}

type RuntimeContext

type RuntimeContext struct {
	SchemaVersion      int                    `json:"schema_version"`
	MatchedCommandPath MatchedCommandPath     `json:"matched_command_path"`
	Invocation         InvocationContext      `json:"invocation"`
	Resolved           ResolvedContext        `json:"resolved"`
	OutputSettings     OutputContext          `json:"output"`
	Host               HostContext            `json:"host"`
	Session            DispatchSessionContext `json:"session"`
}

RuntimeContext is the extension runtime context provided by the parent kongctl process.

func LoadRuntimeContextFile

func LoadRuntimeContextFile(path string) (*RuntimeContext, error)

LoadRuntimeContextFile reads a kongctl extension runtime context file.

func LoadRuntimeContextFromEnv

func LoadRuntimeContextFromEnv() (*RuntimeContext, error)

LoadRuntimeContextFromEnv reads the runtime context file referenced by KONGCTL_EXTENSION_CONTEXT.

func (*RuntimeContext) Args

func (r *RuntimeContext) Args() []string

Args returns the arguments passed through to the extension executable after host-owned flags have been consumed.

func (*RuntimeContext) DataDir

func (r *RuntimeContext) DataDir() string

DataDir returns the stable extension-owned data directory.

func (*RuntimeContext) KongctlCommand

func (r *RuntimeContext) KongctlCommand(ctx context.Context, args ...string) *exec.Cmd

KongctlCommand creates a session-aware child kongctl command.

func (*RuntimeContext) KongctlPath

func (r *RuntimeContext) KongctlPath() string

KongctlPath returns the parent kongctl executable path, falling back to "kongctl" when the runtime context did not provide one.

func (*RuntimeContext) KonnectSDK

func (r *RuntimeContext) KonnectSDK(ctx context.Context) (*konnectsdk.SDK, error)

KonnectSDK returns an authenticated sdk-konnect-go client configured from the parent kongctl invocation context.

func (*RuntimeContext) OriginalArgs

func (r *RuntimeContext) OriginalArgs() []string

OriginalArgs returns the original matched kongctl command path and arguments.

func (*RuntimeContext) Output

func (r *RuntimeContext) Output() Output

Output returns a renderer configured from the runtime context.

func (*RuntimeContext) RunKongctl

func (r *RuntimeContext) RunKongctl(ctx context.Context, args ...string) error

RunKongctl runs a session-aware child kongctl command.

Jump to

Keyboard shortcuts

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