Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/552 eventsubscription #928

Merged
2 changes: 1 addition & 1 deletion providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
ec2.VpcEndpoints,
ec2.VpcPeeringConnections,
kinesis.Streams,
redshift.EventSubscription,
redshift.EventSubscriptions,
}
}

Expand Down
24 changes: 11 additions & 13 deletions providers/aws/redshift/eventsubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
. "github.com/tailwarden/komiser/providers"
)

func EventSubscription(ctx context.Context, client ProviderClient) ([]Resource, error) {
func EventSubscriptions(ctx context.Context, client ProviderClient) ([]Resource, error) {
resources := make([]Resource, 0)
var config redshift.DescribeEventSubscriptionsInput
redshiftClient := redshift.NewFromConfig(*client.AWSClient)
Expand All @@ -33,21 +33,19 @@ func EventSubscription(ctx context.Context, client ProviderClient) ([]Resource,
return resources, err
}

for _, eventSubscription := range output.EventSubscriptionsList { // TODO: capitalization convention?
if eventSubscription.CustSubscriptionId != nil { // TODO: is this equivalent to filesystem.Name from the efs example?
for _, eventSubscription := range output.EventSubscriptionsList {
if eventSubscription.CustSubscriptionId != nil {

resourceArn := fmt.Sprintf("arn:aws:redshift:%s:%s:eventsubscripion/%s", client.AWSClient.Region, *accountId, *eventSubscription.CustSubscriptionId) // TODO: is this arn format correct
outputTags, err := redshiftClient.DescribeTags(ctx, &redshift.DescribeTagsInput{
ResourceName: &resourceArn, // TODO: is ResourceName here equivalent to ResourceId in the efs example?
})
outputTags := eventSubscription.Tags

tags := make([]Tag, 0)

if err == nil {
for _, tag := range outputTags.TaggedResources { // TODO: this is slightly different than in the efs example. Is it correct?
for _, tag := range outputTags {
tags = append(tags, Tag{
Key: *tag.Tag.Key,
Value: *tag.Tag.Value,
Key: *tag.Key,
Value: *tag.Value,
})
}
}
Expand All @@ -57,19 +55,19 @@ func EventSubscription(ctx context.Context, client ProviderClient) ([]Resource,
resources = append(resources, Resource{
Provider: "AWS",
Account: client.Name,
Service: "Redshift",
Service: "Redshift EventSubscription",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: *eventSubscription.CustSubscriptionId,
Cost: monthlyCost,
Tags: tags,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amaxon.com/redshift/home?region=%s/event-subscriptions/%s", client.AWSClient.Region, client.AWSClient.Region, eventSubscription.CustSubscriptionId), // TODO: verify that the link format is correct
Link: fmt.Sprintf("https://%s.console.aws.amaxon.com/redshift/home?region=%s/event-subscriptions/%s", client.AWSClient.Region, client.AWSClient.Region, *eventSubscription.CustSubscriptionId), // TODO: verify that the link format is correct
})
}
}

if aws.ToString(output.Marker) == "" { // TODO: is output.Marker here playing the same role as ouput.NextMarker in the efs example?
if aws.ToString(output.Marker) == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a logger? for debugging purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look around for examples of loggers in a similar positions in existing functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some basic inspection, I don't see a logger in similar places in existing functions in the AWS provider. (like for example providers/aws/lambda/functions.go).

But now it occurs to me that maybe you were suggesting adding a logger temporarily to answer the question in the comment, namely "TODO: is output.Marker here playing the same role as ouput.NextMarker in the efs example?".

In any case, it seems that the feature is working correctly, so maybe there isn't a need to pursue this point further.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me I think we are ready to go with this!

break
}
config.Marker = output.Marker
Expand All @@ -79,7 +77,7 @@ func EventSubscription(ctx context.Context, client ProviderClient) ([]Resource,
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "Redshift",
"service": "Redshift EventSubscription",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
Expand Down