forked from G-Core/gcorelabscloud-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
108 lines (90 loc) · 2.86 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package apitokens
import (
gcorecloud "github.com/alexandrpaliy/gcorelabscloud-go"
"github.com/alexandrpaliy/gcorelabscloud-go/gcore/apitoken/v1/types"
)
type getResult struct {
gcorecloud.Result
}
// Extract is a function that accepts a result and extracts an api token resource.
func (r getResult) Extract() (*APIToken, error) {
var s APIToken
err := r.ExtractInto(&s)
return &s, err
}
func (r getResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "")
}
type listResult struct {
gcorecloud.Result
}
// Extract is a function that accepts a result and extracts an api token resources list.
func (r listResult) Extract() ([]APIToken, error) {
var s []APIToken
err := r.ExtractInto(&s)
return s, err
}
func (r listResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoSlicePtr(v, "")
}
type createResult struct {
gcorecloud.Result
}
// Extract is a function that accepts a result and extracts a token resource.
func (r createResult) Extract() (*Token, error) {
var s Token
err := r.ExtractInto(&s)
return &s, err
}
func (r createResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "")
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as an APIToken.
type GetResult struct {
getResult
}
// ListResult represents the result of a get operation. Call its Extract
// method to interpret it as an []APIToken.
type ListResult struct {
listResult
}
// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Token.
type CreateResult struct {
createResult
}
// DeleteResult represents the result of a delete operation
type DeleteResult struct {
gcorecloud.ErrResult
}
// APIToken represents an api token structure.
type APIToken struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ExpDate *gcorecloud.JSONRFC3339ZZ `json:"exp_date"`
ClientUser *ClientUser `json:"client_user"`
Deleted bool `json:"deleted"`
Expired bool `json:"expired"`
Created gcorecloud.JSONRFC3339ZZ `json:"created"`
LastUsage *gcorecloud.JSONRFC3339Date `json:"last_usage"`
}
// Token represents a token structure.
type Token struct {
Token string `json:"token"`
}
// ClientUser represents a client user structure.
type ClientUser struct {
Role ClientRole `json:"role"`
Deleted bool `json:"deleted"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
UserEmail string `json:"user_email"`
ClientID int `json:"client_id"`
}
// ClientRole represents a client role structure.
type ClientRole struct {
ID types.RoleIDType `json:"id"`
Name types.RoleNameType `json:"name"`
}