Skip to content

Commit

Permalink
feat: add aws codecommit resource (#1229)
Browse files Browse the repository at this point in the history
* feat: add aws codecommit resource

* chore: remove unused code

* chore: remove commented code

---------

Co-authored-by: amal richwin <richwin@munat.Dlink>
  • Loading branch information
AmalRichwin and amal richwin authored Dec 1, 2023
1 parent 2bf9167 commit e49a149
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ require (
require (
cloud.google.com/go/longrunning v0.4.1 // indirect
github.com/apache/arrow/go/v11 v11.0.0 // indirect
github.com/aws/aws-sdk-go-v2/service/codecommit v1.18.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.20.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/google/s2a-go v0.1.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.27.1 h1:TNRPtVMfBVk24DL3o
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.27.1/go.mod h1:f+2AxSfO44KOyp+hsuDsjJyZmaOQxkcmGKRFExyHZdU=
github.com/aws/aws-sdk-go-v2/service/codebuild v1.25.2 h1:7CP1OWPNk3sLQe5eockBr1l8N5prgO7oDuYO+bNNUrI=
github.com/aws/aws-sdk-go-v2/service/codebuild v1.25.2/go.mod h1:lad97CcvLKXfU5uWV/9S3QrHUwk6CBDounq7rNs9K0E=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.18.2 h1:pf48DGYnBziCfCWzL6Cw4fapTNg4qn3NOkKAmds/Ig0=
github.com/aws/aws-sdk-go-v2/service/codecommit v1.18.2/go.mod h1:JzDQFX7S1XLn5z4PnFBEUyTFgxzl7iEOQ1TPpl3OSAs=
github.com/aws/aws-sdk-go-v2/service/configservice v1.31.0 h1:3EaaGPAkwUHVbDKx/TCTAubBUqV8F6++5EaiSiXQgN0=
github.com/aws/aws-sdk-go-v2/service/configservice v1.31.0/go.mod h1:a+PVnn9VNPzPVUiXKXDHK21PSi/TzEKQNIsvSlVXgFY=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.20.3 h1:rGqIKTmugpZ7lEzXTmbiPg45Id09UQpB2YoGaE0J6T4=
github.com/aws/aws-sdk-go-v2/service/codedeploy v1.20.3/go.mod h1:A7i1lQClkFz09enKv5WYKb8a2lf9QeeI1s9dNiym3hg=
github.com/aws/aws-sdk-go-v2/service/configservice v1.41.2 h1:WJt83aWld986AxwJpzE0eDqQi18a/PwZ36y7DqENYdk=
Expand Down
2 changes: 2 additions & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/tailwarden/komiser/providers/aws/apigateway"
"github.com/tailwarden/komiser/providers/aws/cloudfront"
"github.com/tailwarden/komiser/providers/aws/cloudwatch"
"github.com/tailwarden/komiser/providers/aws/codecommit"
"github.com/tailwarden/komiser/providers/aws/codebuild"
"github.com/tailwarden/komiser/providers/aws/codedeploy"
"github.com/tailwarden/komiser/providers/aws/dynamodb"
Expand Down Expand Up @@ -99,6 +100,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
ec2.VpcPeeringConnections,
kinesis.Streams,
redshift.EventSubscriptions,
codecommit.Repositories,
codebuild.BuildProjects,
codedeploy.DeploymentGroups,
}
Expand Down
69 changes: 69 additions & 0 deletions providers/aws/codecommit/repositories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package codecommit

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/codecommit"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
)

func Repositories(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
var listRepoParams codecommit.ListRepositoriesInput
resources := make([]models.Resource, 0)
codecommitClient := codecommit.NewFromConfig(*client.AWSClient)

for {
output, err := codecommitClient.ListRepositories(ctx, &listRepoParams)
if err != nil {
return resources, err
}

for _, repository := range output.Repositories {
outputTags, err := codecommitClient.ListTagsForResource(ctx, &codecommit.ListTagsForResourceInput{
ResourceArn: repository.RepositoryId,
})

tags := make([]models.Tag, 0)
if err == nil {
for _, tag := range outputTags.Tags {
tags = append(tags, models.Tag{
Key: tag,
Value: outputTags.Tags[tag],
})
}
}

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "CodeCommit",
ResourceId: *repository.RepositoryId,
Region: client.AWSClient.Region,
Name: *repository.RepositoryName,
Tags: tags,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amazon.com/codesuite/codecommit/repositories/%s/browse?region=%s", client.AWSClient.Region, *repository.RepositoryName, client.AWSClient.Region),
})
}
if aws.ToString(output.NextToken) == "" {
break
}

listRepoParams.NextToken = output.NextToken
}

log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "CodeCommit",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}

0 comments on commit e49a149

Please sign in to comment.