-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add aws services * fix: links Signed-off-by: Azanul <azanulhaque@gmail.com> * fix: tidy Signed-off-by: Azanul <azanulhaque@gmail.com> * fix: lint Signed-off-by: Azanul <azanulhaque@gmail.com> --------- Signed-off-by: Azanul <azanulhaque@gmail.com> Co-authored-by: Azanul <azanulhaque@gmail.com> Co-authored-by: Azanul Haque <42029519+Azanul@users.noreply.github.com>
- Loading branch information
1 parent
512a905
commit 3fdd340
Showing
13 changed files
with
570 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/providers" | ||
) | ||
|
||
func NatGateways(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { | ||
var config ec2.DescribeNatGatewaysInput | ||
resources := make([]models.Resource, 0) | ||
ec2Client := ec2.NewFromConfig(*client.AWSClient) | ||
|
||
for { | ||
output, err := ec2Client.DescribeNatGateways(ctx, &config) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
for _, natGateways := range output.NatGateways { | ||
tags := make([]models.Tag, 0) | ||
for _, tag := range natGateways.Tags { | ||
tags = append(tags, models.Tag{ | ||
Key: *tag.Key, | ||
Value: *tag.Value, | ||
}) | ||
} | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "AWS", | ||
Account: client.Name, | ||
Service: "Nat Gateway", | ||
Region: client.AWSClient.Region, | ||
ResourceId: *natGateways.NatGatewayId, | ||
Cost: 0, | ||
Name: *natGateways.NatGatewayId, | ||
FetchedAt: time.Now(), | ||
Tags: tags, | ||
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#NatGateway:natGatewayId=%s", client.AWSClient.Region, client.AWSClient.Region, *natGateways.NatGatewayId), | ||
}) | ||
} | ||
if aws.ToString(output.NextToken) == "" { | ||
break | ||
} | ||
|
||
config.NextToken = output.NextToken | ||
} | ||
log.WithFields(log.Fields{ | ||
"provider": "AWS", | ||
"account": client.Name, | ||
"region": client.AWSClient.Region, | ||
"service": "Nat Gateway", | ||
"resources": len(resources), | ||
}).Info("Fetched resources") | ||
return resources, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/providers" | ||
) | ||
|
||
func TransitGatewayPeeringAttachments(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { | ||
var config ec2.DescribeTransitGatewayPeeringAttachmentsInput | ||
resources := make([]models.Resource, 0) | ||
ec2Client := ec2.NewFromConfig(*client.AWSClient) | ||
|
||
for { | ||
output, err := ec2Client.DescribeTransitGatewayPeeringAttachments(ctx, &config) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
for _, tAttachment := range output.TransitGatewayPeeringAttachments { | ||
tags := make([]models.Tag, 0) | ||
for _, tag := range tAttachment.Tags { | ||
tags = append(tags, models.Tag{ | ||
Key: *tag.Key, | ||
Value: *tag.Value, | ||
}) | ||
} | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "AWS", | ||
Account: client.Name, | ||
Service: "Transit Gateway Peering Attachments", | ||
Region: client.AWSClient.Region, | ||
ResourceId: *tAttachment.TransitGatewayAttachmentId, | ||
Cost: 0, | ||
Name: *tAttachment.TransitGatewayAttachmentId, | ||
FetchedAt: time.Now(), | ||
Tags: tags, | ||
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#TransitGatewayAttachment:transitGatewayAttachmentId=%s", client.AWSClient.Region, client.AWSClient.Region, *tAttachment.TransitGatewayAttachmentId), | ||
}) | ||
} | ||
if aws.ToString(output.NextToken) == "" { | ||
break | ||
} | ||
|
||
config.NextToken = output.NextToken | ||
} | ||
log.WithFields(log.Fields{ | ||
"provider": "AWS", | ||
"account": client.Name, | ||
"region": client.AWSClient.Region, | ||
"service": "Transit Gateway Peering Attachments", | ||
"resources": len(resources), | ||
}).Info("Fetched resources") | ||
return resources, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/tailwarden/komiser/models" | ||
"github.com/tailwarden/komiser/providers" | ||
) | ||
|
||
func TransitGatewayVpcAttachments(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { | ||
var config ec2.DescribeTransitGatewayVpcAttachmentsInput | ||
resources := make([]models.Resource, 0) | ||
ec2Client := ec2.NewFromConfig(*client.AWSClient) | ||
|
||
for { | ||
output, err := ec2Client.DescribeTransitGatewayVpcAttachments(ctx, &config) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
for _, tAttachment := range output.TransitGatewayVpcAttachments { | ||
tags := make([]models.Tag, 0) | ||
for _, tag := range tAttachment.Tags { | ||
tags = append(tags, models.Tag{ | ||
Key: *tag.Key, | ||
Value: *tag.Value, | ||
}) | ||
} | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "AWS", | ||
Account: client.Name, | ||
Service: "Transit Gateway Vpc Attachments", | ||
Region: client.AWSClient.Region, | ||
ResourceId: *tAttachment.TransitGatewayAttachmentId, | ||
Cost: 0, | ||
Name: *tAttachment.TransitGatewayAttachmentId, | ||
FetchedAt: time.Now(), | ||
Tags: tags, | ||
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/vpc/home?region=%s#TransitGatewayAttachment:transitGatewayAttachmentId=%s", client.AWSClient.Region, client.AWSClient.Region, *tAttachment.TransitGatewayAttachmentId), | ||
}) | ||
} | ||
if aws.ToString(output.NextToken) == "" { | ||
break | ||
} | ||
|
||
config.NextToken = output.NextToken | ||
} | ||
log.WithFields(log.Fields{ | ||
"provider": "AWS", | ||
"account": client.Name, | ||
"region": client.AWSClient.Region, | ||
"service": "Transit Gateway Vpc Attachments", | ||
"resources": len(resources), | ||
}).Info("Fetched resources") | ||
return resources, nil | ||
} |
Oops, something went wrong.