Skip to content

Commit

Permalink
SQS: Fix timestamp parsing
Browse files Browse the repository at this point in the history
This was broken by PR gruntwork-io#517. SQS uses Unix timestamps, so
we need to make sure to treat them as such.

Signed-off-by: Frank Lichtenheld <[email protected]>
  • Loading branch information
flichtenheld committed Nov 7, 2023
1 parent 26bd391 commit 677a407
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions aws/resources/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package resources

import (
"context"
"strconv"
"time"
"github.com/aws/aws-sdk-go/aws"
awsgo "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/gruntwork-io/cloud-nuke/config"
"github.com/gruntwork-io/cloud-nuke/logging"
"github.com/gruntwork-io/cloud-nuke/report"
"github.com/gruntwork-io/cloud-nuke/telemetry"
"github.com/gruntwork-io/cloud-nuke/util"
"github.com/gruntwork-io/go-commons/errors"
commonTelemetry "github.com/gruntwork-io/go-commons/telemetry"
)
Expand Down Expand Up @@ -42,17 +43,17 @@ func (sq *SqsQueue) getAll(c context.Context, configObj config.Config) ([]*strin
return nil, errors.WithStackTrace(err)
}

// Convert string timestamp to int64
createdAt := queueAttributes.Attributes["CreatedTimestamp"]
createdAtTime, err := util.ParseTimestamp(createdAt)
// Convert string timestamp to int64 and then to time.Time
createdAt := *queueAttributes.Attributes["CreatedTimestamp"]
createdAtInt, err := strconv.ParseInt(createdAt, 10, 64)
if err != nil {
return nil, errors.WithStackTrace(err)
}
createdAtTime := time.Unix(createdAtInt, 0)

// Compare time as int64
if configObj.SQS.ShouldInclude(config.ResourceValue{
Name: queue,
Time: createdAtTime,
Time: &createdAtTime,
}) {
urls = append(urls, queue)
}
Expand All @@ -61,7 +62,7 @@ func (sq *SqsQueue) getAll(c context.Context, configObj config.Config) ([]*strin
return urls, nil
}

// Deletes all Elastic Load Balancers
// Deletes all Queues
func (sq *SqsQueue) nukeAll(urls []*string) error {
if len(urls) == 0 {
logging.Debugf("No SQS Queues to nuke in region %s", sq.Region)
Expand Down
5 changes: 3 additions & 2 deletions aws/resources/sqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gruntwork-io/cloud-nuke/telemetry"
"github.com/stretchr/testify/require"
"regexp"
"strconv"
"testing"
"time"
)
Expand Down Expand Up @@ -55,12 +56,12 @@ func TestSqsQueue_GetAll(t *testing.T) {
GetQueueAttributesOutput: map[string]sqs.GetQueueAttributesOutput{
queue1: {
Attributes: map[string]*string{
"CreatedTimestamp": awsgo.String(now.Format(time.RFC3339)),
"CreatedTimestamp": awsgo.String(strconv.FormatInt(now.Unix(), 10)),
},
},
queue2: {
Attributes: map[string]*string{
"CreatedTimestamp": awsgo.String(now.Add(1).Format(time.RFC3339)),
"CreatedTimestamp": awsgo.String(strconv.FormatInt(now.Add(1).Unix(), 10)),
},
},
},
Expand Down

0 comments on commit 677a407

Please sign in to comment.