blob: ed87be7d840f97ec21fc33f2dfed3000637ced0e [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
10type AccessList []NetworkItem
11
12type NetworkItem struct {
13 Address string
14 ID int
15 Type Type
16}
17
18type Type string
19
20const (
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.
27type AccessListPage struct {
28 pagination.SinglePageBase
29}
30
31// IsEmpty checks whether an AccessListPage struct is empty.
32func (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.
43func 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
53type CreateResult struct {
54 gophercloud.ErrResult
55}
56
57type DeleteResult struct {
58 gophercloud.ErrResult
59}