/
results.go
65 lines (57 loc) · 1.84 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package shareaccessrules
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
)
// ShareAccess contains information associated with an OpenStack share access rule.
type ShareAccess struct {
// The UUID of the share to which you are granted or denied access.
ShareID string `json:"share_id"`
// The date and time stamp when the resource was created within the service’s database.
CreatedAt time.Time `json:"-"`
// The date and time stamp when the resource was last updated within the service’s database.
UpdatedAt time.Time `json:"-"`
// The access rule type.
AccessType string `json:"access_type"`
// The value that defines the access. The back end grants or denies the access to it.
AccessTo string `json:"access_to"`
// The access credential of the entity granted share access.
AccessKey string `json:"access_key"`
// The state of the access rule.
State string `json:"state"`
// The access level to the share.
AccessLevel string `json:"access_level"`
// The access rule ID.
ID string `json:"id"`
// Access rule metadata.
Metadata map[string]interface{} `json:"metadata"`
}
func (r *ShareAccess) UnmarshalJSON(b []byte) error {
type tmp ShareAccess
var s struct {
tmp
CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = ShareAccess(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
return nil
}
// GetResult contains the response body and error from a Get request.
type GetResult struct {
gophercloud.Result
}
// Extract will get the ShareAccess object from the GetResult.
func (r GetResult) Extract() (*ShareAccess, error) {
var s struct {
ShareAccess *ShareAccess `json:"access"`
}
err := r.ExtractInto(&s)
return s.ShareAccess, err
}