@@ -61,13 +61,13 @@ var cleanCmd = &cobra.Command{
6161 config = GlobalCliConfig
6262 awsEnvRegion = os .Getenv ("AWS_DEFAULT_REGION" )
6363 awsEnvProfile = os .Getenv ("AWS_PROFILE" )
64+
6465 if * config .RegionFlag == "" {
6566 if awsEnvRegion != "" {
6667 * config .RegionFlag , err = validateRegion (f , awsEnvRegion )
6768 if err != nil {
6869 return err
6970 }
70-
7171 } else {
7272 return errors .New ("missing region flag and AWS_DEFAULT_REGION env variable. Please use -r and provide a valid AWS region" )
7373 }
@@ -94,6 +94,7 @@ var cleanCmd = &cobra.Command{
9494 } else {
9595 log .Infof ("The AWS Profile flag \" %s\" was passed in" , * config .ProfileFlag )
9696 }
97+
9798 awsConfigOptions = append (awsConfigOptions , awsConfig .WithSharedConfigProfile (* config .ProfileFlag ))
9899
99100 if * config .Verbose {
@@ -112,11 +113,13 @@ var cleanCmd = &cobra.Command{
112113
113114 if * config .LambdaListFile != "" {
114115 log .Info ("******** CUSTOM LAMBDA LIST PROVIDED ********" )
116+
115117 list , err := internal .GenerateLambdaDeleteList (* config .LambdaListFile )
116118 if err != nil {
117119 log .Infof ("an issue occurred while processing %s" , * config .LambdaListFile )
118120 log .Info (err .Error ())
119121 }
122+
120123 customeDeleteList = list
121124 }
122125
@@ -129,6 +132,7 @@ var cleanCmd = &cobra.Command{
129132 if err != nil {
130133 return errors .New ("ERROR RETRIEVING AWS CREDENTIALS" )
131134 }
135+
132136 if creds .Expired () {
133137 return errors .New ("AWS CREDENTIALS EXPIRED" )
134138 }
@@ -138,6 +142,7 @@ var cleanCmd = &cobra.Command{
138142 // Set the User-Agent for all AWS with the Lambda client
139143 o .APIOptions = append (o .APIOptions , middleware .AddUserAgentKeyValue ("go-lambda-cleanup" , VersionString ))
140144 })
145+
141146 err = executeClean (ctx , & config , initSvc , customeDeleteList )
142147 if err != nil {
143148 return err
@@ -150,7 +155,7 @@ var cleanCmd = &cobra.Command{
150155/*
151156executeClean is the main function that executes the clean-up process
152157It takes a context, a pointer to a cliConfig struct, a pointer to a lambda client, and a list of custom lambdas to delete
153- An error is returned if the function fails to execute
158+ An error is returned if the function fails to execute.
154159*/
155160func executeClean (ctx context.Context , config * cliConfig , svc * lambda.Client , customList []string ) error {
156161 startTime := time .Now ()
@@ -311,7 +316,7 @@ func displayDuration(startTime time.Time) {
311316}
312317
313318// generateDeleteInputStructs takes a list of lambda.DeleteFunctionInput and a boolean value to determine if the user wants more details. The function returns a list of lambda.DeleteFunctionInput
314- // An error is returned if the function fails to execute
319+ // An error is returned if the function fails to execute.
315320func generateDeleteInputStructs (versionsList [][]types.FunctionConfiguration , details bool ) ([][]lambda.DeleteFunctionInput , error ) {
316321 var (
317322 returnError error
@@ -349,7 +354,7 @@ func generateDeleteInputStructs(versionsList [][]types.FunctionConfiguration, de
349354}
350355
351356// calculateSpaceRemoval returns the total size of all the versions to be deleted.
352- // The function takes a list of lambda.DeleteFunctionInput and returns an int
357+ // The function takes a list of lambda.DeleteFunctionInput and returns an int.
353358func calculateSpaceRemoval (deleteList [][]types.FunctionConfiguration ) int {
354359 var (
355360 size int
@@ -367,7 +372,7 @@ func calculateSpaceRemoval(deleteList [][]types.FunctionConfiguration) int {
367372}
368373
369374// countDeleteVersions returns the total number of versions to be deleted.
370- // The function takes a list of lambda.DeleteFunctionInput and returns an int
375+ // The function takes a list of lambda.DeleteFunctionInput and returns an int.
371376func countDeleteVersions (deleteList [][]lambda.DeleteFunctionInput ) int {
372377 var (
373378 versionsCount int
@@ -594,16 +599,16 @@ func getLambdaStorage(list []types.FunctionConfiguration) (int64, error) {
594599
595600// validateRegion validates the user input to ensure it is a valid AWS region. The function takes a embed.FS and a string. The function returns a string and an error
596601// An embedded file is used to validate the user input. The embedded file contains a list of all the AWS regions
597- // Example of the embedded file: ap-south-2 ap-south-1 eu-south-1 eu-south-2 me-central-1 ca-central-1 eu-central-1 eu-central-2
602+ // Example of the embedded file: ap-south-2 ap-south-1 eu-south-1 eu-south-2 me-central-1 ca-central-1 eu-central-1 eu-central-2.
598603func validateRegion (f embed.FS , input string ) (string , error ) {
599604 var output string
600605
601606 var err error
602607
603608 rawData , _ := f .ReadFile (regionFile )
604- regionsList := strings .Split (string (rawData ), " " )
609+ regionsList := strings .SplitSeq (string (rawData ), " " )
605610
606- for _ , region := range regionsList {
611+ for region := range regionsList {
607612 if strings .ToLower (input ) == strings .TrimSpace (region ) {
608613 output = strings .TrimSpace (region )
609614 }
0 commit comments