nuke

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 15 Imported by: 8

Documentation

Overview

Package nuke provides the framework for scanning for resources and then iterating over said resources to determine if they should be removed or not and in what order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type INuke

type INuke interface {
	Run() error
	Scan() error
	Filter(item *queue.Item) error
	HandleQueue()
	HandleRemove(item *queue.Item)
	HandleWait(item *queue.Item, cache ListCache)
}

type ListCache

type ListCache map[string]map[string][]resource.Resource

ListCache is used to cache the list of resources that are returned from the API.

type Nuke

type Nuke struct {
	Parameters *Parameters           // Parameters is a collection of common variables used to configure the before of the Nuke instance.
	Filters    filter.Filters        // Filters is the collection of filters that will be used to filter resources
	Settings   *libsettings.Settings // Settings is the collection of settings that will be used to control resource behavior

	ValidateHandlers []func() error
	ResourceTypes    map[registry.Scope]types.Collection
	Scanners         map[registry.Scope][]*scanner.Scanner
	Queue            *queue.Queue // Queue is the queue of resources that will be processed
	// contains filtered or unexported fields
}

Nuke is the main struct for the library. It is used to register resource types, scanners, filters and validation handlers.

func New

func New(params *Parameters, filters filter.Filters, settings *libsettings.Settings) *Nuke

New returns an instance of nuke that is properly configured for initial use

func (*Nuke) Filter

func (n *Nuke) Filter(item *queue.Item) error

Filter is used to filter resources. It will run the filters that were registered with the instance of Nuke and set the state of the resource to filtered if it matches the filter.

func (*Nuke) HandleQueue

func (n *Nuke) HandleQueue(ctx context.Context)

HandleQueue is used to handle the queue of resources. It will iterate over the queue and trigger the appropriate handlers based on the state of the resource.

func (*Nuke) HandleRemove

func (n *Nuke) HandleRemove(ctx context.Context, item *queue.Item)

HandleRemove is used to handle the removal of a resource. It will remove the resource and set the state of the resource to pending if it was successful or failed if it was not.

func (*Nuke) HandleWait

func (n *Nuke) HandleWait(ctx context.Context, item *queue.Item, cache ListCache)

HandleWait is used to handle the waiting of a resource. It will check if the resource has been removed. If it has, it will set the state of the resource to finished. If it has not, it will set the state of the resource to waiting.

func (*Nuke) HandleWaitDependency

func (n *Nuke) HandleWaitDependency(ctx context.Context, item *queue.Item)

HandleWaitDependency is used to handle the waiting of a resource. It will check if the resource has any dependencies and if it does, it will check if the dependencies have been removed. If they have, it will trigger the remove handler.

func (*Nuke) Prompt

func (n *Nuke) Prompt() error

Prompt actually calls the registered prompt function as part of the run

func (*Nuke) RegisterPrompt

func (n *Nuke) RegisterPrompt(prompt func() error)

RegisterPrompt is used to register the prompt function that used to prompt the user for input, usually to confirm if the nuke process should continue or not.

func (*Nuke) RegisterResourceTypes

func (n *Nuke) RegisterResourceTypes(scope registry.Scope, resourceTypes ...string)

RegisterResourceTypes is used to register resource types against a scope. A scope is a string that is used to group resource types together. For example, you could have a scope of "aws" and register all AWS resource types. For Azure, you have to register resources by tenant or subscription or even resource group.

func (*Nuke) RegisterScanner

func (n *Nuke) RegisterScanner(scope registry.Scope, instance *scanner.Scanner) error

RegisterScanner is used to register a scanner against a scope. A scope is a string that is used to group resource types together. A scanner is what is responsible for actually querying the API for resources and adding them to the queue for processing.

func (*Nuke) RegisterValidateHandler

func (n *Nuke) RegisterValidateHandler(handler func() error)

RegisterValidateHandler allows the tool instantiating the library to register a validation handler. It is optional.

func (*Nuke) RegisterVersion

func (n *Nuke) RegisterVersion(version string)

RegisterVersion allows the tool instantiating the library to register its version so there's consist output of the version information across all tools. It is optional.

func (*Nuke) Run

func (n *Nuke) Run(ctx context.Context) error

Run is the main entry point for the library. It will run the validation handlers, prompt the user, scan for resources, filter them and then process them.

func (*Nuke) Scan

func (n *Nuke) Scan(ctx context.Context) error

Scan is used to scan for resources. It will run the scanners that were registered with the library by the invoking tool. It will also filter the resources based on the filters that were registered. It will also print the current status of the resources.

func (*Nuke) SetLogger

func (n *Nuke) SetLogger(logger *logrus.Entry)

SetLogger allows the tool instantiating the library to set the logger that is used for the library. It is optional.

func (*Nuke) SetRunSleep

func (n *Nuke) SetRunSleep(duration time.Duration)

SetRunSleep allows the tool instantiating the library to set the sleep duration between runs of the queue. It is optional.

func (*Nuke) Validate

func (n *Nuke) Validate() error

Validate is used to run the validation handlers that were registered with the library by the invoking tool.

func (*Nuke) Version

func (n *Nuke) Version()

Version prints the version that was registered with the library by the invoking tool.

type Parameters

type Parameters struct {
	NoDryRun       bool // NoDryRun instructs Run to actually perform the remove function
	Force          bool // Force instructs Run to proceed without confirmation from user
	ForceSleep     int  // ForceSleep indicates how long of a delay before proceeding with confirmation
	Quiet          bool // Quiet will hide resources if they have been filtered
	MaxWaitRetries int  // MaxWaitRetries is the total number of times a resource will be retried during wait state

	// WaitOnDependencies controls whether resources will be removed after their dependencies. It is important to note
	// that it does not currently track direct dependencies but instead dependent resources. For example if ResourceA
	// depends on ResourceB, all ResourceB has to be in a completed state (removed or failed) before ResourceA will be
	// processed
	WaitOnDependencies bool

	// UseFilterGroups controls whether the filter groups are used or not. If set to true, then the filters will be
	// processed by groups, where each group is a list of filters that are processed together. A single filter in a
	// group must match for the group to match. If set to false, then the filters will be processed individually and
	// a single filter must match for the resource to be filtered.
	UseFilterGroups bool

	// Includes is a list of resource types that are to be included during the nuke process. If a resource type is
	// listed in both the Includes and Excludes fields then the Excludes field will take precedence.
	Includes []string

	// Excludes is a list of resource types that are to be excluded during the nuke process. If a resource type is
	// listed in both the Includes and Excludes fields then the Excludes field will take precedence.
	Excludes []string

	// Alternatives is a list of resource types that are to be used instead of the default resource. The primary use
	// case for this is AWS Cloud Control API resources.
	Alternatives []string
}

Parameters is a collection of common variables used to configure the before of the Nuke instance.

Jump to

Keyboard shortcuts

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