github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/kms/v1/keys/requests.go (about) 1 package keys 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 //"github.com/chnsz/golangsdk/pagination" 6 ) 7 8 type CreateOpts struct { 9 // Alias of a CMK 10 KeyAlias string `json:"key_alias" required:"true"` 11 // CMK description 12 KeyDescription string `json:"key_description,omitempty"` 13 // Region where a CMK resides 14 Realm string `json:"realm,omitempty"` 15 // Purpose of a CMK (The default value is Encrypt_Decrypt) 16 KeyUsage string `json:"key_usage,omitempty"` 17 // Key Algorithm 18 KeySpec string `json:"key_spec,omitempty"` 19 // Enterprise project id 20 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 21 // Key source, the value can be kms or external, the default value is kms. 22 Origin string `json:"origin,omitempty"` 23 // Keystore id, default value is the KMS default keystore id 24 KeyStoreID string `json:"keystore_id,omitempty"` 25 } 26 27 type ImportMaterialOpts struct { 28 // The ID of the key. 29 KeyID string `json:"key_id" required:"true"` 30 // Key import token in Base64 format. 31 // It matches the regular expression ^[0-9a-zA-Z+/=]{200,6144}$. 32 ImportToken string `json:"import_token" required:"true"` 33 // Encrypted symmetric key material in Base64 format. 34 // It matches the regular expression ^[0-9a-zA-Z+/=]{344,360}$. 35 // If an asymmetric key is imported, this parameter is a temporary intermediate key used to encrypt the private key. 36 EncryptedKeyMaterial string `json:"encrypted_key_material" required:"true"` 37 // Private key encrypted using a temporary intermediate key. 38 // This parameter is required for importing an asymmetric key. 39 // The value must be encoded using in Base64 and match the following regular expression: ^[0-9a-zA-Z+/=]{200,6144}$ 40 EncryptedPrivatekey string `json:"encrypted_privatekey,omitempty"` 41 // Expiration time of the key material. 42 ExpirationTime string `json:"expiration_time,omitempty"` 43 // 36-byte sequence number of a request message 44 Sequence string `json:"sequence,omitempty"` 45 } 46 47 type DeleteOpts struct { 48 // ID of a CMK 49 KeyID string `json:"key_id" required:"true"` 50 // Number of days after which a CMK is scheduled to be deleted 51 // (The value ranges from 7 to 1096.) 52 PendingDays string `json:"pending_days" required:"true"` 53 } 54 55 type DeleteKeyMaterialOpts struct { 56 // ID of the key 57 KeyID string `json:"key_id" required:"true"` 58 // 36-byte sequence number of a request message 59 Sequence string `json:"sequence,omitempty"` 60 } 61 62 type UpdateAliasOpts struct { 63 // ID of a CMK 64 KeyID string `json:"key_id" required:"true"` 65 // CMK description 66 KeyAlias string `json:"key_alias" required:"true"` 67 } 68 69 type UpdateDesOpts struct { 70 // ID of a CMK 71 KeyID string `json:"key_id" required:"true"` 72 // CMK description 73 KeyDescription string `json:"key_description" required:"true"` 74 } 75 76 type DataEncryptOpts struct { 77 // ID of a CMK 78 KeyID string `json:"key_id" required:"true"` 79 // CMK description 80 EncryptionContext string `json:"encryption_context,omitempty"` 81 // 36-byte serial number of a request message 82 DatakeyLength string `json:"datakey_length,omitempty"` 83 } 84 85 type EncryptDEKOpts struct { 86 // ID of a CMK 87 KeyID string `json:"key_id" required:"true"` 88 // CMK description 89 EncryptionContext string `json:"encryption_context,omitempty"` 90 // 36-byte serial number of a request message 91 DataKeyPlainLength string `json:"datakey_plain_length,omitempty"` 92 // Both the plaintext (64 bytes) of a DEK and the SHA-256 hash value (32 bytes) 93 // of the plaintext are expressed as a hexadecimal character string. 94 PlainText string `json:"plain_text" required:"true"` 95 } 96 97 // ListOpts holds options for listing Volumes. It is passed to the volumes.List 98 // function. 99 type ListOpts struct { 100 // State of a CMK 101 KeyState string `json:"key_state,omitempty"` 102 Limit string `json:"limit,omitempty"` 103 Marker string `json:"marker,omitempty"` 104 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 105 } 106 107 // ToKeyCreateMap assembles a request body based on the contents of a 108 // CreateOpts. 109 func (opts CreateOpts) ToKeyCreateMap() (map[string]interface{}, error) { 110 return golangsdk.BuildRequestBody(opts, "") 111 } 112 113 func (opts ImportMaterialOpts) ToKeyMaterialImportMap() (map[string]interface{}, error) { 114 return golangsdk.BuildRequestBody(opts, "") 115 } 116 117 func (opts DeleteKeyMaterialOpts) ToKeyMaterialDeleteMap() (map[string]interface{}, error) { 118 return golangsdk.BuildRequestBody(opts, "") 119 } 120 121 // ToKeyDeleteMap assembles a request body based on the contents of a 122 // DeleteOpts. 123 func (opts DeleteOpts) ToKeyDeleteMap() (map[string]interface{}, error) { 124 return golangsdk.BuildRequestBody(opts, "") 125 } 126 127 // ToKeyUpdateAliasMap assembles a request body based on the contents of a 128 // UpdateAliasOpts. 129 func (opts UpdateAliasOpts) ToKeyUpdateAliasMap() (map[string]interface{}, error) { 130 return golangsdk.BuildRequestBody(opts, "") 131 } 132 133 // ToKeyUpdateDesMap assembles a request body based on the contents of a 134 // UpdateDesOpts. 135 func (opts UpdateDesOpts) ToKeyUpdateDesMap() (map[string]interface{}, error) { 136 return golangsdk.BuildRequestBody(opts, "") 137 } 138 139 func (opts DataEncryptOpts) ToDataEncryptMap() (map[string]interface{}, error) { 140 return golangsdk.BuildRequestBody(opts, "") 141 } 142 143 func (opts EncryptDEKOpts) ToEncryptDEKMap() (map[string]interface{}, error) { 144 return golangsdk.BuildRequestBody(opts, "") 145 } 146 147 func (opts ListOpts) ToKeyListMap() (map[string]interface{}, error) { 148 return golangsdk.BuildRequestBody(opts, "") 149 } 150 151 type CreateOptsBuilder interface { 152 ToKeyCreateMap() (map[string]interface{}, error) 153 } 154 155 type ImportKeyMaterialOptsBuilder interface { 156 ToKeyMaterialImportMap() (map[string]interface{}, error) 157 } 158 159 type DeleteOptsBuilder interface { 160 ToKeyDeleteMap() (map[string]interface{}, error) 161 } 162 163 type DeleteKeyMaterialOptsBuilder interface { 164 ToKeyMaterialDeleteMap() (map[string]interface{}, error) 165 } 166 167 type UpdateAliasOptsBuilder interface { 168 ToKeyUpdateAliasMap() (map[string]interface{}, error) 169 } 170 171 type UpdateDesOptsBuilder interface { 172 ToKeyUpdateDesMap() (map[string]interface{}, error) 173 } 174 175 type DataEncryptOptsBuilder interface { 176 ToDataEncryptMap() (map[string]interface{}, error) 177 } 178 179 type EncryptDEKOptsBuilder interface { 180 ToEncryptDEKMap() (map[string]interface{}, error) 181 } 182 183 type ListOptsBuilder interface { 184 ToKeyListMap() (map[string]interface{}, error) 185 } 186 187 // Create will create a new key based on the values in CreateOpts. To ExtractKeyInfo 188 // the key object from the response, call the ExtractKeyInfo method on the 189 // CreateResult. 190 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 191 b, err := opts.ToKeyCreateMap() 192 if err != nil { 193 r.Err = err 194 return 195 } 196 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 197 OkCodes: []int{200}, 198 }) 199 return 200 } 201 202 // ImportKeyMaterial will import a key material for a pending import key. 203 func ImportKeyMaterial(client *golangsdk.ServiceClient, opts ImportKeyMaterialOptsBuilder) (r ImportKeyMaterialResult) { 204 b, err := opts.ToKeyMaterialImportMap() 205 if err != nil { 206 r.Err = err 207 return 208 } 209 _, r.Err = client.Post(importKeyMaterialURL(client), b, &r.Body, nil) 210 return 211 } 212 213 // Get retrieves the key with the provided ID. To extract the key object 214 // from the response, call the Extract method on the GetResult. 215 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 216 b := map[string]interface{}{"key_id": id} 217 _, r.Err = client.Post(getURL(client), &b, &r.Body, &golangsdk.RequestOpts{ 218 OkCodes: []int{200}, 219 }) 220 return 221 } 222 223 // Delete will delete the existing key with the provided ID. 224 func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder) (r DeleteResult) { 225 b, err := opts.ToKeyDeleteMap() 226 if err != nil { 227 r.Err = err 228 return 229 } 230 _, r.Err = client.Post(deleteURL(client), b, &r.Body, &golangsdk.RequestOpts{ 231 OkCodes: []int{200}, 232 JSONResponse: &r.Body, 233 }) 234 return 235 } 236 237 // DeleteKeyMaterial will delete the existing key material with the keyID. 238 func DeleteKeyMaterial(client *golangsdk.ServiceClient, opts DeleteKeyMaterialOptsBuilder) (r DeleteKeyMaterialResult) { 239 b, err := opts.ToKeyMaterialDeleteMap() 240 if err != nil { 241 r.Err = err 242 return 243 } 244 _, r.Err = client.Post(deleteKeyMaterialURL(client), b, &r.Body, nil) 245 return 246 } 247 248 func UpdateAlias(client *golangsdk.ServiceClient, opts UpdateAliasOptsBuilder) (r UpdateAliasResult) { 249 b, err := opts.ToKeyUpdateAliasMap() 250 if err != nil { 251 r.Err = err 252 return 253 } 254 _, r.Err = client.Post(updateAliasURL(client), b, &r.Body, &golangsdk.RequestOpts{ 255 OkCodes: []int{200}, 256 }) 257 return 258 } 259 260 func UpdateDes(client *golangsdk.ServiceClient, opts UpdateDesOptsBuilder) (r UpdateDesResult) { 261 b, err := opts.ToKeyUpdateDesMap() 262 if err != nil { 263 r.Err = err 264 return 265 } 266 _, r.Err = client.Post(updateDesURL(client), b, &r.Body, &golangsdk.RequestOpts{ 267 OkCodes: []int{200}, 268 }) 269 return 270 } 271 272 func DataEncryptGet(client *golangsdk.ServiceClient, opts DataEncryptOptsBuilder) (r DataEncryptResult) { 273 b, err := opts.ToDataEncryptMap() 274 if err != nil { 275 r.Err = err 276 return 277 } 278 _, r.Err = client.Post(dataEncryptURL(client), b, &r.Body, &golangsdk.RequestOpts{ 279 OkCodes: []int{200}, 280 }) 281 return 282 } 283 284 func DataEncryptGetWithoutPlaintext(client *golangsdk.ServiceClient, opts DataEncryptOptsBuilder) (r DataEncryptResult) { 285 b, err := opts.ToDataEncryptMap() 286 if err != nil { 287 r.Err = err 288 return 289 } 290 _, r.Err = client.Post(dataEncryptURL(client), b, &r.Body, &golangsdk.RequestOpts{ 291 OkCodes: []int{200}, 292 }) 293 return 294 } 295 296 func EncryptDEKGet(client *golangsdk.ServiceClient, opts EncryptDEKOptsBuilder) (r EncryptDEKResult) { 297 b, err := opts.ToEncryptDEKMap() 298 if err != nil { 299 r.Err = err 300 return 301 } 302 _, r.Err = client.Post(encryptDEKURL(client), b, &r.Body, &golangsdk.RequestOpts{ 303 OkCodes: []int{200}, 304 }) 305 return 306 } 307 308 func EnableKey(client *golangsdk.ServiceClient, id string) (r ExtractUpdateKeyStateResult) { 309 b := map[string]interface{}{"key_id": id} 310 _, r.Err = client.Post(enableKeyURL(client), b, &r.Body, &golangsdk.RequestOpts{ 311 OkCodes: []int{200}, 312 }) 313 return 314 } 315 316 func DisableKey(client *golangsdk.ServiceClient, id string) (r ExtractUpdateKeyStateResult) { 317 b := map[string]interface{}{"key_id": id} 318 _, r.Err = client.Post(disableKeyURL(client), b, &r.Body, &golangsdk.RequestOpts{ 319 OkCodes: []int{200}, 320 }) 321 return 322 } 323 324 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { 325 b, err := opts.ToKeyListMap() 326 if err != nil { 327 r.Err = err 328 return 329 } 330 _, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{ 331 OkCodes: []int{200}, 332 }) 333 return 334 } 335 336 func ListAllKeys(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { 337 b, err := opts.ToKeyListMap() 338 if err != nil { 339 r.Err = err 340 return 341 } 342 _, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{ 343 OkCodes: []int{200}, 344 }) 345 return 346 } 347 348 //func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r GetResult) { 349 // //url := listURL(client) 350 // //if opts != nil { 351 // // query, err := opts.ToKeyListQuery() 352 // // if err != nil { 353 // // return pagination.Pager{Err: err} 354 // // } 355 // // url += query 356 // //} 357 // b, err := opts.ToKeyListQuery() 358 // if err != nil { 359 // r.Err = err 360 // return 361 // } 362 // _, r.Err = client.Post(listURL(client), b, &r.Body, &golangsdk.RequestOpts{ 363 // OkCodes: []int{200}, 364 // }) 365 // return 366 // 367 // //return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 368 // // return KeyPage{pagination.LinkedPageBase{PageResult: r}} 369 // //}) 370 //}