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 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 10 | // AccessList represents the rules of network access to a particular load |
| 11 | // balancer. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 12 | type AccessList []NetworkItem |
| 13 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 14 | // NetworkItem describes how an IP address or entire subnet may interact with a |
| 15 | // load balancer. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 16 | type NetworkItem struct { |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 17 | // The IP address or subnet (CIDR) that defines the network item. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 18 | Address string |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 19 | |
| 20 | // The numeric unique ID for this item. |
| 21 | ID int |
| 22 | |
| 23 | // Either ALLOW or DENY. |
| 24 | Type Type |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 27 | // Type defines how an item may connect to the load balancer. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 28 | type Type string |
| 29 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 30 | // Convenience consts. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 31 | const ( |
| 32 | ALLOW Type = "ALLOW" |
| 33 | DENY Type = "DENY" |
| 34 | ) |
| 35 | |
Jamie Hannaford | dfdf0a2 | 2014-11-12 11:06:45 +0100 | [diff] [blame^] | 36 | // AccessListPage is the page returned by a pager for traversing over a |
| 37 | // collection of network items in an access list. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 38 | type AccessListPage struct { |
| 39 | pagination.SinglePageBase |
| 40 | } |
| 41 | |
| 42 | // IsEmpty checks whether an AccessListPage struct is empty. |
| 43 | func (p AccessListPage) IsEmpty() (bool, error) { |
| 44 | is, err := ExtractAccessList(p) |
| 45 | if err != nil { |
| 46 | return true, nil |
| 47 | } |
| 48 | return len(is) == 0, nil |
| 49 | } |
| 50 | |
| 51 | // ExtractAccessList accepts a Page struct, specifically an AccessListPage |
| 52 | // struct, and extracts the elements into a slice of NetworkItem structs. In |
| 53 | // other words, a generic collection is mapped into a relevant slice. |
| 54 | func ExtractAccessList(page pagination.Page) (AccessList, error) { |
| 55 | var resp struct { |
| 56 | List AccessList `mapstructure:"accessList" json:"accessList"` |
| 57 | } |
| 58 | |
| 59 | err := mapstructure.Decode(page.(AccessListPage).Body, &resp) |
| 60 | |
| 61 | return resp.List, err |
| 62 | } |
| 63 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 64 | // CreateResult represents the result of a create operation. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 65 | type CreateResult struct { |
| 66 | gophercloud.ErrResult |
| 67 | } |
| 68 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 69 | // DeleteResult represents the result of a delete operation. |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 70 | type DeleteResult struct { |
| 71 | gophercloud.ErrResult |
| 72 | } |