blob: 9ea5ea2f4b7da7e6c0850be6874fd3fdbcf95e4c [file] [log] [blame]
Jamie Hannaford339394c2014-11-04 16:16:21 +01001package acl
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +01002
3import (
4 "github.com/mitchellh/mapstructure"
5
6 "github.com/rackspace/gophercloud"
7 "github.com/rackspace/gophercloud/pagination"
8)
9
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010010// AccessList represents the rules of network access to a particular load
11// balancer.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010012type AccessList []NetworkItem
13
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010014// NetworkItem describes how an IP address or entire subnet may interact with a
15// load balancer.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010016type NetworkItem struct {
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010017 // The IP address or subnet (CIDR) that defines the network item.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010018 Address string
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010019
20 // The numeric unique ID for this item.
21 ID int
22
23 // Either ALLOW or DENY.
24 Type Type
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010025}
26
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010027// Type defines how an item may connect to the load balancer.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010028type Type string
29
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010030// Convenience consts.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010031const (
32 ALLOW Type = "ALLOW"
33 DENY Type = "DENY"
34)
35
Jamie Hannaforddfdf0a22014-11-12 11:06:45 +010036// AccessListPage is the page returned by a pager for traversing over a
37// collection of network items in an access list.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010038type AccessListPage struct {
39 pagination.SinglePageBase
40}
41
42// IsEmpty checks whether an AccessListPage struct is empty.
43func (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.
54func 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 Hannafordcfe2f282014-11-07 15:11:21 +010064// CreateResult represents the result of a create operation.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010065type CreateResult struct {
66 gophercloud.ErrResult
67}
68
Jamie Hannafordcfe2f282014-11-07 15:11:21 +010069// DeleteResult represents the result of a delete operation.
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010070type DeleteResult struct {
71 gophercloud.ErrResult
72}