migrations

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateRegisteredResources

func MigrateRegisteredResources(ctx context.Context, h MigrationHandler, prompter MigrationPrompter, commit, interactive bool) error

MigrateRegisteredResources is the main entry point for migrating registered resources to namespaces.

Types

type HuhPrompter

type HuhPrompter struct{}

HuhPrompter implements MigrationPrompter using charmbracelet/huh forms.

func (*HuhPrompter) ConfirmBackup

func (p *HuhPrompter) ConfirmBackup() (bool, error)

func (*HuhPrompter) ConfirmResourceNamespace

func (p *HuhPrompter) ConfirmResourceNamespace(resourceName, detectedNamespaceFQN string) (string, error)

func (*HuhPrompter) SelectBatchNamespace

func (p *HuhPrompter) SelectBatchNamespace(nsList []*policy.Namespace) (string, error)

func (*HuhPrompter) SelectResourceNamespace

func (p *HuhPrompter) SelectResourceNamespace(resourceName string, nsList []*policy.Namespace) (string, error)

type MigrationHandler

type MigrationHandler interface {
	ListRegisteredResources(ctx context.Context, limit, offset int32, namespace string) (*registeredresources.ListRegisteredResourcesResponse, error)
	ListRegisteredResourceValues(ctx context.Context, resourceID string, limit, offset int32) (*registeredresources.ListRegisteredResourceValuesResponse, error)
	CreateRegisteredResource(ctx context.Context, namespace, name string, values []string, metadata *common.MetadataMutable) (*policy.RegisteredResource, error)
	CreateRegisteredResourceValue(ctx context.Context, resourceID string, value string, actionAttributeValues []*registeredresources.ActionAttributeValue, metadata *common.MetadataMutable) (*policy.RegisteredResourceValue, error)
	DeleteRegisteredResource(ctx context.Context, id string) error
	ListNamespaces(ctx context.Context, state common.ActiveStateEnum, limit, offset int32) (*namespaces.ListNamespacesResponse, error)
}

MigrationHandler defines the handler methods needed for registered resource migration. handlers.Handler satisfies this interface implicitly.

type MigrationPrompter

type MigrationPrompter interface {
	// ConfirmBackup prompts the user to confirm they have taken a backup.
	ConfirmBackup() (bool, error)

	// SelectBatchNamespace prompts the user to select one namespace for all resources.
	SelectBatchNamespace(nsList []*policy.Namespace) (string, error)

	// SelectResourceNamespace prompts the user to select a namespace for a specific resource.
	// The returned string may be a namespace FQN/ID, optSkipResource, or optAbortAll.
	SelectResourceNamespace(resourceName string, nsList []*policy.Namespace) (string, error)

	// ConfirmResourceNamespace shows the auto-detected namespace and asks the user to confirm,
	// skip the resource, or abort. Returns the namespace FQN, optSkipResource, or optAbortAll.
	ConfirmResourceNamespace(resourceName, detectedNamespaceFQN string) (string, error)
}

MigrationPrompter abstracts interactive prompts so they can be mocked in tests.

type RegisteredResourceMigrationPlan

type RegisteredResourceMigrationPlan struct {
	Resource        *policy.RegisteredResource
	Values          []*policy.RegisteredResourceValue
	TargetNamespace string // namespace FQN or ID to migrate to
	Commit          bool
}

RegisteredResourceMigrationPlan holds an existing resource with its values and the target namespace.

Jump to

Keyboard shortcuts

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