util

package
v0.13.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultTimeLayout = "2006-01-02 15:04:05 MST"

DefaultTimeLayout is the standard layout used for displaying timestamps. Includes the local timezone abbreviation to make it clear times are local.

Variables

This section is empty.

Functions

func ConvertJWKToPEM added in v0.13.4

func ConvertJWKToPEM(jwkJSON string) ([]byte, error)

ConvertJWKToPEM converts an Ed25519 JWK to PEM format

func ConvertPEMToJWK added in v0.13.4

func ConvertPEMToJWK(pemData string) (string, error)

ConvertPEMToJWK converts an Ed25519 PEM private key to JWK format

func CopyDir added in v0.13.4

func CopyDir(src, dst string) error

CopyDir recursively copies a directory from src to dst

func CopyFile added in v0.13.4

func CopyFile(src, dst string) error

CopyFile copies a single file from src to dst

func FirstOrDash

func FirstOrDash(items ...string) string

FirstOrDash returns the first non-empty string from the provided items. If all items are empty, it returns "-".

func FormatLocal

func FormatLocal(t time.Time) string

FormatLocal formats the provided time in the user's local timezone. If the time is zero, it returns "-".

func GetKernelClient

func GetKernelClient(cmd *cobra.Command) kernel.Client

GetKernelClient retrieves the kernel client from the command context

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error is a Kernel API error with HTTP 404.

func IsPEMKey added in v0.13.4

func IsPEMKey(data string) bool

IsPEMKey checks if the input string is in PEM format

func JoinOrDash

func JoinOrDash(items ...string) string

JoinOrDash joins the provided strings with ", " as separator. If no items are provided, it returns "-".

func ModifyFile added in v0.13.4

func ModifyFile(path, oldStr, newStr string) error

ModifyFile replaces all occurrences of oldStr with newStr in the file. Returns an error if the pattern is not found in the file

func NewClient

func NewClient(opts ...option.RequestOption) kernel.Client

NewClient returns a kernel API client preconfigured with middleware that detects when a newer CLI/SDK version is required and informs the user.

It mirrors kernel.NewClient but injects an HTTP middleware that intercepts 400 responses with error codes "sdk_upgrade_required" or "sdk_update_required". When encountered, a helpful upgrade message is displayed once per process.

func OrDash

func OrDash(s string) string

OrDash returns the string if non-empty, otherwise returns "-".

func PrintPrettyJSON added in v0.13.4

func PrintPrettyJSON(v RawJSONProvider) error

PrintPrettyJSON prints the raw JSON from an SDK response type with indentation. It uses the RawJSON() method to get the original API response, avoiding zero-value fields that would appear when re-marshaling the Go struct.

func PrintPrettyJSONSlice added in v0.13.4

func PrintPrettyJSONSlice[T RawJSONProvider](items []T) error

PrintPrettyJSONSlice prints a slice of SDK response types as a JSON array. Each element must implement RawJSONProvider.

func Unzip

func Unzip(zipFilePath, destDir string) error

Unzip extracts a zip file to the specified directory

func ValidatePEMKey added in v0.13.4

func ValidatePEMKey(pemData string) error

ValidatePEMKey validates that a PEM-encoded string contains a valid Ed25519 private key

func ZipDirectory

func ZipDirectory(srcDir, destZip string) error

ZipDirectory compresses the given source directory into the destination file path.

Types

type CleanedUpSdkError

type CleanedUpSdkError struct {
	Err error
}

CleanedUpSdkError extracts a message field from the raw JSON resposne. This is the convention we use in the API for error response bodies (400s and 500s)

func (CleanedUpSdkError) Error

func (e CleanedUpSdkError) Error() string

func (CleanedUpSdkError) Unwrap

func (e CleanedUpSdkError) Unwrap() error

type ContextKey

type ContextKey string

ContextKey is the type for context keys

const KernelClientKey ContextKey = "kernel_client"

KernelClientKey is the context key for the kernel client

type RawJSONProvider added in v0.13.4

type RawJSONProvider interface {
	RawJSON() string
}

RawJSONProvider is an interface for SDK types that provide raw JSON responses.

Jump to

Keyboard shortcuts

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