common

package
v0.3.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmExecution

func ConfirmExecution(plan *planner.Plan, _, stderr io.Writer, stdin io.Reader) bool

ConfirmExecution prompts for confirmation. Returns true if the user confirms with 'yes', false otherwise.

func CopyField

func CopyField(dest, src map[string]any, key string)

CopyField copies a field from source to destination map if it exists

func DisplayPlanSummary

func DisplayPlanSummary(plan *planner.Plan, out io.Writer)

DisplayPlanSummary shows an enhanced summary of the plan with better formatting, field-level changes, protected resource warnings, and comprehensive statistics.

func ExtractResourceID

func ExtractResourceID(fields map[string]any) string

ExtractResourceID extracts the resource ID from fields map

func ExtractResourceInfoFromChange

func ExtractResourceInfoFromChange(change planner.PlannedChange) (resourceType, resourceName string)

ExtractResourceInfoFromChange gets resource type and name from a planned change

func ExtractResourceName

func ExtractResourceName(fields map[string]any) string

ExtractResourceName extracts the resource name from fields map

func FormatAPIError

func FormatAPIError(resourceType, resourceName, operation string, err error) error

FormatAPIError wraps API errors with resource context

func FormatDependencyError

func FormatDependencyError(resourceType, resourceName, dependencyType, dependencyRef string) error

FormatDependencyError creates an error for dependency resolution failures

func FormatExecutionError

func FormatExecutionError(resourceType, resourceName, action, errorMsg string) error

FormatExecutionError creates a standardized error message for execution failures

func FormatProtectionError

func FormatProtectionError(resourceType, resourceName, action string) error

FormatProtectionError creates a standardized error message for protection violations

func FormatResourceExistsError

func FormatResourceExistsError(resourceType, resourceName string) error

FormatResourceExistsError creates a standardized error for resources that already exist

func FormatResourceNotFoundError

func FormatResourceNotFoundError(resourceType, resourceName string) error

FormatResourceNotFoundError creates a standardized error for missing resources

func FormatValidationError

func FormatValidationError(resourceType, resourceName, reason string) error

FormatValidationError creates a standardized error message for validation failures

func GetProtectionStatus

func GetProtectionStatus(normalizedLabels map[string]string) bool

GetProtectionStatus extracts the protection status from normalized labels

func HasFieldChanged

func HasFieldChanged(oldFields, newFields map[string]any, key string) bool

HasFieldChanged checks if a field value has changed between old and new maps

func IsProtectionChange

func IsProtectionChange(protection any) bool

IsProtectionChange checks if the change is specifically updating the protection status

func LoadPlan

func LoadPlan(source string, stdin io.Reader) (*planner.Plan, error)

LoadPlan loads a plan from the given source. If source is "-", reads from stdin. Otherwise, reads from the specified file path.

func MapOptionalBoolField

func MapOptionalBoolField(target *bool, source map[string]any, key string)

MapOptionalBoolField maps a boolean field from source map to target pointer if present

func MapOptionalBoolFieldToPtr

func MapOptionalBoolFieldToPtr(target **bool, source map[string]any, key string)

MapOptionalBoolFieldToPtr maps a boolean field to a double pointer (used by SDK types)

func MapOptionalIntField

func MapOptionalIntField(target *int, source map[string]any, key string)

MapOptionalIntField maps an integer field from source map to target pointer if present

func MapOptionalSliceField

func MapOptionalSliceField(target *[]string, source map[string]any, key string)

MapOptionalSliceField maps a slice field from source map to target pointer if present

func MapOptionalStringField

func MapOptionalStringField(target *string, source map[string]any, key string)

MapOptionalStringField maps a string field from source map to target pointer if present

func MapOptionalStringFieldToPtr

func MapOptionalStringFieldToPtr(target **string, source map[string]any, key string)

MapOptionalStringFieldToPtr maps a string field to a double pointer (used by SDK types)

func PaginatedList

func PaginatedList[T any](ctx context.Context, handler PaginationHandler[T]) ([]T, error)

PaginatedList handles pagination logic for any paginated API

func ProcessInBatches

func ProcessInBatches[T any](items []T, batchSize int, processor BatchProcessor[T]) error

ProcessInBatches processes a slice of items in batches

func ValidateRequiredFields

func ValidateRequiredFields(fields map[string]any, requiredFields []string) error

ValidateRequiredFields checks that all required fields are present and non-empty

func ValidateResourceProtection

func ValidateResourceProtection(
	resourceType, resourceName string, isProtected bool,
	change planner.PlannedChange, isProtectionChange bool,
) error

ValidateResourceProtection validates that protected resources are not being modified inappropriately

func WrapWithResourceContext

func WrapWithResourceContext(err error, resourceType, resourceName string) error

WrapWithResourceContext adds resource context to an existing error

Types

type BatchProcessor

type BatchProcessor[T any] func(batch []T) error

BatchProcessor processes items in batches with a given batch size

type PageMeta

type PageMeta struct {
	Total       float64 `json:"total"`
	Page        int64   `json:"page"`
	PageSize    int64   `json:"page_size"`
	HasNextPage bool    `json:"has_next_page"`
}

PageMeta represents pagination metadata returned by APIs

type PaginationHandler

type PaginationHandler[T any] func(pageNumber int64) ([]T, *PageMeta, error)

PaginationHandler defines a function that performs paginated requests Returns: (items, pageInfo, error)

func NewSimplePaginationHandler

func NewSimplePaginationHandler[T any](pageSize int64, fn SimplePaginationFunc[T]) PaginationHandler[T]

type SimplePaginationFunc

type SimplePaginationFunc[T any] func(pageNumber, pageSize int64) ([]T, *PageMeta, error)

SimplePaginationHandler creates a handler for simple pagination scenarios where you just need to call a function with page number and size

Jump to

Keyboard shortcuts

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