Samuel A. Falvo II | f9ffaa1 | 2014-02-21 15:14:29 -0800 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package monitoring |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
Jon Perritt | 5eb55b1 | 2014-08-18 14:48:23 -0500 | [diff] [blame] | 7 | identity "github.com/rackspace/gophercloud/openstack/identity/v2" |
Samuel A. Falvo II | f9ffaa1 | 2014-02-21 15:14:29 -0800 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/openstack/utils" |
| 9 | "github.com/rackspace/gophercloud/rackspace/monitoring" |
| 10 | "github.com/rackspace/gophercloud/rackspace/monitoring/notificationPlans" |
Jon Perritt | 5eb55b1 | 2014-08-18 14:48:23 -0500 | [diff] [blame] | 11 | "testing" |
Samuel A. Falvo II | f9ffaa1 | 2014-02-21 15:14:29 -0800 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | func TestRBACPermissions(t *testing.T) { |
| 15 | ao, err := utils.AuthOptions() |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | |
| 20 | ao.AllowReauth = true |
| 21 | r, err := identity.Authenticate(ao) |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | |
| 26 | // Find the cloud monitoring API |
| 27 | |
| 28 | sc, err := identity.GetServiceCatalog(r) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | |
| 33 | ces, err := sc.CatalogEntries() |
| 34 | if err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | |
| 38 | monUrl, err := findMonitoringEndpoint(ces) |
| 39 | if err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | |
| 43 | // Build ourselves an interface to cloud monitoring! |
| 44 | |
| 45 | np := notificationPlans.NewClient(monitoring.Options{ |
| 46 | Endpoint: monUrl, |
| 47 | AuthOptions: ao, |
| 48 | Authentication: r, |
| 49 | }) |
| 50 | |
| 51 | // Try to delete a bogus notification plan |
| 52 | |
| 53 | dr, err := np.Delete("ajkhdlkajhdflkajshdf") |
| 54 | if err != nil { |
| 55 | fmt.Printf("%#v\n", err) |
| 56 | } |
| 57 | fmt.Printf("%#v\n", dr) |
| 58 | } |
| 59 | |
| 60 | func findMonitoringEndpoint(ces []identity.CatalogEntry) (string, error) { |
| 61 | for _, ce := range ces { |
| 62 | if ce.Type == "rax:monitor" { |
| 63 | return ce.Endpoints[0].PublicURL, nil |
| 64 | } |
| 65 | } |
| 66 | return "", fmt.Errorf("No monitoring API in the service catalog") |
| 67 | } |