diff --git a/go.mod b/go.mod index 953b45b02..2c25dbf41 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 1dcfbd603..96e5ba6b4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/providers/aws/aws.go b/providers/aws/aws.go index 585f19c16..1e03cee43 100644 --- a/providers/aws/aws.go +++ b/providers/aws/aws.go @@ -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" @@ -99,6 +100,7 @@ func listOfSupportedServices() []providers.FetchDataFunction { ec2.VpcPeeringConnections, kinesis.Streams, redshift.EventSubscriptions, + codecommit.Repositories, codebuild.BuildProjects, codedeploy.DeploymentGroups, } diff --git a/providers/aws/codecommit/repositories.go b/providers/aws/codecommit/repositories.go new file mode 100644 index 000000000..e33b02e9b --- /dev/null +++ b/providers/aws/codecommit/repositories.go @@ -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 +}