2024-01-01 15:33:08 -06:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/digitalocean/godo"
|
2024-01-24 22:55:34 -06:00
|
|
|
"golang.org/x/oauth2"
|
2024-01-01 15:33:08 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (d *DigitalOcean) listRegions() []godo.Region {
|
|
|
|
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: d.token})
|
|
|
|
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
|
|
|
|
client := godo.NewClient(oauthClient)
|
|
|
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
// Retrieve all regions.
|
|
|
|
regions, _, err := client.Regions.List(ctx, &godo.ListOptions{})
|
|
|
|
if err != nil {
|
|
|
|
d.err = err
|
|
|
|
log.Warn(err, "digitalocean.listRegions() failed")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-01-24 22:55:34 -06:00
|
|
|
// Print details of each region.
|
|
|
|
fmt.Println("Available Regions:")
|
|
|
|
for _, region := range regions {
|
|
|
|
fmt.Printf("Slug: %s, Name: %s, Available: %v\n", region.Slug, region.Name, region.Available)
|
|
|
|
}
|
2024-01-01 15:33:08 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
return regions
|
|
|
|
}
|