Jamie Hannaford | 339394c | 2014-11-04 16:16:21 +0100 | [diff] [blame] | 1 | package acl |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "github.com/mitchellh/mapstructure" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | ) |
| 9 | |
| 10 | type AccessList []NetworkItem |
| 11 | |
| 12 | type NetworkItem struct { |
| 13 | Address string |
| 14 | ID int |
| 15 | Type Type |
| 16 | } |
| 17 | |
| 18 | type Type string |
| 19 | |
| 20 | const ( |
| 21 | ALLOW Type = "ALLOW" |
| 22 | DENY Type = "DENY" |
| 23 | ) |
| 24 | |
| 25 | // AccessListPage is the page returned by a pager when traversing over a collection of |
| 26 | // network items in an access list. |
| 27 | type AccessListPage struct { |
| 28 | pagination.SinglePageBase |
| 29 | } |
| 30 | |
| 31 | // IsEmpty checks whether an AccessListPage struct is empty. |
| 32 | func (p AccessListPage) IsEmpty() (bool, error) { |
| 33 | is, err := ExtractAccessList(p) |
| 34 | if err != nil { |
| 35 | return true, nil |
| 36 | } |
| 37 | return len(is) == 0, nil |
| 38 | } |
| 39 | |
| 40 | // ExtractAccessList accepts a Page struct, specifically an AccessListPage |
| 41 | // struct, and extracts the elements into a slice of NetworkItem structs. In |
| 42 | // other words, a generic collection is mapped into a relevant slice. |
| 43 | func ExtractAccessList(page pagination.Page) (AccessList, error) { |
| 44 | var resp struct { |
| 45 | List AccessList `mapstructure:"accessList" json:"accessList"` |
| 46 | } |
| 47 | |
| 48 | err := mapstructure.Decode(page.(AccessListPage).Body, &resp) |
| 49 | |
| 50 | return resp.List, err |
| 51 | } |
| 52 | |
| 53 | type CreateResult struct { |
| 54 | gophercloud.ErrResult |
| 55 | } |
| 56 | |
| 57 | type DeleteResult struct { |
| 58 | gophercloud.ErrResult |
| 59 | } |