This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
results.go
159 lines (137 loc) · 4 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package vaults
import (
"fmt"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/common/tags"
"github.com/huaweicloud/golangsdk/pagination"
)
type commonResult struct {
golangsdk.Result
}
type CreateResult struct {
commonResult
}
type GetResult struct {
commonResult
}
type UpdateResult struct {
commonResult
}
type DeleteResult struct {
golangsdk.ErrResult
}
type Vault struct {
ID string `json:"id"`
Name string `json:"name"`
Billing Billing `json:"billing"`
Description string `json:"description"`
ProjectID string `json:"project_id"`
ProviderID string `json:"provider_id"`
Resources []ResourceResp `json:"resources"`
Tags []tags.ResourceTag `json:"tags"`
EnterpriseProjectID string `json:"enterprise_project_id"`
AutoBind bool `json:"auto_bind"`
BindRules VaultBindRules `json:"bind_rules"`
UserID string `json:"user_id"`
CreatedAt string `json:"created_at"`
AutoExpand bool `json:"auto_expand"`
}
type Billing struct {
Allocated int `json:"allocated"`
ChargingMode string `json:"charging_mode"`
CloudType string `json:"cloud_type"`
ConsistentLevel string `json:"consistent_level"`
ObjectType string `json:"object_type"`
OrderID string `json:"order_id"`
ProductID string `json:"product_id"`
ProtectType string `json:"protect_type"`
Size int `json:"size"`
SpecCode string `json:"spec_code"`
Status string `json:"status"`
StorageUnit string `json:"storage_unit"`
Used int `json:"used"`
FrozenScene string `json:"frozen_scene"`
}
type ResourceResp struct {
ExtraInfo ResourceExtraInfo `json:"extra_info"`
ID string `json:"id"`
Name string `json:"name"`
ProtectStatus string `json:"protect_status"`
Size int `json:"size"`
Type string `json:"type"`
BackupSize int `json:"backup_size"`
BackupCount int `json:"backup_count"`
}
func (r commonResult) Extract() (*Vault, error) {
var s struct {
Vault *Vault `json:"vault"`
}
err := r.ExtractInto(&s)
return s.Vault, err
}
type AssociateResourcesResult struct {
golangsdk.Result
}
func (r AssociateResourcesResult) Extract() ([]string, error) {
var s struct {
AddResourceIDs []string `json:"add_resource_ids"`
}
if r.Err != nil {
return nil, r.Err
}
err := r.ExtractInto(&s)
if err != nil {
return nil, fmt.Errorf("failed to extract Associated Resource IDs")
}
return s.AddResourceIDs, nil
}
type DissociateResourcesResult struct {
golangsdk.Result
}
func (r DissociateResourcesResult) Extract() ([]string, error) {
var s struct {
RemoveResourceIDs []string `json:"remove_resource_ids"`
}
if r.Err != nil {
return nil, r.Err
}
err := r.ExtractInto(&s)
if err != nil {
return nil, fmt.Errorf("failed to extract Dissociated Resource IDs")
}
return s.RemoveResourceIDs, nil
}
type BindPolicyResult struct {
golangsdk.Result
}
type PolicyBinding struct {
VaultID string `json:"vault_id"`
PolicyID string `json:"policy_id"`
}
func (r BindPolicyResult) Extract() (*PolicyBinding, error) {
var s struct {
PolicyBinding *PolicyBinding `json:"associate_policy"`
}
err := r.ExtractInto(&s)
return s.PolicyBinding, err
}
type UnbindPolicyResult struct {
golangsdk.Result
}
func (r UnbindPolicyResult) Extract() (*PolicyBinding, error) {
var s struct {
PolicyBinding *PolicyBinding `json:"dissociate_policy"`
}
err := r.ExtractInto(&s)
return s.PolicyBinding, err
}
type VaultPage struct {
pagination.SinglePageBase
}
func ExtractVaults(r pagination.Page) (*[]Vault, error) {
var s struct {
Vaults []Vault `json:"vaults"`
}
err := (r.(VaultPage)).ExtractInto(&s)
return &s.Vaults, err
}