Skip to content

Commit

Permalink
Handle missing project permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrv committed Nov 7, 2024
1 parent 2e4c1ce commit 2098839
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/gcp/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package gcp
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"

"google.golang.org/api/compute/v1"
"google.golang.org/api/container/v1"
"google.golang.org/api/googleapi"
)

type Cluster struct {
Expand Down Expand Up @@ -57,6 +60,7 @@ func getClusters(ctx context.Context, projects []Project) ([]Cluster, error) {
if err != nil {
return nil, err
}

clusters = append(clusters, cluster...)
}

Expand All @@ -72,6 +76,11 @@ func getGCPClusters(ctx context.Context, project Project) ([]Cluster, error) {
call := svc.Projects.Locations.Clusters.List("projects/" + project.ID + "/locations/-")
response, err := call.Do()
if err != nil {
if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.StatusForbidden {
fmt.Printf("No access to project %s, skipping\n", project.ID)
return nil, nil
}

return nil, err
}

Expand Down

0 comments on commit 2098839

Please # to comment.