blob: b15e5e039d3f8844e830e95749280921f5e60370 [file] [log] [blame]
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -07001package main
2
3import (
4 "fmt"
5 "flag"
6 "github.com/rackspace/gophercloud"
7)
8
9var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance testing. $? non-zero on error though.")
10var rgn = flag.String("r", "DFW", "Datacenter region to interrogate.")
11
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}