Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "flag" |
Max Lincoln | 75e06ec | 2013-12-13 00:00:12 -0300 | [diff] [blame] | 6 | "github.com/maxlinc/gophercloud" |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.") |
Samuel A. Falvo II | e4a3e42 | 2013-09-13 12:36:37 -0700 | [diff] [blame] | 10 | var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.") |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 11 | |
| 12 | func main() { |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 13 | flag.Parse() |
| 14 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 15 | // Invoke withIdentity such that re-auth is enabled. |
| 16 | withIdentity(true, func(auth gophercloud.AccessProvider) { |
| 17 | token1 := auth.AuthToken() |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 18 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 19 | withServerApi(auth, func(servers gophercloud.CloudServersProvider) { |
| 20 | // Just to confirm everything works, we should be able to list images without error. |
| 21 | _, err := servers.ListImages() |
| 22 | if err != nil { |
| 23 | panic(err) |
| 24 | } |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 25 | |
Samuel A. Falvo II | 887d780 | 2013-07-29 17:55:37 -0700 | [diff] [blame] | 26 | // Revoke our current authentication token. |
| 27 | auth.Revoke(auth.AuthToken()) |
| 28 | |
| 29 | // Attempt to list images again. This should _succeed_, because we enabled re-authentication. |
| 30 | _, err = servers.ListImages() |
| 31 | if err != nil { |
| 32 | panic(err) |
| 33 | } |
| 34 | |
| 35 | // However, our new authentication token should differ. |
| 36 | token2 := auth.AuthToken() |
| 37 | |
| 38 | if !*quiet { |
| 39 | fmt.Println("Old authentication token: ", token1) |
| 40 | fmt.Println("New authentication token: ", token2) |
| 41 | } |
| 42 | |
| 43 | if token1 == token2 { |
| 44 | panic("Tokens should differ") |
| 45 | } |
| 46 | }) |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 47 | }) |
Samuel A. Falvo II | 659e14b | 2013-07-16 12:04:54 -0700 | [diff] [blame] | 48 | } |