Skip to content

Commit

Permalink
Merge pull request #1478 from Azanul/develop
Browse files Browse the repository at this point in the history
Alter log level for disabled services
  • Loading branch information
Azanul authored Aug 1, 2024
2 parents 7df17b6 + 24b39da commit 5655ca0
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 48 deletions.
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
10 changes: 8 additions & 2 deletions providers/gcp/compute/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package compute
import (
"context"
"fmt"
"strings"
"time"

compute "cloud.google.com/go/compute/apiv1"
Expand Down Expand Up @@ -42,8 +43,13 @@ func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.R
break
}
if err != nil {
logrus.WithError(err).Errorf("failed to list snapshots")
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 snapshots")
return resources, err
}
}

tags := make([]models.Tag, 0)
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/container/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package container
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -36,8 +37,13 @@ func Clusters(ctx context.Context, client providers.ProviderClient) ([]models.Re
ProjectId: client.GCPClient.Credentials.ProjectID,
})
if err != nil {
logrus.WithError(err).Errorf("failed to collect 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 collect clusters")
return resources, err
}
}

for _, cluster := range clusters.Clusters {
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/firestore/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package firestore
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -26,8 +27,13 @@ func Documents(ctx context.Context, client providers.ProviderClient) ([]models.R

list, err := itr.GetAll()
if err != nil {
logrus.WithError(err).Errorf("failed to list all firestore collections")
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 all firestore collections")
return resources, err
}
}

for _, collection := range list {
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/function/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strings"
"time"

log "github.com/sirupsen/logrus"
Expand All @@ -26,8 +27,13 @@ func Functions(ctx context.Context, client providers.ProviderClient) ([]models.R
"projects/" + client.GCPClient.Credentials.ProjectID + "/locations/-",
).Do()
if err != nil {
log.WithError(err).Errorf("failed to list Cloud Functions")
return resources, err
if strings.Contains(err.Error(), "SERVICE_DISABLED") {
log.Warn(err.Error())
return resources, nil
} else {
log.WithError(err).Errorf("failed to list Cloud Functions")
return resources, err
}
}

for _, function := range functions.Functions {
Expand Down
5 changes: 3 additions & 2 deletions providers/gcp/gateway/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gateway
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -34,12 +35,12 @@ RegionsLoop:
"projects/" + client.GCPClient.Credentials.ProjectID + "/locations/" + regionName,
).Do()
if err != nil {
if err.Error() == "googleapi: Error 403: Location "+regionName+" is not found or access is unauthorized., forbidden" {
if err.Error() == "googleapi: Error 403: Location "+regionName+" is not found or access is unauthorized., forbidden" || strings.Contains(err.Error(), "SERVICE_DISABLED") {
logrus.Warn(err.Error())
continue RegionsLoop
} else {
logrus.WithError(err).Errorf("failed to list API Gateways")
return resources, err

}
}

Expand Down
9 changes: 7 additions & 2 deletions providers/gcp/iam/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ func Roles(ctx context.Context, client providers.ProviderClient) ([]models.Resou
"projects/" + client.GCPClient.Credentials.ProjectID,
).Do()
if err != nil {
logrus.WithError(err).Errorf("failed to list IAM roles")
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 IAM roles")
return resources, err
}
}

for _, role := range roles.Roles {
Expand Down
10 changes: 8 additions & 2 deletions providers/gcp/iam/service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iam
import (
"context"
"fmt"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -25,8 +26,13 @@ func ServiceAccounts(ctx context.Context, client providers.ProviderClient) ([]mo
"projects/" + client.GCPClient.Credentials.ProjectID,
).Do()
if err != nil {
logrus.WithError(err).Errorf("failed to list IAM Service Accounts")
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 IAM Service Accounts")
return resources, err
}
}

for _, account := range serviceAccounts.Accounts {
Expand Down
Loading

0 comments on commit 5655ca0

Please sign in to comment.