github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/kms/v1/keys/results.go (about) 1 package keys 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 type commonResult struct { 9 golangsdk.Result 10 } 11 12 // GetRotationResult contains the response body and error from a Get request. 13 type GetRotationResult struct { 14 golangsdk.Result 15 } 16 17 // Key contains all the information associated with a CMK. 18 type Key struct { 19 // Current ID of a CMK 20 KeyID string `json:"key_id"` 21 // ID of a user domain for the key. 22 DomainID string `json:"domain_id"` 23 // Alias of a CMK 24 KeyAlias string `json:"key_alias"` 25 // Region where a CMK resides 26 Realm string `json:"realm"` 27 // Description of a CMK 28 KeyDescription string `json:"key_description"` 29 // Creation time (time stamp) of a CMK 30 CreationDate string `json:"creation_date"` 31 // Scheduled deletion time (time stamp) of a CMK 32 ScheduledDeletionDate string `json:"scheduled_deletion_date"` 33 // State of a CMK 34 KeyState string `json:"key_state"` 35 // Identification of a Master Key. The value 1 indicates a Default 36 // Master Key, and the value 0 indicates a CMK 37 DefaultKeyFlag string `json:"default_key_flag"` 38 // Expiration time 39 ExpirationTime string `json:"expiration_time"` 40 // Origin of a CMK. The default value is kms. The following values 41 // are enumerated: kms indicates that the CMK material is generated by KMS. 42 Origin string `json:"origin"` 43 } 44 45 type ListKey struct { 46 Keys []string `json:"keys"` 47 KeyDetails []Key `json:"key_details"` 48 NextMarker string `json:"next_marker"` 49 Truncated string `json:"truncated"` 50 } 51 52 type DataKey struct { 53 // Current ID of a CMK 54 KeyID string `json:"key_id"` 55 PlainText string `json:"plain_text"` 56 CipherText string `json:"cipher_text"` 57 } 58 59 type EncryptDEK struct { 60 // Current ID of a CMK 61 KeyID string `json:"key_id"` 62 DataKeyLength string `json:"datakey_length"` 63 CipherText string `json:"cipher_text"` 64 } 65 66 type UpdateKeyState struct { 67 // Current ID of a CMK 68 KeyID string `json:"key_id"` 69 KeyState string `json:"key_state"` 70 } 71 72 // CreateResult contains the response body and error from a Create request. 73 type CreateResult struct { 74 commonResult 75 } 76 77 // GetResult contains the response body and error from a Get request. 78 type GetResult struct { 79 commonResult 80 } 81 82 // DeleteResult contains the response body and error from a Delete request. 83 type DeleteResult struct { 84 commonResult 85 } 86 87 // CancelDeleteResult contains the response body and error from a CancelDelete request. 88 type CancelDeleteResult struct { 89 commonResult 90 } 91 92 // UpdateAliasResult contains the response body and error from a UpdateAlias request. 93 type UpdateAliasResult struct { 94 commonResult 95 } 96 97 // UpdateDesResult contains the response body and error from a UpdateDes request. 98 type UpdateDesResult struct { 99 commonResult 100 } 101 102 type DataEncryptResult struct { 103 commonResult 104 } 105 106 type EncryptDEKResult struct { 107 commonResult 108 } 109 110 type ExtractUpdateKeyStateResult struct { 111 commonResult 112 } 113 114 type ListResult struct { 115 commonResult 116 } 117 118 type KeyRotationResult struct { 119 // Key rotation status. The default value is false, indicating that key rotation is disabled. 120 Enabled bool `json:"key_rotation_enabled"` 121 // Rotation interval. The value is an integer in the range 30 to 365. 122 Interval int `json:"rotation_interval"` 123 // Last key rotation time. The timestamp indicates the total microseconds past the start of the epoch date (January 1, 1970). 124 LastRotationTime string `json:"last_rotation_time"` 125 // Number of key rotations. 126 NumberOfRotations int `json:"number_of_rotations"` 127 } 128 129 func (r commonResult) ExtractListKey() (*ListKey, error) { 130 var s *ListKey 131 err := r.ExtractInto(&s) 132 if err != nil { 133 return nil, err 134 } 135 return s, nil 136 } 137 138 func (r commonResult) Extract() (*Key, error) { 139 var s *Key 140 err := r.ExtractInto(&s) 141 if err != nil { 142 return nil, err 143 } 144 return s, nil 145 } 146 147 func (r commonResult) ExtractKeyInfo() (*Key, error) { 148 var s Key 149 err := r.ExtractKeyInfoInto(&s) 150 if err != nil { 151 return nil, err 152 } 153 return &s, nil 154 } 155 156 func (r commonResult) ExtractKeyInfoInto(v interface{}) error { 157 return r.Result.ExtractIntoStructPtr(v, "key_info") 158 } 159 160 func (r commonResult) ExtractDataKey() (*DataKey, error) { 161 var s *DataKey 162 err := r.ExtractInto(&s) 163 if err != nil { 164 return nil, err 165 } 166 return s, nil 167 } 168 169 func (r commonResult) ExtractEncryptDEK() (*EncryptDEK, error) { 170 var s *EncryptDEK 171 err := r.ExtractInto(&s) 172 if err != nil { 173 return nil, err 174 } 175 return s, nil 176 } 177 178 type KeyPage struct { 179 pagination.LinkedPageBase 180 } 181 182 func (r KeyPage) IsEmpty() (bool, error) { 183 s, err := ExtractKeys(r) 184 return len(s) == 0, err 185 } 186 187 func ExtractKeys(r pagination.Page) ([]Key, error) { 188 var s struct { 189 Keys []Key `json:"keys"` 190 } 191 err := (r.(KeyPage)).ExtractInto(&s) 192 if err != nil { 193 return nil, err 194 } 195 return s.Keys, nil 196 } 197 198 func (r GetRotationResult) ExtractResult() (KeyRotationResult, error) { 199 var s KeyRotationResult 200 err := r.ExtractInto(&s) 201 return s, err 202 }