Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyPagination[T any](items []T, limit, page int64) ([]T, int64)
- func BoolPtr(b bool) *bool
- func DefaultFilterPaths() []string
- func ExtractAndValidateFormat(params map[string]interface{}) (string, error)
- func ExtractBool(params map[string]interface{}, key string, defaultValue bool) bool
- func ExtractFormat(params map[string]interface{}) string
- func ExtractInt64(params map[string]interface{}, key string, defaultValue int64) int64
- func ExtractOptionalInt64(params map[string]interface{}, key string) *int64
- func ExtractOptionalString(params map[string]interface{}, key string) string
- func ExtractOptionalStringWithDefault(params map[string]interface{}, key, defaultValue string) string
- func ExtractRequiredString(params map[string]interface{}, key string) (string, error)
- func FilterFields(data []map[string]string, fields []string) []map[string]string
- func FormatAsJSON(data interface{}) (string, error)
- func FormatAsTable(data []map[string]string, headers []string) string
- func FormatAsYAML(data interface{}) (string, error)
- func FormatEmptyResult(format string) (string, error)
- func FormatOutput(data []map[string]string, format string, headers []string, fields []string) (string, error)
- func FormatSingleResult(data map[string]interface{}, format string, tableHeaders ...string) (string, error)
- func FormatTime(timestamp string) string
- func FormatWithFields(data []map[string]string, fields []string, format string) (string, error)
- func GetStringValue(v interface{}) string
- func ResolveCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)
- func ResolveOptionalCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)
- func ResolveOptionalProject(ctx context.Context, client *norman.Client, params map[string]interface{}, ...) (string, error)
- func ValidateFormat(format string) error
- type ResourceFilter
Constants ¶
const ( FormatJSON = "json" FormatYAML = "yaml" FormatTable = "table" )
Format constants
const ( ParamCluster = "cluster" ParamNamespace = "namespace" ParamProject = "project" ParamFormat = "format" ParamName = "name" ParamUser = "user" ParamContainer = "container" ParamTailLines = "tailLines" ParamSinceSeconds = "sinceSeconds" ParamTimestamps = "timestamps" // Kubernetes toolset parameters ParamKind = "kind" ParamLabelSelector = "labelSelector" ParamLimit = "limit" ParamResource = "resource" ParamPatch = "patch" ParamPrevious = "previous" ParamPage = "page" )
Parameter name constants
Variables ¶
var ( ErrRancherNotConfigured = errors.New("rancher client not configured, please configure rancher credentials to use this tool") ErrSteveNotConfigured = errors.New("kubernetes client not configured, please configure rancher credentials to use this tool") ErrInvalidFormat = errors.New("invalid output format") ErrMissingParameter = errors.New("missing required parameter") ErrReadOnlyMode = errors.New("operation not allowed: server is running in read-only mode") ErrDestructiveDisabled = errors.New("operation not allowed: destructive operations are disabled") )
Error definitions
Functions ¶
func ApplyPagination ¶
ApplyPagination applies limit and page to a slice, returns paginated slice and total count.
func DefaultFilterPaths ¶
func DefaultFilterPaths() []string
DefaultFilterPaths returns recommended default filter paths for reducing output verbosity. Users can use these as a starting point for their configuration.
func ExtractAndValidateFormat ¶
ExtractAndValidateFormat extracts format parameter and validates it. Returns validated format or error if format is invalid.
func ExtractBool ¶
ExtractBool extracts a boolean parameter with a default value
func ExtractFormat ¶
ExtractFormat extracts the format parameter with "json" as default.
func ExtractInt64 ¶
ExtractInt64 extracts an int64 parameter with a default value
func ExtractOptionalInt64 ¶
ExtractOptionalInt64 extracts an optional int64 parameter
func ExtractOptionalString ¶
ExtractOptionalString extracts an optional string parameter. Returns empty string if the parameter is missing or empty.
func ExtractOptionalStringWithDefault ¶
func ExtractOptionalStringWithDefault(params map[string]interface{}, key, defaultValue string) string
ExtractOptionalStringWithDefault extracts an optional string parameter with a default value. Returns defaultValue if the parameter is missing or empty.
func ExtractRequiredString ¶
ExtractRequiredString extracts a required string parameter from params map. Returns ErrMissingParameter if the parameter is missing or empty.
func FilterFields ¶
FilterFields filters map data to include only specified fields If fields is nil or empty, returns data unchanged
func FormatAsJSON ¶
FormatAsJSON formats data as JSON
func FormatAsTable ¶
FormatAsTable formats data as a table with headers
func FormatAsYAML ¶
FormatAsYAML formats data as YAML
func FormatEmptyResult ¶
FormatEmptyResult formats an empty result based on the output format.
func FormatOutput ¶
func FormatOutput(data []map[string]string, format string, headers []string, fields []string) (string, error)
FormatOutput is a generic helper for formatting slice data in different output formats. It reduces code duplication across handlers by consolidating the format switch logic. If fields is provided, only those fields will be included in the output.
func FormatSingleResult ¶
func FormatSingleResult(data map[string]interface{}, format string, tableHeaders ...string) (string, error)
FormatSingleResult formats a single result object (map[string]interface{}) in the specified format. This is useful for get handlers that return a single resource. tableHeaders is optional - if provided and format is "table", it renders a table with those fields.
func FormatTime ¶
FormatTime formats time for display. Returns "-" for empty timestamps.
func FormatWithFields ¶
FormatWithFields formats data with specific fields only If fields is empty, includes all fields
func GetStringValue ¶
func GetStringValue(v interface{}) string
GetStringValue extracts string value from interface safely. Returns "-" for nil values.
func ResolveCluster ¶
func ResolveCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)
ResolveCluster extracts cluster parameter and resolves it via fuzzy lookup Supports: exact ID, exact name, or partial name match Returns the resolved cluster ID
func ResolveOptionalCluster ¶
func ResolveOptionalCluster(ctx context.Context, client *norman.Client, params map[string]interface{}) (string, error)
ResolveOptionalCluster extracts optional cluster parameter and resolves it via fuzzy lookup Returns empty string if cluster is not specified Supports: exact ID, exact name, or partial name match
func ResolveOptionalProject ¶
func ResolveOptionalProject(ctx context.Context, client *norman.Client, params map[string]interface{}, clusterID string) (string, error)
ResolveOptionalProject extracts optional project parameter and resolves it via fuzzy lookup Returns empty string if project is not specified Supports: exact ID, exact name, or partial name match
func ValidateFormat ¶
ValidateFormat validates that the format is one of the supported formats
Types ¶
type ResourceFilter ¶
type ResourceFilter struct {
// contains filtered or unexported fields
}
ResourceFilter provides configurable filtering for Kubernetes resources. It removes specified fields from resources based on user-configured paths.
func NewResourceFilter ¶
func NewResourceFilter(paths []string) *ResourceFilter
NewResourceFilter creates a new ResourceFilter with the specified paths.
func NewResourceFilterFromParams ¶
func NewResourceFilterFromParams(params map[string]interface{}) *ResourceFilter
NewResourceFilterFromParams creates a ResourceFilter from handler params. Returns nil if no filters are configured.
func (*ResourceFilter) Filter ¶
func (f *ResourceFilter) Filter(obj *unstructured.Unstructured) *unstructured.Unstructured
Filter removes the configured fields from a resource and returns a cleaned copy. The original resource is not modified.
func (*ResourceFilter) FilterList ¶
func (f *ResourceFilter) FilterList(list *unstructured.UnstructuredList) *unstructured.UnstructuredList
FilterList applies filtering to all resources in a list.