Documentation ¶
Overview ¶
Code in this file uses the Nuke data type defined in nuke.go to provider helpers for aws-nuke.
Package libnukemod contains copies of code from the libnuke project https://github.com/ekristen/libnuke and modifications to it. In order to integrate with reaper, the resources observed by libnuke needed to be converted into the resource data type of the reaper, so that the list of resources can be printed in a coherent manner across all the different providers. For this, the Nuke.Run() command, which combines scan and delete, had to be split into separate steps. Hence, the mods.go adds Delete() to Nuke. The Nuke.Scan() function prints all the scanned resources. This breaks the reaper interface. Scan() is modified to not print the resources. To support the retain-period feature of reaper, aws-nuke needs to understand the custom timestamp that test-env uses. Since the default aws-nuke filters can't be appended without copying and modifying more code, ApplyRetentionFilter() is introduced. This allows applying the filter on the items after gathering all the resources and before deleting them.
Code in this file extends the Nuke data type defined in nuke.go and adds other helpers for using libnuke.
Index ¶
- func ApplyRetentionFilter(n *Nuke, period string) error
- type INuke
- type ListCache
- type MockResource
- type Nuke
- func (n *Nuke) Delete(ctx context.Context) error
- func (n *Nuke) Filter(item *queue.Item) error
- func (n *Nuke) HandleQueue(ctx context.Context)
- func (n *Nuke) HandleRemove(ctx context.Context, item *queue.Item)
- func (n *Nuke) HandleWait(ctx context.Context, item *queue.Item, cache ListCache)
- func (n *Nuke) HandleWaitDependency(ctx context.Context, item *queue.Item)
- func (n *Nuke) Prompt() error
- func (n *Nuke) RegisterPrompt(prompt func() error)
- func (n *Nuke) RegisterResourceTypes(scope registry.Scope, resourceTypes ...string)
- func (n *Nuke) RegisterScanner(scope registry.Scope, instance *scanner.Scanner) error
- func (n *Nuke) RegisterValidateHandler(handler func() error)
- func (n *Nuke) RegisterVersion(version string)
- func (n *Nuke) Run(ctx context.Context) error
- func (n *Nuke) Scan(ctx context.Context) error
- func (n *Nuke) SetLogger(logger *logrus.Entry)
- func (n *Nuke) SetRunSleep(duration time.Duration)
- func (n *Nuke) Validate() error
- func (n *Nuke) Version()
- type Parameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyRetentionFilter ¶
ApplyRetentionFilter applies the retention filter on the Nuke queue items that are to be removed. It only alters the items that were already selected for removal by checking if the retention period applies to them. If an item is to be removed but don't contain the createdat tag, it is filtered to not be removed. This function reduces the number of items to be removed or keeps them the same as before. It never increases the items to be deleted.
Types ¶
type MockResource ¶
type MockResource struct { ARN string Tags types.Properties RemoveError error }
func MockResourceWithTags ¶
func MockResourceWithTags(arn string, props map[string]string) MockResource
func (MockResource) Properties ¶
func (mr MockResource) Properties() types.Properties
func (MockResource) String ¶
func (mr MockResource) String() string
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 SetUpLibnukeAWS ¶
func SetUpLibnukeAWS(ctx context.Context, accountID string, defaultRegion string, cfg config.Config) (*Nuke, error)
SetUpLibnukeAWS configures and returns Nuke for AWS. This is based on the aws-nuke nuke command.
func (*Nuke) Delete ¶
Delete deletes the resources. This deletes the existing scanned items in nuke, skipping a re-scan and summarizes the result of delete.
func (*Nuke) Filter ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) RegisterPrompt ¶
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 ¶
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 ¶
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 ¶
RegisterValidateHandler allows the tool instantiating the library to register a validation handler. It is optional.
func (*Nuke) RegisterVersion ¶
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 ¶
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 ¶
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 ¶
SetLogger allows the tool instantiating the library to set the logger that is used for the library. It is optional.
func (*Nuke) SetRunSleep ¶
SetRunSleep allows the tool instantiating the library to set the sleep duration between runs of the queue. It is optional.
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 // 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.