-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
120 lines (108 loc) · 3.64 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
109
110
111
112
113
114
115
116
117
118
119
120
package acls
import "github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/pagination"
// Policy is the structure represents the ACL policy details.
type Policy struct {
// The ACL name.
Name string `json:"acl_name"`
// The ACL type. The valid values are as follows:
// + PERMIT
// + DENY
Type string `json:"acl_type"`
// The value of the ACL policy.
Value string `json:"acl_value"`
// The entity type. The valid values are as follows:
// + IP
// + DOMAIN
// + DOMAIN_ID
EntityType string `json:"entity_type"`
// The ID of the ACL policy.
ID string `json:"id"`
// The latest update time.
UpdatedAt string `json:"update_time"`
}
// BindPage is a single page maximum result representing a query by offset page.
type PolicyPage struct {
pagination.OffsetPageBase
}
// IsEmpty checks whether a PolicyPage struct is empty.
func (b PolicyPage) IsEmpty() (bool, error) {
arr, err := ExtractPolicies(b)
return len(arr) == 0, err
}
// ExtractPolicies is a method to extract the list of ACL policies.
func ExtractPolicies(r pagination.Page) ([]Policy, error) {
var s []Policy
err := r.(PolicyPage).Result.ExtractIntoSlicePtr(&s, "acls")
return s, err
}
// BindResp is the structure that represents the API response of the ACL policy binding.
type BindResp struct {
// The ID of the binding relationship.
ID string `json:"id"`
// The API ID.
ApiId string `json:"api_id"`
// The environment ID where the API is published.
EnvId string `json:"env_id"`
// Throttling policy ID
PolicyId string `json:"acl_id"`
// The creation time.
CreatedAt string `json:"create_time"`
}
// BindPage is a single page maximum result representing a query by offset page.
type BindPage struct {
pagination.OffsetPageBase
}
// IsEmpty checks whether a BindPage struct is empty.
func (b BindPage) IsEmpty() (bool, error) {
arr, err := ExtractBindInfos(b)
return len(arr) == 0, err
}
// ExtractBinds is a method to extract the list of binding details for ACL policy.
func ExtractBindInfos(r pagination.Page) ([]AclBindApiInfo, error) {
var s []AclBindApiInfo
err := r.(BindPage).Result.ExtractIntoSlicePtr(&s, "apis")
return s, err
}
// AclBindApiInfo is the structure that represents the binding details.
type AclBindApiInfo struct {
// The API ID.
ID string `json:"api_id"`
// The API Name.
Name string `json:"api_name"`
// The API type.
Type int `json:"api_type"`
// The API type.
Description string `json:"api_remark"`
// The environment ID where the API is published.
EnvId string `json:"env_id"`
// The name of the environment published by the API.
EnvName string `json:"env_name"`
// The binding ID.
BindId string `json:"bind_id"`
// Group name to which the API belongs.
GroupName string `json:"group_name"`
// The time when the API and the policy were bound.
BoundAt string `json:"bind_time"`
// API publish record ID.
PublishId string `json:"publish_id"`
}
// BatchUnbindResp is the structure that represents the API response of the ACL policy unbinding.
type BatchUnbindResp struct {
// Number of API and throttling policy bindings that have been successfully unbound.
SuccessCount int `json:"success_count"`
// Unbind failed error code
Failures []Failure `json:"failure"`
}
// Failure is the structure that represents the failure details.
type Failure struct {
// API and ACL policy binding relationship ID that failed to unbind.
BindId string `json:"bind_id"`
// Unbind failed error code.
ErrorCode string `json:"error_code"`
// Unbind failed error message.
ErrorMsg string `json:"error_msg"`
// ID of the API that failed to unbind.
ApiId string `json:"api_id"`
// The name of the API that failed to unbind.
ApiName string `json:"api_name"`
}