blob: 1bcf4fc92dfd889fa61bf2641b7505c884b86974 [file] [log] [blame]
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07001package main
2
3import (
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07004 "flag"
Jon Perritt2be65d12013-12-13 17:21:09 -06005 "fmt"
Max Lincoln28b49562013-12-13 13:23:44 -03006 "github.com/rackspace/gophercloud"
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07007)
8
9var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.")
Samuel A. Falvo IIe4a3e422013-09-13 12:36:37 -070010var rgn = flag.String("r", "", "Datacenter region to interrogate. Leave blank for provider-default region.")
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070011
12func main() {
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070013 flag.Parse()
14
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070015 // Invoke withIdentity such that re-auth is enabled.
16 withIdentity(true, func(auth gophercloud.AccessProvider) {
17 token1 := auth.AuthToken()
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070018
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070019 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 II659e14b2013-07-16 12:04:54 -070025
Samuel A. Falvo II887d7802013-07-29 17:55:37 -070026 // 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 II659e14b2013-07-16 12:04:54 -070047 })
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070048}