Documentation
¶
Overview ¶
Package io provides utilities for input and output operations.
This package contains utilities for reading from and writing to files, along with various I/O helper functions for file operations, including configuration validation utilities.
Key functionality:
- File reading: ReadFileSafe, FindFile
- File writing: TryWriteFile
- Path operations: ExpandHomePath
- String utilities: TrimNonEmpty
Subpackages:
- config-manager: Configuration loading and management
- generator: Template and configuration generation
- marshaller: Serialization and deserialization
- scaffolder: Project scaffolding and file generation
- validator: Configuration validation
Index ¶
- Variables
- func ExpandHomePath(path string) (string, error)
- func FindFile(filePath string) (string, error)
- func ReadFileSafe(basePath, filePath string) ([]byte, error)
- func TrimNonEmpty(s string) (string, bool)
- func TryWriteFile(content string, output string, force bool) (string, error)
- type OCIReference
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPathOutsideBase is returned when a file path is outside the specified base directory. ErrPathOutsideBase = errors.New("invalid path: file is outside base directory") // ErrEmptyOutputPath is returned when the output path is empty. ErrEmptyOutputPath = errors.New("output path cannot be empty") // ErrBasePath is returned when the base path is empty. ErrBasePath = errors.New("base path cannot be empty") )
File operation errors.
var ( // ErrInvalidOCIScheme is returned when an OCI reference doesn't start with 'oci://'. ErrInvalidOCIScheme = errors.New("OCI reference must start with 'oci://'") // ErrInvalidOCIFormat is returned when the OCI reference format is invalid. ErrInvalidOCIFormat = errors.New( "invalid OCI reference format; expected oci://<host>:<port>/<repository>[/<variant>]:<ref>", ) // ErrInvalidPort is returned when the port in an OCI reference is invalid. ErrInvalidPort = errors.New("invalid port number in OCI reference") )
OCI reference parsing errors.
Functions ¶
func ExpandHomePath ¶
ExpandHomePath expands a path beginning with ~/ to the user's home directory and converts relative paths to absolute paths.
Parameters:
- path: The path to expand (e.g., "~/config.yaml", "./config.yaml", or "/absolute/path")
Returns:
- string: The expanded and absolute path
- error: Error if unable to get current user information or convert to absolute path
func FindFile ¶
FindFile resolves a file path with directory traversal. For absolute paths, returns the path as-is. For relative paths, traverses up from the current directory to find the file.
Parameters:
- filePath: The file path to resolve
Returns:
- string: The resolved absolute path if found, or the original path if not found
- error: Error if unable to get current directory
func ReadFileSafe ¶
ReadFileSafe reads the file at filePath only if it is located within basePath. It resolves absolute paths and rejects reads where the resolved path is outside basePath (prevents path traversal and accidental file inclusion).
Parameters:
- basePath: The base directory that filePath must be within
- filePath: The file path to read (must be within basePath)
Returns:
- []byte: The file contents
- error: ErrPathOutsideBase if path is outside base, or read error
func TrimNonEmpty ¶
TrimNonEmpty returns the trimmed string and whether it's non-empty. This consolidates the common pattern of trimming and checking for emptiness.
Parameters:
- s: The string to trim and check
Returns:
- string: The trimmed string
- bool: True if the trimmed string is non-empty, false otherwise
func TryWriteFile ¶
TryWriteFile writes content to a file path, handling force/overwrite logic. It validates that the output path doesn't contain path traversal attempts.
Parameters:
- content: The content to write to the file
- output: The output file path
- force: If true, overwrites existing files; if false, skips existing files
Returns:
- string: The content that was written (for chaining)
- error: ErrEmptyOutputPath if output is empty, or write error
Caller responsibilities:
- Ensure the output path is within intended bounds
- Handle the returned content appropriately
Types ¶
type OCIReference ¶ added in v5.13.0
OCIReference represents a parsed OCI artifact reference. Format: oci://<host>:<port>/<repository>/<optional-variant>:<ref>
func ParseOCIReference ¶ added in v5.13.0
func ParseOCIReference(ref string) (*OCIReference, error)
ParseOCIReference parses an OCI reference string into its components. Format: oci://<host>:<port>/<repository>/<optional-variant>:<ref> Returns nil (not an error) when ref is empty, indicating defaults should be used. Examples:
- oci://localhost:5111/k8s:dev
- oci://localhost:5111/my-app/base:v1.0.0
- oci://registry.example.com:443/workloads:latest
func (*OCIReference) FullRepository ¶ added in v5.13.0
func (r *OCIReference) FullRepository() string
FullRepository returns the complete repository path including variant.
func (*OCIReference) String ¶ added in v5.13.0
func (r *OCIReference) String() string
String returns the full OCI reference string.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package configmanager provides centralized configuration management for KSail.
|
Package configmanager provides centralized configuration management for KSail. |
|
k3d
Package k3d provides configuration management for K3d clusters.
|
Package k3d provides configuration management for K3d clusters. |
|
kind
Package kind provides configuration management for Kind clusters.
|
Package kind provides configuration management for Kind clusters. |
|
ksail
Package configmanager provides configuration management for KSail v1alpha1.Cluster configurations.
|
Package configmanager provides configuration management for KSail v1alpha1.Cluster configurations. |
|
loader
Package loader provides common functionality for config managers to eliminate duplication.
|
Package loader provides common functionality for config managers to eliminate duplication. |
|
talos
Package talos provides configuration management for Talos cluster patches.
|
Package talos provides configuration management for Talos cluster patches. |
|
Package detector provides utilities for detecting existing Kubernetes resources in the source directory, such as GitOps Custom Resources managed by KSail.
|
Package detector provides utilities for detecting existing Kubernetes resources in the source directory, such as GitOps Custom Resources managed by KSail. |
|
Package generator provides an interface for generating files from code.
|
Package generator provides an interface for generating files from code. |
|
argocd
Package argocd provides generators for ArgoCD GitOps resources.
|
Package argocd provides generators for ArgoCD GitOps resources. |
|
flux
Package flux provides generators for Flux GitOps resources.
|
Package flux provides generators for Flux GitOps resources. |
|
k3d
Package k3dgenerator provides utilities for generating K3d cluster configurations.
|
Package k3dgenerator provides utilities for generating K3d cluster configurations. |
|
kind
Package kindgenerator provides utilities for generating Kind cluster configurations.
|
Package kindgenerator provides utilities for generating Kind cluster configurations. |
|
kustomization
Package kustomizationgenerator provides utilities for generating kustomization.yaml files.
|
Package kustomizationgenerator provides utilities for generating kustomization.yaml files. |
|
talos
Package talosgenerator provides a generator for Talos project scaffolding.
|
Package talosgenerator provides a generator for Talos project scaffolding. |
|
yaml
Package yamlgenerator provides YAML generation functionality for arbitrary models.
|
Package yamlgenerator provides YAML generation functionality for arbitrary models. |
|
Package marshaller provides functionality for marshaling and unmarshaling resources.
|
Package marshaller provides functionality for marshaling and unmarshaling resources. |
|
Package scaffolder provides utilities for scaffolding KSail project files and configuration.
|
Package scaffolder provides utilities for scaffolding KSail project files and configuration. |
|
Package validator provides interfaces for configuration file validation.
|
Package validator provides interfaces for configuration file validation. |
|
k3d
Package k3d provides K3d configuration validation functionality.
|
Package k3d provides K3d configuration validation functionality. |
|
kind
Package kind provides Kind configuration validation functionality.
|
Package kind provides Kind configuration validation functionality. |
|
ksail
Package ksail provides validation for KSail cluster configurations.
|
Package ksail provides validation for KSail cluster configurations. |