blob: 8b198c7c962b3847bc4e5b4166e221d65f86f295 [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() {
13 provider, username, password := getCredentials()
14 flag.Parse()
15
16 // Authenticate initially against the service.
17 auth, err := gophercloud.Authenticate(
18 provider,
19 gophercloud.AuthOptions{
20 Username: username,
21 Password: password,
Samuel A. Falvo II9e64f6b2013-07-16 14:26:50 -070022 AllowReauth: true, // This enables reauthentication.
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070023 },
24 )
25 if err != nil {
26 panic(err)
27 }
28
29 // Cache our initial authentication token.
30 token1 := auth.AuthToken()
31
32 // Acquire access to the cloud servers API.
33 servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
34 Name: "cloudServersOpenStack",
35 Region: *rgn,
36 VersionId: "2",
37 UrlChoice: gophercloud.PublicURL,
38 })
39 if err != nil {
40 panic(err)
41 }
42
43 // Just to confirm everything works, we should be able to list images without error.
44 _, err = servers.ListImages()
45 if err != nil {
46 panic(err)
47 }
48
49 // Revoke our current authentication token.
50 auth.Revoke(auth.AuthToken())
Samuel A. Falvo II659e14b2013-07-16 12:04:54 -070051
52 // Attempt to list images again. This should _succeed_, because we enabled re-authentication.
53 _, err = servers.ListImages()
54 if err != nil {
55 panic(err)
56 }
57
58 // However, our new authentication token should differ.
59 token2 := auth.AuthToken()
60
61 if !*quiet {
62 fmt.Println("Old authentication token: ", token1)
63 fmt.Println("New authentication token: ", token2)
64 }
65}