-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dropdown to select zone for gcp resources
- Loading branch information
1 parent
a088932
commit a7539ce
Showing
5 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gcp | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/one2nc/cloudlens/internal" | ||
"github.com/rs/zerolog/log" | ||
"google.golang.org/api/compute/v1" | ||
) | ||
|
||
func FecthZones(ctx context.Context) ([]string, error) { | ||
|
||
|
||
zonesResp := []string{} | ||
|
||
// Create a client with default credentials. | ||
client, err := compute.NewService(ctx) | ||
if err != nil { | ||
log.Printf("Failed to create compute service client: %v", err) | ||
return zonesResp, err | ||
|
||
} | ||
|
||
// List available zones in your project. | ||
projectID := ctx.Value(internal.KeyActiveProject).(string) // Replace with your GCP project ID. | ||
zones, err := client.Zones.List(projectID).Context(ctx).Do() | ||
if err != nil { | ||
log.Printf("Failed to list zones: %v", err) | ||
return zonesResp, err | ||
} | ||
|
||
for _, zone := range zones.Items { | ||
zonesResp = append(zonesResp, zone.Name) | ||
} | ||
|
||
return zonesResp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters