Samuel A. Falvo II | 8a549ef | 2014-01-24 15:20:54 -0800 | [diff] [blame^] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "github.com/rackspace/gophercloud/openstack/identity" |
| 6 | "github.com/rackspace/gophercloud/openstack/utils" |
| 7 | ) |
| 8 | |
| 9 | type extractor func(*identity.TokenDesc) string |
| 10 | |
| 11 | func main() { |
| 12 | ao, err := utils.AuthOptions() |
| 13 | if err != nil { |
| 14 | panic(err) |
| 15 | } |
| 16 | |
| 17 | ao.AllowReauth = true |
| 18 | r, err := identity.Authenticate(ao) |
| 19 | if err != nil { |
| 20 | panic(err) |
| 21 | } |
| 22 | |
| 23 | t, err := identity.Token(r) |
| 24 | if err != nil { |
| 25 | panic(err) |
| 26 | } |
| 27 | |
| 28 | table := map[string]extractor{ |
| 29 | "ID": func(t *identity.TokenDesc) string { return t.Id() }, |
| 30 | "Expires": func(t *identity.TokenDesc) string { return t.Expires() }, |
| 31 | } |
| 32 | |
| 33 | for attr, fn := range table { |
| 34 | fmt.Printf("Your token's %s is %s\n", attr, fn(t)) |
| 35 | } |
| 36 | |
| 37 | sc, err := identity.ServiceCatalog(r) |
| 38 | if err != nil { |
| 39 | panic(err) |
| 40 | } |
| 41 | ces, err := sc.CatalogEntries() |
| 42 | fmt.Printf("Service Catalog Summary:\n %32s %-16s\n", "Name", "Type") |
| 43 | for _, ce := range ces { |
| 44 | fmt.Printf(" %32s | %-16s\n", ce.Name, ce.Type) |
| 45 | } |
| 46 | |
| 47 | for _, ce := range ces { |
| 48 | fmt.Printf("Endpoints for %s/%s\n", ce.Name, ce.Type) |
| 49 | for _, ep := range ce.Endpoints { |
| 50 | fmt.Printf(" Version: %s\n", ep.VersionId) |
| 51 | fmt.Printf(" Region: %s\n", ep.Region) |
| 52 | fmt.Printf(" Tenant: %s\n", ep.TenantId) |
| 53 | fmt.Printf(" Public URL: %s\n", ep.PublicURL) |
| 54 | fmt.Printf(" Internal URL: %s\n", ep.InternalURL) |
| 55 | } |
| 56 | } |
| 57 | } |