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
82 lines (68 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package policies
import (
"fmt"
"github.com/huaweicloud/golangsdk"
"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 Policy struct {
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
OperationDefinition *PolicyODCreate `json:"operation_definition"`
OperationType string `json:"operation_type"`
Trigger *PolicyTriggerResp `json:"trigger"`
AssociatedVaults []PolicyAssociateVault `json:"associated_vaults"`
}
type PolicyTriggerResp struct {
TriggerID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Properties PolicyTriggerPropertiesResp `json:"properties"`
}
type PolicyTriggerPropertiesResp struct {
Pattern []string `json:"pattern"`
StartTime string `json:"start_time"`
}
type PolicyAssociateVault struct {
VaultID string `json:"vault_id"`
DestinationVaultID string `json:"destination_vault_id"`
}
func (r commonResult) Extract() (*Policy, error) {
var s struct {
Policy *Policy `json:"policy"`
}
if r.Err != nil {
return nil, r.Err
}
err := r.ExtractInto(&s)
if err != nil {
return nil, fmt.Errorf("error extracting policy from create response: %s", err)
}
return s.Policy, err
}
type PolicyPage struct {
pagination.SinglePageBase
}
func ExtractPolicies(r pagination.Page) ([]Policy, error) {
var s []Policy
err := r.(PolicyPage).Result.ExtractIntoSlicePtr(&s, "policies")
if err != nil {
return nil, err
}
return s, nil
}