github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/vaults/results.go (about) 1 package vaults 2 3 import ( 4 "fmt" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/common/tags" 8 "github.com/huaweicloud/golangsdk/pagination" 9 ) 10 11 type commonResult struct { 12 golangsdk.Result 13 } 14 15 type CreateResult struct { 16 commonResult 17 } 18 19 type GetResult struct { 20 commonResult 21 } 22 23 type UpdateResult struct { 24 commonResult 25 } 26 27 type DeleteResult struct { 28 golangsdk.ErrResult 29 } 30 31 type Vault struct { 32 ID string `json:"id"` 33 Name string `json:"name"` 34 Billing Billing `json:"billing"` 35 Description string `json:"description"` 36 ProjectID string `json:"project_id"` 37 ProviderID string `json:"provider_id"` 38 Resources []ResourceResp `json:"resources"` 39 Tags []tags.ResourceTag `json:"tags"` 40 EnterpriseProjectID string `json:"enterprise_project_id"` 41 AutoBind bool `json:"auto_bind"` 42 BindRules VaultBindRules `json:"bind_rules"` 43 UserID string `json:"user_id"` 44 CreatedAt string `json:"created_at"` 45 AutoExpand bool `json:"auto_expand"` 46 } 47 48 type Billing struct { 49 Allocated int `json:"allocated"` 50 ChargingMode string `json:"charging_mode"` 51 CloudType string `json:"cloud_type"` 52 ConsistentLevel string `json:"consistent_level"` 53 ObjectType string `json:"object_type"` 54 OrderID string `json:"order_id"` 55 ProductID string `json:"product_id"` 56 ProtectType string `json:"protect_type"` 57 Size int `json:"size"` 58 SpecCode string `json:"spec_code"` 59 Status string `json:"status"` 60 StorageUnit string `json:"storage_unit"` 61 Used int `json:"used"` 62 FrozenScene string `json:"frozen_scene"` 63 } 64 65 type ResourceResp struct { 66 ExtraInfo ResourceExtraInfo `json:"extra_info"` 67 ID string `json:"id"` 68 Name string `json:"name"` 69 ProtectStatus string `json:"protect_status"` 70 Size int `json:"size"` 71 Type string `json:"type"` 72 BackupSize int `json:"backup_size"` 73 BackupCount int `json:"backup_count"` 74 } 75 76 func (r commonResult) Extract() (*Vault, error) { 77 var s struct { 78 Vault *Vault `json:"vault"` 79 } 80 err := r.ExtractInto(&s) 81 return s.Vault, err 82 } 83 84 type AssociateResourcesResult struct { 85 golangsdk.Result 86 } 87 88 func (r AssociateResourcesResult) Extract() ([]string, error) { 89 var s struct { 90 AddResourceIDs []string `json:"add_resource_ids"` 91 } 92 if r.Err != nil { 93 return nil, r.Err 94 } 95 err := r.ExtractInto(&s) 96 if err != nil { 97 return nil, fmt.Errorf("failed to extract Associated Resource IDs") 98 } 99 return s.AddResourceIDs, nil 100 } 101 102 type DissociateResourcesResult struct { 103 golangsdk.Result 104 } 105 106 func (r DissociateResourcesResult) Extract() ([]string, error) { 107 var s struct { 108 RemoveResourceIDs []string `json:"remove_resource_ids"` 109 } 110 if r.Err != nil { 111 return nil, r.Err 112 } 113 err := r.ExtractInto(&s) 114 if err != nil { 115 return nil, fmt.Errorf("failed to extract Dissociated Resource IDs") 116 } 117 return s.RemoveResourceIDs, nil 118 } 119 120 type BindPolicyResult struct { 121 golangsdk.Result 122 } 123 124 type PolicyBinding struct { 125 VaultID string `json:"vault_id"` 126 PolicyID string `json:"policy_id"` 127 } 128 129 func (r BindPolicyResult) Extract() (*PolicyBinding, error) { 130 var s struct { 131 PolicyBinding *PolicyBinding `json:"associate_policy"` 132 } 133 err := r.ExtractInto(&s) 134 return s.PolicyBinding, err 135 } 136 137 type UnbindPolicyResult struct { 138 golangsdk.Result 139 } 140 141 func (r UnbindPolicyResult) Extract() (*PolicyBinding, error) { 142 var s struct { 143 PolicyBinding *PolicyBinding `json:"dissociate_policy"` 144 } 145 err := r.ExtractInto(&s) 146 return s.PolicyBinding, err 147 } 148 149 type VaultPage struct { 150 pagination.SinglePageBase 151 } 152 153 func ExtractVaults(r pagination.Page) (*[]Vault, error) { 154 var s struct { 155 Vaults []Vault `json:"vaults"` 156 } 157 err := (r.(VaultPage)).ExtractInto(&s) 158 return &s.Vaults, err 159 }