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

Added support of aws codepipelines #1192

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions providers/aws/CodePipelines/GetPipelines.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package codepipeline

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/pipeline"

Check failure on line 11 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / build_test_cli

no required module provides package github.com/aws/aws-sdk-go-v2/service/pipeline; to add it:
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/tailwarden/komiser/utils"
)

func GetPipelines(ctx context.Context, client ProviderClient) ([]Resource, error) {

Check failure on line 16 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: ProviderClient (typecheck)
resources := make([]Resource, 0)

Check failure on line 17 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: Resource (typecheck)
var config pipeline.ListClustersInput
pipelineClient := pipeline.NewFromConfig(*client.AWSClient)

stsClient := sts.NewFromConfig(*client.AWSClient)
stsOutput, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
return resources, err
}

accountId := stsOutput.Account

for {
output, err := pipelineClient.ListClusters(ctx, &config)
if err != nil {
return resources, err
}

for _, cluster := range output.Clusters {
resourceArn := fmt.Sprintf("arn:aws:pipeline:%s:%s:cluster/%s", client.AWSClient.Region, *accountId, cluster)
outputTags, err := pipelineClient.ListTagsForResource(ctx, &pipeline.ListTagsForResourceInput{
ResourceArn: &resourceArn,
})

tags := make([]Tag, 0)

Check failure on line 41 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: Tag (typecheck)

if err == nil {
for key, value := range outputTags.Tags {
tags = append(tags, Tag{

Check failure on line 45 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: Tag (typecheck)
Key: key,
Value: value,
})
}
}

outputDescribe, err := pipelineClient.DescribeCluster(ctx, &eks.DescribeClusterInput{

Check failure on line 52 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: eks (typecheck)
Name: &cluster,
})

resources = append(resources, Resource{

Check failure on line 56 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: Resource (typecheck)
Provider: "AWS",
Account: client.Name,
Service: "codepipeline",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: cluster,
Tags: tags,
CreatedAt: createdAt,

Check failure on line 64 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: createdAt (typecheck)
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amazon.com/codepipeline/home?region=%s#/clusters/%s", client.AWSClient.Region, client.AWSClient.Region, cluster),
})
}

if aws.ToString(output.NextToken) == "" {
break
}
å

Check failure on line 73 in providers/aws/CodePipelines/GetPipelines.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: å (typecheck)
config.NextToken = output.NextToken
}
log.WithFields(log.Fields{
"provider": "AWS",
"account": client.Name,
"region": client.AWSClient.Region,
"service": "codepipeline",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
1 change: 1 addition & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aws

Check failure on line 1 in providers/aws/aws.go

View workflow job for this annotation

GitHub Actions / golangci-lint

: # github.com/tailwarden/komiser/providers/aws

import (
"context"
Expand Down Expand Up @@ -95,8 +95,9 @@
ec2.VpcPeeringConnections,
kinesis.Streams,
redshift.EventSubscriptions,
codepipeline.GetPipelines,
}
}

Check failure on line 100 in providers/aws/aws.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: codepipeline (typecheck)

func FetchResources(ctx context.Context, client providers.ProviderClient, regions []string, db *bun.DB, telemetry bool, analytics utils.Analytics) {
listOfSupportedRegions := getRegions()
Expand Down
Loading