Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/dashboard/storybo…
Browse files Browse the repository at this point in the history
…ok/addons-7.6.17
  • Loading branch information
Azanul authored Aug 4, 2024
2 parents 3ba592b + c40e317 commit 39eafdd
Show file tree
Hide file tree
Showing 24 changed files with 274 additions and 64 deletions.
90 changes: 90 additions & 0 deletions providers/aws/redshift/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package redshift

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/redshift"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
awsUtils "github.com/tailwarden/komiser/providers/aws/utils"
)

func Resources(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)
var config redshift.DescribeClustersInput
redshiftClient := redshift.NewFromConfig(*client.AWSClient)

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

accountId := stsOutput.Account

serviceCost, err := awsUtils.GetCostAndUsage(ctx, client.AWSClient.Region, "Redshift")
if err != nil {
log.Warnln("Couldn't fetch Redshift cost and usage:", err)
}

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

for _, cluster := range output.Clusters {
resourceArn := fmt.Sprintf("arn:aws:redshift:%s:%s:cluster/%s", client.AWSClient.Region, *accountId, *cluster.ClusterIdentifier)
outputTags := cluster.Tags

tags := make([]models.Tag, 0)

for _, tag := range outputTags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

monthlyCost := float64(0)

resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Redshift Cluster",
ResourceId: resourceArn,
Region: client.AWSClient.Region,
Name: *cluster.ClusterIdentifier,
Cost: monthlyCost,
Metadata: map[string]string{
"serviceCost": fmt.Sprint(serviceCost),
},
Tags: tags,
FetchedAt: time.Now(),
Link: fmt.Sprintf("https://%s.console.aws.amaxon.com/redshift/home?region=%s/clusters/%s", client.AWSClient.Region, client.AWSClient.Region, *cluster.ClusterIdentifier),
})

}

if aws.ToString(output.Marker) == "" {
break
}
config.Marker = output.Marker
}

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

}
30 changes: 14 additions & 16 deletions providers/aws/redshift/eventsubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/redshift"
"github.com/aws/aws-sdk-go-v2/service/sts"
. "github.com/tailwarden/komiser/models"
. "github.com/tailwarden/komiser/providers"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
awsUtils "github.com/tailwarden/komiser/providers/aws/utils"
)

func EventSubscriptions(ctx context.Context, client ProviderClient) ([]Resource, error) {
resources := make([]Resource, 0)
func EventSubscriptions(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := make([]models.Resource, 0)
var config redshift.DescribeEventSubscriptionsInput
redshiftClient := redshift.NewFromConfig(*client.AWSClient)

Expand Down Expand Up @@ -45,20 +45,18 @@ func EventSubscriptions(ctx context.Context, client ProviderClient) ([]Resource,
resourceArn := fmt.Sprintf("arn:aws:redshift:%s:%s:eventsubscripion/%s", client.AWSClient.Region, *accountId, *eventSubscription.CustSubscriptionId)
outputTags := eventSubscription.Tags

tags := make([]Tag, 0)
tags := make([]models.Tag, 0)

if err == nil {
for _, tag := range outputTags {
tags = append(tags, Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}
for _, tag := range outputTags {
tags = append(tags, models.Tag{
Key: *tag.Key,
Value: *tag.Value,
})
}

monthlyCost := float64(0)

resources = append(resources, Resource{
resources = append(resources, models.Resource{
Provider: "AWS",
Account: client.Name,
Service: "Redshift EventSubscription",
Expand All @@ -69,9 +67,9 @@ func EventSubscriptions(ctx context.Context, client ProviderClient) ([]Resource,
Metadata: map[string]string{
"serviceCost": fmt.Sprint(serviceCost),
},
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),
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),
})
}
}
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/alloydb/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package alloydb
import (
"context"
"errors"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func Clusters(ctx context.Context, client providers.ProviderClient) ([]models.Re
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to get clusters")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get clusters")
return resources, err
}
}
resources = append(resources, models.Resource{
Provider: "GCP",
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/alloydb/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package alloydb
import (
"context"
"errors"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func Instances(ctx context.Context, client providers.ProviderClient) ([]models.R
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to get instances")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get instances")
return resources, err
}
}
resources = append(resources, models.Resource{
Provider: "GCP",
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/appengine/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package appengine
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func Services(ctx context.Context, client providers.ProviderClient) ([]models.Re
for {
svc, err := svcs.Next()
if err != nil {
logrus.WithError(err).Errorf("failed to get app engine")
break
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get app engine")
break
}
}
if svc == nil {
break
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/artifactregistry/docker_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifactregistry
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func ArtifactregistryDockerImages(ctx context.Context, client providers.Provider
for {
image, err := imageItr.Next()
if err != nil {
logrus.WithError(err).Errorf("failed to get nex image")
break
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get nex image")
break
}
}
if image == nil {
break
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/artifactregistry/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifactregistry
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func ArtifactregistryPackages(ctx context.Context, client providers.ProviderClie
for {
pkg, err := pkgItr.Next()
if err != nil {
logrus.WithError(err).Errorf("failed to get next package")
break
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get next package")
break
}
}
if pkg == nil {
break
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/artifactregistry/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifactregistry
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -29,8 +30,13 @@ func ArtifactregistryRepositories(ctx context.Context, client providers.Provider
for {
repo, err := repoItr.Next()
if err != nil {
logrus.WithError(err).Errorf("failed to get next repo")
break
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to get next repo")
break
}
}
if repo == nil {
break
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/bigquery/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bigquery
import (
"context"
"fmt"
"strings"
"time"

"cloud.google.com/go/bigquery"
Expand Down Expand Up @@ -50,8 +51,13 @@ func Tables(ctx context.Context, client providers.ProviderClient) ([]models.Reso
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to list dataset")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to list dataset")
return resources, err
}
}

tablesIterator := dataset.Tables(ctx)
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/certificate/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -36,8 +37,13 @@ func Certificates(ctx context.Context, client providers.ProviderClient) ([]model
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to list certificates")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to list certificates")
return resources, err
}
}

certificateNameWithoutProjectAndLocation := extractCertificateName(certificate.Name)
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/compute/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compute
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -43,8 +44,13 @@ func Disks(ctx context.Context, client providers.ProviderClient) ([]models.Resou
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to list disks")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to list disks")
return resources, err
}
}
if len(disksListPair.Value.Disks) == 0 {
continue
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/compute/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compute
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -43,8 +44,13 @@ func Instances(ctx context.Context, client providers.ProviderClient) ([]models.R
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to list instances")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
return resources, nil
} else {
logrus.WithError(err).Errorf("failed to list instances")
return resources, err
}
}
if len(instanceListPair.Value.Instances) == 0 {
continue
Expand Down
Loading

0 comments on commit 39eafdd

Please sign in to comment.