Documentation ¶
Overview ¶
Package utils provides cli specifics methods for interacting with AWS services
Package utils provides cli specifics methods for interacting with AWS services ¶
Package utils provides cli specifics methods for interacting with AWS services ¶
Package utils provides cli specifics methods for interacting with AWS services
Index ¶
- Variables
- func CurrentUTCDateTime() string
- func InitiateTearDown(config models.Config)
- func TimeDiff(startTime, endTime string) string
- func UpdateNukeStats(dt map[string]models.StackDetails)
- type AlertMessage
- type CFNManager
- func (dm CFNManager) AWSSessionAccountID(sess *session.Session) (acID string, err error)
- func (dm CFNManager) DeleteStack(stackName string) error
- func (dm CFNManager) DescribeStack(stackName string) (*cloudformation.Stack, error)
- func (dm CFNManager) ListEnvironmentExports() (map[string][]string, error)
- func (dm CFNManager) ListEnvironmentStacks() (map[string]models.StackDetails, error)
- func (dm CFNManager) ListImports(exportNames []string) (map[string]struct{}, error)
- func (dm CFNManager) ListStackResources(stackName string) ([]*cloudformation.StackResourceSummary, error)
- func (dm CFNManager) RegexMatch(stackName string) bool
- func (dm CFNManager) Session() (*cloudformation.CloudFormation, error)
- type NotificationManager
- func (nm NotificationManager) Alert(am AlertMessage) error
- func (nm NotificationManager) ErrorAlert(am AlertMessage)
- func (nm NotificationManager) GenericAlert(am AlertMessage)
- func (nm NotificationManager) StartAlert(am AlertMessage)
- func (nm NotificationManager) StuckAlert(am AlertMessage)
- func (nm NotificationManager) SuccessAlert(am AlertMessage)
- type S3Manager
- type SlackMessage
Constants ¶
This section is empty.
Variables ¶
var ( // NUKE_START_TIME is the start timestamp of teardown. NUKE_START_TIME = CurrentUTCDateTime() // NUKE_END_TIME is the end timestamp of teardown. NUKE_END_TIME = CurrentUTCDateTime() // AWS_SDK_MAX_RETRY is max retry count for AWS SDK. AWS_SDK_MAX_RETRY int = 5 // TOTAL_STACK_COUNT is the number of stacks found to be eligible for deletion. TOTAL_STACK_COUNT int // DELETED_STACK_COUNT is the number of stacks deleted so far. DELETED_STACK_COUNT int // ACTIVE_STACK_COUNT is the number of stacks yet to be deleted or in the process of being deleted. ACTIVE_STACK_COUNT int // NUKE_DURATION_IN_HRS is the total run time of teardown until now. NUKE_DURATION_IN_HRS float64 )
var ColorMapping map[string]string = map[string]string{"Start": "#f0e62e", "Complete": "#25db2e", "Error": "#e81e1e"}
ColorMapping is the mapping of slack message color based on teardown event types 'Start', 'Complete', 'Error'
Functions ¶
func CurrentUTCDateTime ¶
func CurrentUTCDateTime() string
CurrentUTCDateTime returns current time in ISO string
func InitiateTearDown ¶
InitiateTearDown scans and deletes cloudformation stacks respecting the dependencies. A stack is eligible for deletion when it's exports has not been imported by any other stacks.
func UpdateNukeStats ¶
func UpdateNukeStats(dt map[string]models.StackDetails)
UpdateNukeStats updates global variables used for capturing teardown stats
Types ¶
type AlertMessage ¶
type AlertMessage struct { Message string // Long message with details about the event Event string // Start | Complete | Error FailedStack models.StackDetails Attachment map[string]interface{} }
AlertMessage is the structure of a alert event which is translated to slack message later.
type CFNManager ¶
type CFNManager struct { TargetAccountId string NukeRoleARN string StackPattern string AWSProfile string AWSRegion string EndpointURL *string }
CFNManager exposes methods to interact with CloudFormation via SDK.
func (CFNManager) AWSSessionAccountID ¶ added in v0.1.1
func (dm CFNManager) AWSSessionAccountID(sess *session.Session) (acID string, err error)
AWSSessionAccountID fetches account id from current aws session
func (CFNManager) DeleteStack ¶
func (dm CFNManager) DeleteStack(stackName string) error
DeleteStack sends delete request for a stack. Returns success if the stack we are trying to delete has already been deleted.
func (CFNManager) DescribeStack ¶
func (dm CFNManager) DescribeStack(stackName string) (*cloudformation.Stack, error)
DescribeStack returns description for particular stack.
func (CFNManager) ListEnvironmentExports ¶
func (dm CFNManager) ListEnvironmentExports() (map[string][]string, error)
ListEnvironmentExports finds all exported values for our matching stacks in this format:
{ "stack-1-name": ["export-1", "export-2"], "stack-2-name": [] }
func (CFNManager) ListEnvironmentStacks ¶
func (dm CFNManager) ListEnvironmentStacks() (map[string]models.StackDetails, error)
ListEnvironmentStacks lists matching stacks for the given regex.
func (CFNManager) ListImports ¶
func (dm CFNManager) ListImports(exportNames []string) (map[string]struct{}, error)
ListImports lists all stacks importing given exported names.
func (CFNManager) ListStackResources ¶
func (dm CFNManager) ListStackResources(stackName string) ([]*cloudformation.StackResourceSummary, error)
ListStackResources lists description of all resources in a stack.
func (CFNManager) RegexMatch ¶
func (dm CFNManager) RegexMatch(stackName string) bool
RegexMatch matches stack name with the supplied regex so that we can filter desired stacks for deletion.
func (CFNManager) Session ¶
func (dm CFNManager) Session() (*cloudformation.CloudFormation, error)
Session creates a new aws cloudformation session. By default it uses given aws profile and region but it also provides option to assume a different role. It also has validation for target account id to ensure we are deleting in the correct aws account.
type NotificationManager ¶
type NotificationManager struct { StackPattern string DryRun string SlackWebHookURL string // Webhook url is specific to channel }
NotificationManager exposes methods for sending alerts to slack channel.
func (NotificationManager) Alert ¶
func (nm NotificationManager) Alert(am AlertMessage) error
Alert posts message to Slack channel using webhook Only posts the message if it's not a dry run and webhook url is present
func (NotificationManager) ErrorAlert ¶
func (nm NotificationManager) ErrorAlert(am AlertMessage)
ErrorAlert prepares slack message for stack deletion error
func (NotificationManager) GenericAlert ¶
func (nm NotificationManager) GenericAlert(am AlertMessage)
GenericAlert prepares slack message for a generic message
func (NotificationManager) StartAlert ¶
func (nm NotificationManager) StartAlert(am AlertMessage)
StartAlert prepares slack message for teardown start event
func (NotificationManager) StuckAlert ¶
func (nm NotificationManager) StuckAlert(am AlertMessage)
StuckAlert prepares slack message when stack teardown is stuck
func (NotificationManager) SuccessAlert ¶
func (nm NotificationManager) SuccessAlert(am AlertMessage)
SuccessAlert prepares slack message for successful completion of stack teardown
type S3Manager ¶
type S3Manager struct { TargetAccountId string NukeRoleARN string AWSProfile string AWSRegion string EndpointURL *string }
S3Manager exposes methods to interact with AWS S3 service via SDK.
func (S3Manager) AWSSessionAccountID ¶ added in v0.1.1
AWSSessionAccountID fetches account id from current aws session
func (S3Manager) EmptyBucket ¶
EmptyBucket deletes all objects from a particular S3 bucket.
type SlackMessage ¶
type SlackMessage struct {
Attachments []map[string]interface{} `json:"attachments"`
}
SlackMessage is the structure accepted by Slack post message api. More info: https://app.slack.com/block-kit-builder