| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using Azure.Core; |
| | 5 | | using Azure.Core.Pipeline; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | |
|
| | 11 | | namespace Azure.Security.KeyVault.Keys |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// The KeyClient provides synchronous and asynchronous methods to manage <see cref="KeyVaultKey"/> in the Azure Key |
| | 15 | | /// supports creating, retrieving, updating, deleting, purging, backing up, restoring, and listing the <see cref="Ke |
| | 16 | | /// The client also supports listing <see cref="DeletedKey"/> for a soft-delete enabled Azure Key Vault. |
| | 17 | | /// </summary> |
| | 18 | | public class KeyClient |
| | 19 | | { |
| | 20 | | internal const string KeysPath = "/keys/"; |
| | 21 | | internal const string DeletedKeysPath = "/deletedkeys/"; |
| | 22 | |
|
| | 23 | | private readonly KeyVaultPipeline _pipeline; |
| | 24 | |
|
| | 25 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Initializes a new instance of the <see cref="KeyClient"/> class for mocking. |
| | 29 | | /// </summary> |
| 838 | 30 | | protected KeyClient() |
| | 31 | | { |
| 838 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Initializes a new instance of the <see cref="KeyClient"/> class for the specified vault. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="vaultUri">A <see cref="Uri"/> to the vault on which the client operates. Appears as "DNS Name" |
| | 38 | | /// <param name="credential">A <see cref="TokenCredential"/> used to authenticate requests to the vault, such as |
| | 39 | | /// <exception cref="ArgumentNullException"><paramref name="vaultUri"/> or <paramref name="credential"/> is null |
| | 40 | | public KeyClient(Uri vaultUri, TokenCredential credential) |
| 0 | 41 | | : this(vaultUri, credential, null) |
| | 42 | | { |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Initializes a new instance of the <see cref="KeyClient"/> class for the specified vault. |
| | 47 | | /// </summary> |
| | 48 | | /// <param name="vaultUri">A <see cref="Uri"/> to the vault on which the client operates. Appears as "DNS Name" |
| | 49 | | /// <param name="credential">A <see cref="TokenCredential"/> used to authenticate requests to the vault, such as |
| | 50 | | /// <param name="options"><see cref="KeyClientOptions"/> that allow to configure the management of the request s |
| | 51 | | /// <exception cref="ArgumentNullException"><paramref name="vaultUri"/> or <paramref name="credential"/> is null |
| 838 | 52 | | public KeyClient(Uri vaultUri, TokenCredential credential, KeyClientOptions options) |
| | 53 | | { |
| 838 | 54 | | Argument.AssertNotNull(vaultUri, nameof(vaultUri)); |
| 838 | 55 | | Argument.AssertNotNull(credential, nameof(credential)); |
| | 56 | |
|
| 838 | 57 | | options ??= new KeyClientOptions(); |
| 838 | 58 | | string apiVersion = options.GetVersionString(); |
| | 59 | |
|
| 838 | 60 | | HttpPipeline pipeline = HttpPipelineBuilder.Build(options, |
| 838 | 61 | | new ChallengeBasedAuthenticationPolicy(credential)); |
| | 62 | |
|
| 838 | 63 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 838 | 64 | | _pipeline = new KeyVaultPipeline(vaultUri, apiVersion, pipeline, _clientDiagnostics); |
| 838 | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Gets the <see cref="Uri"/> of the vault used to create this instance of the <see cref="KeyClient"/>. |
| | 69 | | /// </summary> |
| 0 | 70 | | public virtual Uri VaultUri => _pipeline.VaultUri; |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Creates and stores a new key in Key Vault. The create key operation can be used to create any key type in Az |
| | 74 | | /// If the named key already exists, Azure Key Vault creates a new version of the key. It requires the keys/crea |
| | 75 | | /// </summary> |
| | 76 | | /// <param name="name">The name of the key.</param> |
| | 77 | | /// <param name="keyType">The type of key to create. See <see cref="KeyType"/> for valid values.</param> |
| | 78 | | /// <param name="keyOptions">Specific attributes with information about the key.</param> |
| | 79 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 80 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string, or <paramref name="keyType"/ |
| | 81 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 82 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 83 | | public virtual Response<KeyVaultKey> CreateKey(string name, KeyType keyType, CreateKeyOptions keyOptions = defau |
| | 84 | | { |
| 90 | 85 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| 86 | 86 | | Argument.AssertNotDefault(ref keyType, nameof(keyType)); |
| | 87 | |
|
| 84 | 88 | | var parameters = new KeyRequestParameters(keyType, keyOptions); |
| | 89 | |
|
| 84 | 90 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateKey)}"); |
| 84 | 91 | | scope.AddAttribute("key", name); |
| 84 | 92 | | scope.Start(); |
| | 93 | |
|
| | 94 | | try |
| | 95 | | { |
| 168 | 96 | | return _pipeline.SendRequest(RequestMethod.Post, parameters, () => new KeyVaultKey(name), cancellationTo |
| | 97 | | } |
| 0 | 98 | | catch (Exception e) |
| | 99 | | { |
| 0 | 100 | | scope.Failed(e); |
| 0 | 101 | | throw; |
| | 102 | | } |
| 84 | 103 | | } |
| | 104 | |
|
| | 105 | | /// <summary> |
| | 106 | | /// Creates and stores a new key in Key Vault. The create key operation can be used to create any key type in Az |
| | 107 | | /// If the named key already exists, Azure Key Vault creates a new version of the key. It requires the keys/crea |
| | 108 | | /// </summary> |
| | 109 | | /// <param name="name">The name of the key.</param> |
| | 110 | | /// <param name="keyType">The type of key to create. See <see cref="KeyType"/> for valid values.</param> |
| | 111 | | /// <param name="keyOptions">Specific attributes with information about the key.</param> |
| | 112 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 113 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string, or <paramref name="keyType"/ |
| | 114 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 115 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 116 | | public virtual async Task<Response<KeyVaultKey>> CreateKeyAsync(string name, KeyType keyType, CreateKeyOptions k |
| | 117 | | { |
| 90 | 118 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| 86 | 119 | | Argument.AssertNotDefault(ref keyType, nameof(keyType)); |
| | 120 | |
|
| 84 | 121 | | var parameters = new KeyRequestParameters(keyType, keyOptions); |
| | 122 | |
|
| 84 | 123 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateKey)}"); |
| 84 | 124 | | scope.AddAttribute("key", name); |
| 84 | 125 | | scope.Start(); |
| | 126 | |
|
| | 127 | | try |
| | 128 | | { |
| 168 | 129 | | return await _pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new KeyVaultKey(name), can |
| | 130 | | } |
| 0 | 131 | | catch (Exception e) |
| | 132 | | { |
| 0 | 133 | | scope.Failed(e); |
| 0 | 134 | | throw; |
| | 135 | | } |
| 84 | 136 | | } |
| | 137 | |
|
| | 138 | | /// <summary> |
| | 139 | | /// Creates and stores a new Elliptic Curve key in Key Vault. If the named key already exists, |
| | 140 | | /// Azure Key Vault creates a new version of the key. It requires the keys/create permission. |
| | 141 | | /// </summary> |
| | 142 | | /// <param name="ecKeyOptions">The key options object containing information about the Elliptic Curve key being |
| | 143 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 144 | | /// <exception cref="ArgumentNullException"><paramref name="ecKeyOptions"/> is null.</exception> |
| | 145 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 146 | | public virtual Response<KeyVaultKey> CreateEcKey(CreateEcKeyOptions ecKeyOptions, CancellationToken cancellation |
| | 147 | | { |
| 56 | 148 | | Argument.AssertNotNull(ecKeyOptions, nameof(ecKeyOptions)); |
| | 149 | |
|
| 54 | 150 | | var parameters = new KeyRequestParameters(ecKeyOptions); |
| | 151 | |
|
| 54 | 152 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateEcKey)}"); |
| 54 | 153 | | scope.AddAttribute("key", ecKeyOptions.Name); |
| 54 | 154 | | scope.Start(); |
| | 155 | |
|
| | 156 | | try |
| | 157 | | { |
| 108 | 158 | | return _pipeline.SendRequest(RequestMethod.Post, parameters, () => new KeyVaultKey(ecKeyOptions.Name), c |
| | 159 | | } |
| 0 | 160 | | catch (Exception e) |
| | 161 | | { |
| 0 | 162 | | scope.Failed(e); |
| 0 | 163 | | throw; |
| | 164 | | } |
| 54 | 165 | | } |
| | 166 | |
|
| | 167 | | /// <summary> |
| | 168 | | /// Creates and stores a new Elliptic Curve key in Key Vault. If the named key already exists, |
| | 169 | | /// Azure Key Vault creates a new version of the key. It requires the keys/create permission. |
| | 170 | | /// </summary> |
| | 171 | | /// <param name="ecKeyOptions">The key options object containing information about the Elliptic Curve key being |
| | 172 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 173 | | /// <exception cref="ArgumentNullException"><paramref name="ecKeyOptions"/> is null.</exception> |
| | 174 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 175 | | public virtual async Task<Response<KeyVaultKey>> CreateEcKeyAsync(CreateEcKeyOptions ecKeyOptions, CancellationT |
| | 176 | | { |
| 56 | 177 | | Argument.AssertNotNull(ecKeyOptions, nameof(ecKeyOptions)); |
| | 178 | |
|
| 54 | 179 | | var parameters = new KeyRequestParameters(ecKeyOptions); |
| | 180 | |
|
| 54 | 181 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateEcKey)}"); |
| 54 | 182 | | scope.AddAttribute("key", ecKeyOptions.Name); |
| 54 | 183 | | scope.Start(); |
| | 184 | |
|
| | 185 | | try |
| | 186 | | { |
| 108 | 187 | | return await _pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new KeyVaultKey(ecKeyOptio |
| | 188 | | } |
| 0 | 189 | | catch (Exception e) |
| | 190 | | { |
| 0 | 191 | | scope.Failed(e); |
| 0 | 192 | | throw; |
| | 193 | | } |
| 54 | 194 | | } |
| | 195 | |
|
| | 196 | | /// <summary> |
| | 197 | | /// Creates and stores a new RSA key in Key Vault. If the named key already exists, Azure Key Vault creates a ne |
| | 198 | | /// version of the key. It requires the keys/create permission. |
| | 199 | | /// </summary> |
| | 200 | | /// <param name="rsaKeyOptions">The key options object containing information about the RSA key being created.</ |
| | 201 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 202 | | /// <exception cref="ArgumentNullException"><paramref name="rsaKeyOptions"/> is null.</exception> |
| | 203 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 204 | | public virtual Response<KeyVaultKey> CreateRsaKey(CreateRsaKeyOptions rsaKeyOptions, CancellationToken cancellat |
| | 205 | | { |
| 24 | 206 | | Argument.AssertNotNull(rsaKeyOptions, nameof(rsaKeyOptions)); |
| | 207 | |
|
| 22 | 208 | | var parameters = new KeyRequestParameters(rsaKeyOptions); |
| | 209 | |
|
| 22 | 210 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateRsaKey)}"); |
| 22 | 211 | | scope.AddAttribute("key", rsaKeyOptions.Name); |
| 22 | 212 | | scope.Start(); |
| | 213 | |
|
| | 214 | | try |
| | 215 | | { |
| 44 | 216 | | return _pipeline.SendRequest(RequestMethod.Post, parameters, () => new KeyVaultKey(rsaKeyOptions.Name), |
| | 217 | | } |
| 0 | 218 | | catch (Exception e) |
| | 219 | | { |
| 0 | 220 | | scope.Failed(e); |
| 0 | 221 | | throw; |
| | 222 | | } |
| 22 | 223 | | } |
| | 224 | |
|
| | 225 | | /// <summary> |
| | 226 | | /// Creates and stores a new RSA key in Key Vault. If the named key already exists, Azure Key Vault creates a ne |
| | 227 | | /// version of the key. It requires the keys/create permission. |
| | 228 | | /// </summary> |
| | 229 | | /// <param name="rsaKeyOptions">The key options object containing information about the RSA key being created.</ |
| | 230 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 231 | | /// <exception cref="ArgumentNullException"><paramref name="rsaKeyOptions"/> is null.</exception> |
| | 232 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 233 | | public virtual async Task<Response<KeyVaultKey>> CreateRsaKeyAsync(CreateRsaKeyOptions rsaKeyOptions, Cancellati |
| | 234 | | { |
| 24 | 235 | | Argument.AssertNotNull(rsaKeyOptions, nameof(rsaKeyOptions)); |
| | 236 | |
|
| 22 | 237 | | var parameters = new KeyRequestParameters(rsaKeyOptions); |
| | 238 | |
|
| 22 | 239 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(CreateRsaKey)}"); |
| 22 | 240 | | scope.AddAttribute("key", rsaKeyOptions.Name); |
| 22 | 241 | | scope.Start(); |
| | 242 | |
|
| | 243 | | try |
| | 244 | | { |
| 44 | 245 | | return await _pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new KeyVaultKey(rsaKeyOpti |
| | 246 | | } |
| 0 | 247 | | catch (Exception e) |
| | 248 | | { |
| 0 | 249 | | scope.Failed(e); |
| 0 | 250 | | throw; |
| | 251 | | } |
| 22 | 252 | | } |
| | 253 | |
|
| | 254 | | /// <summary> |
| | 255 | | /// The update key operation changes specified attributes of a stored key and |
| | 256 | | /// can be applied to any key type and key version stored in Azure Key Vault. |
| | 257 | | /// </summary> |
| | 258 | | /// <remarks> |
| | 259 | | /// In order to perform this operation, the key must already exist in the Key |
| | 260 | | /// Vault. Note: The cryptographic material of a key itself cannot be changed. |
| | 261 | | /// This operation requires the keys/update permission. |
| | 262 | | /// </remarks> |
| | 263 | | /// <param name="properties">The <see cref="KeyProperties"/> object with updated properties.</param> |
| | 264 | | /// <param name="keyOperations">Optional list of supported <see cref="KeyOperation"/>. If null, no changes will |
| | 265 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 266 | | /// <exception cref="ArgumentNullException"><paramref name="properties"/> is null, or <see cref="KeyProperties.V |
| | 267 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 268 | | public virtual Response<KeyVaultKey> UpdateKeyProperties(KeyProperties properties, IEnumerable<KeyOperation> key |
| | 269 | | { |
| 42 | 270 | | Argument.AssertNotNull(properties, nameof(properties)); |
| 38 | 271 | | Argument.AssertNotNull(properties.Version, $"{nameof(properties)}.{nameof(properties.Version)}"); |
| | 272 | |
|
| 36 | 273 | | var parameters = new KeyRequestParameters(properties, keyOperations); |
| | 274 | |
|
| 36 | 275 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(UpdateKeyProperties)}"); |
| 36 | 276 | | scope.AddAttribute("key", properties.Name); |
| 36 | 277 | | scope.Start(); |
| | 278 | |
|
| | 279 | | try |
| | 280 | | { |
| 72 | 281 | | return _pipeline.SendRequest(RequestMethod.Patch, parameters, () => new KeyVaultKey(properties.Name), ca |
| | 282 | | } |
| 0 | 283 | | catch (Exception e) |
| | 284 | | { |
| 0 | 285 | | scope.Failed(e); |
| 0 | 286 | | throw; |
| | 287 | | } |
| 36 | 288 | | } |
| | 289 | |
|
| | 290 | | /// <summary> |
| | 291 | | /// The update key operation changes specified attributes of a stored key and |
| | 292 | | /// can be applied to any key type and key version stored in Azure Key Vault. |
| | 293 | | /// </summary> |
| | 294 | | /// <remarks> |
| | 295 | | /// In order to perform this operation, the key must already exist in the Key |
| | 296 | | /// Vault. Note: The cryptographic material of a key itself cannot be changed. |
| | 297 | | /// This operation requires the keys/update permission. |
| | 298 | | /// </remarks> |
| | 299 | | /// <param name="properties">The <see cref="KeyProperties"/> object with updated properties.</param> |
| | 300 | | /// <param name="keyOperations">Optional list of supported <see cref="KeyOperation"/>. If null, no changes will |
| | 301 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 302 | | /// <exception cref="ArgumentNullException"><paramref name="properties"/> or <paramref name="keyOperations"/> is |
| | 303 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 304 | | public virtual async Task<Response<KeyVaultKey>> UpdateKeyPropertiesAsync(KeyProperties properties, IEnumerable< |
| | 305 | | { |
| 42 | 306 | | Argument.AssertNotNull(properties, nameof(properties)); |
| 38 | 307 | | Argument.AssertNotNull(properties.Version, $"{nameof(properties)}.{nameof(properties.Version)}"); |
| | 308 | |
|
| 36 | 309 | | var parameters = new KeyRequestParameters(properties, keyOperations); |
| | 310 | |
|
| 36 | 311 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(UpdateKeyProperties)}"); |
| 36 | 312 | | scope.AddAttribute("key", properties.Name); |
| 36 | 313 | | scope.Start(); |
| | 314 | |
|
| | 315 | | try |
| | 316 | | { |
| 72 | 317 | | return await _pipeline.SendRequestAsync(RequestMethod.Patch, parameters, () => new KeyVaultKey(propertie |
| | 318 | | } |
| 0 | 319 | | catch (Exception e) |
| | 320 | | { |
| 0 | 321 | | scope.Failed(e); |
| 0 | 322 | | throw; |
| | 323 | | } |
| 36 | 324 | | } |
| | 325 | |
|
| | 326 | | /// <summary> |
| | 327 | | /// Gets the public part of a stored key. |
| | 328 | | /// </summary> |
| | 329 | | /// <remarks> |
| | 330 | | /// The get key operation is applicable to all key types. If the requested key |
| | 331 | | /// is symmetric, then no key is released in the response. This |
| | 332 | | /// operation requires the keys/get permission. |
| | 333 | | /// </remarks> |
| | 334 | | /// <param name="name">The name of the key.</param> |
| | 335 | | /// <param name="version">The version of the key.</param> |
| | 336 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 337 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 338 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 339 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 340 | | public virtual Response<KeyVaultKey> GetKey(string name, string version = null, CancellationToken cancellationTo |
| | 341 | | { |
| 64 | 342 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 343 | |
|
| 60 | 344 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(GetKey)}"); |
| 60 | 345 | | scope.AddAttribute("key", name); |
| 60 | 346 | | scope.Start(); |
| | 347 | |
|
| | 348 | | try |
| | 349 | | { |
| 104 | 350 | | return _pipeline.SendRequest(RequestMethod.Get, () => new KeyVaultKey(name), cancellationToken, KeysPath |
| | 351 | | } |
| 16 | 352 | | catch (Exception e) |
| | 353 | | { |
| 16 | 354 | | scope.Failed(e); |
| 16 | 355 | | throw; |
| | 356 | | } |
| 44 | 357 | | } |
| | 358 | |
|
| | 359 | | /// <summary> |
| | 360 | | /// Gets the public part of a stored key. |
| | 361 | | /// </summary> |
| | 362 | | /// <remarks> |
| | 363 | | /// The get key operation is applicable to all key types. If the requested key |
| | 364 | | /// is symmetric, then no key is released in the response. This |
| | 365 | | /// operation requires the keys/get permission. |
| | 366 | | /// </remarks> |
| | 367 | | /// <param name="name">The name of the key.</param> |
| | 368 | | /// <param name="version">The version of the key.</param> |
| | 369 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 370 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 371 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 372 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 373 | | public virtual async Task<Response<KeyVaultKey>> GetKeyAsync(string name, string version = null, CancellationTok |
| | 374 | | { |
| 64 | 375 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 376 | |
|
| 60 | 377 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(GetKey)}"); |
| 60 | 378 | | scope.AddAttribute("key", name); |
| 60 | 379 | | scope.Start(); |
| | 380 | |
|
| | 381 | | try |
| | 382 | | { |
| 104 | 383 | | return await _pipeline.SendRequestAsync(RequestMethod.Get, () => new KeyVaultKey(name), cancellationToke |
| | 384 | | } |
| 16 | 385 | | catch (Exception e) |
| | 386 | | { |
| 16 | 387 | | scope.Failed(e); |
| 16 | 388 | | throw; |
| | 389 | | } |
| 44 | 390 | | } |
| | 391 | |
|
| | 392 | | /// <summary> |
| | 393 | | /// Lists the properties of all keys in the specified vault. You can use the returned <see cref="KeyProperties.N |
| | 394 | | /// </summary> |
| | 395 | | /// <remarks> |
| | 396 | | /// Retrieves a list of the keys in the Key Vault that contains the public part of a stored key. |
| | 397 | | /// The list operation is applicable to all key types, however only the base key identifier, |
| | 398 | | /// attributes, and tags are provided in the response. Individual versions of a |
| | 399 | | /// key are not listed in the response. This operation requires the keys/list |
| | 400 | | /// permission. |
| | 401 | | /// </remarks> |
| | 402 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 403 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 404 | | public virtual Pageable<KeyProperties> GetPropertiesOfKeys(CancellationToken cancellationToken = default) |
| | 405 | | { |
| 4 | 406 | | Uri firstPageUri = _pipeline.CreateFirstPageUri(KeysPath); |
| | 407 | |
|
| 24 | 408 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 409 | | } |
| | 410 | |
|
| | 411 | | /// <summary> |
| | 412 | | /// Lists the properties of all keys in the specified vault. You can use the returned <see cref="KeyProperties.N |
| | 413 | | /// </summary> |
| | 414 | | /// <remarks> |
| | 415 | | /// Retrieves a list of the keys in the Key Vault that contains the public part of a stored key. |
| | 416 | | /// The list operation is applicable to all key types, however only the base key identifier, |
| | 417 | | /// attributes, and tags are provided in the response. Individual versions of a |
| | 418 | | /// key are not listed in the response. This operation requires the keys/list |
| | 419 | | /// permission. |
| | 420 | | /// </remarks> |
| | 421 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 422 | | public virtual AsyncPageable<KeyProperties> GetPropertiesOfKeysAsync(CancellationToken cancellationToken = defau |
| | 423 | | { |
| 4 | 424 | | Uri firstPageUri = _pipeline.CreateFirstPageUri(KeysPath); |
| | 425 | |
|
| 24 | 426 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 427 | | } |
| | 428 | |
|
| | 429 | | /// <summary> |
| | 430 | | /// Lists the properties of all versions of the specified key. You can use the returned <see cref="KeyProperties |
| | 431 | | /// </summary> |
| | 432 | | /// <remarks> |
| | 433 | | /// The full key identifier, attributes, and tags are provided in the response. |
| | 434 | | /// This operation requires the keys/list permission. |
| | 435 | | /// </remarks> |
| | 436 | | /// <param name="name">The name of the key.</param> |
| | 437 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 438 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 439 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 440 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 441 | | public virtual Pageable<KeyProperties> GetPropertiesOfKeyVersions(string name, CancellationToken cancellationTok |
| | 442 | | { |
| 8 | 443 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 444 | |
|
| 4 | 445 | | Uri firstPageUri = _pipeline.CreateFirstPageUri($"{KeysPath}{name}/versions"); |
| | 446 | |
|
| 12 | 447 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 448 | | } |
| | 449 | |
|
| | 450 | | /// <summary> |
| | 451 | | /// Lists the properties of all versions of the specified key. You can use the returned <see cref="KeyProperties |
| | 452 | | /// </summary> |
| | 453 | | /// <remarks> |
| | 454 | | /// The full key identifier, attributes, and tags are provided in the response. |
| | 455 | | /// This operation requires the keys/list permission. |
| | 456 | | /// </remarks> |
| | 457 | | /// <param name="name">The name of the key.</param> |
| | 458 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 459 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 460 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 461 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 462 | | public virtual AsyncPageable<KeyProperties> GetPropertiesOfKeyVersionsAsync(string name, CancellationToken cance |
| | 463 | | { |
| 8 | 464 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 465 | |
|
| 4 | 466 | | Uri firstPageUri = _pipeline.CreateFirstPageUri($"{KeysPath}{name}/versions"); |
| | 467 | |
|
| 12 | 468 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 469 | | } |
| | 470 | |
|
| | 471 | | /// <summary> |
| | 472 | | /// Gets the public part of a deleted key. |
| | 473 | | /// </summary> |
| | 474 | | /// <remarks> |
| | 475 | | /// The Get Deleted Key operation is applicable for soft-delete enabled vaults. |
| | 476 | | /// While the operation can be invoked on any vault, it will return an error if |
| | 477 | | /// invoked on a non soft-delete enabled vault. This operation requires the |
| | 478 | | /// keys/get permission. |
| | 479 | | /// </remarks> |
| | 480 | | /// <param name="name">The name of the key.</param> |
| | 481 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 482 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 483 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 484 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 485 | | public virtual Response<DeletedKey> GetDeletedKey(string name, CancellationToken cancellationToken = default) |
| | 486 | | { |
| 12 | 487 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 488 | |
|
| 8 | 489 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(GetDeletedKey)}"); |
| 8 | 490 | | scope.AddAttribute("key", name); |
| 8 | 491 | | scope.Start(); |
| | 492 | |
|
| | 493 | | try |
| | 494 | | { |
| 14 | 495 | | return _pipeline.SendRequest(RequestMethod.Get, () => new DeletedKey(name), cancellationToken, DeletedKe |
| | 496 | | } |
| 2 | 497 | | catch (Exception e) |
| | 498 | | { |
| 2 | 499 | | scope.Failed(e); |
| 2 | 500 | | throw; |
| | 501 | | } |
| 6 | 502 | | } |
| | 503 | |
|
| | 504 | | /// <summary> |
| | 505 | | /// Gets the public part of a deleted key. |
| | 506 | | /// </summary> |
| | 507 | | /// <remarks> |
| | 508 | | /// The Get Deleted Key operation is applicable for soft-delete enabled vaults. |
| | 509 | | /// While the operation can be invoked on any vault, it will return an error if |
| | 510 | | /// invoked on a non soft-delete enabled vault. This operation requires the |
| | 511 | | /// keys/get permission. |
| | 512 | | /// </remarks> |
| | 513 | | /// <param name="name">The name of the key.</param> |
| | 514 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 515 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 516 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 517 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 518 | | public virtual async Task<Response<DeletedKey>> GetDeletedKeyAsync(string name, CancellationToken cancellationTo |
| | 519 | | { |
| 12 | 520 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 521 | |
|
| 8 | 522 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(GetDeletedKey)}"); |
| 8 | 523 | | scope.AddAttribute("key", name); |
| 8 | 524 | | scope.Start(); |
| | 525 | |
|
| | 526 | | try |
| | 527 | | { |
| 14 | 528 | | return await _pipeline.SendRequestAsync(RequestMethod.Get, () => new DeletedKey(name), cancellationToken |
| | 529 | | } |
| 2 | 530 | | catch (Exception e) |
| | 531 | | { |
| 2 | 532 | | scope.Failed(e); |
| 2 | 533 | | throw; |
| | 534 | | } |
| 6 | 535 | | } |
| | 536 | |
|
| | 537 | | /// <summary> |
| | 538 | | /// Deletes a key of any type from storage in Azure Key Vault. |
| | 539 | | /// </summary> |
| | 540 | | /// <remarks> |
| | 541 | | /// The delete key operation cannot be used to remove individual versions of a |
| | 542 | | /// key. This operation removes the cryptographic material associated with the |
| | 543 | | /// key, which means the key is not usable for Sign/Verify, Wrap/Unwrap or |
| | 544 | | /// Encrypt/Decrypt operations. This operation requires the keys/delete |
| | 545 | | /// permission. |
| | 546 | | /// </remarks> |
| | 547 | | /// <param name="name">The name of the key.</param> |
| | 548 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 549 | | /// <returns> |
| | 550 | | /// A <see cref="DeleteKeyOperation"/> to wait on this long-running operation. |
| | 551 | | /// If the Key Vault is soft delete-enabled, you only need to wait for the operation to complete if you need to |
| | 552 | | /// otherwise, the key is deleted automatically on the <see cref="DeletedKey.ScheduledPurgeDate"/>. |
| | 553 | | /// </returns> |
| | 554 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 555 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 556 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 557 | | public virtual DeleteKeyOperation StartDeleteKey(string name, CancellationToken cancellationToken = default) |
| | 558 | | { |
| 28 | 559 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 560 | |
|
| 24 | 561 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(StartDeleteKey)}"); |
| 24 | 562 | | scope.AddAttribute("key", name); |
| 24 | 563 | | scope.Start(); |
| | 564 | |
|
| | 565 | | try |
| | 566 | | { |
| 46 | 567 | | Response<DeletedKey> response = _pipeline.SendRequest(RequestMethod.Delete, () => new DeletedKey(name), |
| 22 | 568 | | return new DeleteKeyOperation(_pipeline, response); |
| | 569 | | } |
| 2 | 570 | | catch (Exception e) |
| | 571 | | { |
| 2 | 572 | | scope.Failed(e); |
| 2 | 573 | | throw; |
| | 574 | | } |
| 22 | 575 | | } |
| | 576 | |
|
| | 577 | | /// <summary> |
| | 578 | | /// Deletes a key of any type from storage in Azure Key Vault. |
| | 579 | | /// </summary> |
| | 580 | | /// <remarks> |
| | 581 | | /// The delete key operation cannot be used to remove individual versions of a |
| | 582 | | /// key. This operation removes the cryptographic material associated with the |
| | 583 | | /// key, which means the key is not usable for Sign/Verify, Wrap/Unwrap or |
| | 584 | | /// Encrypt/Decrypt operations. This operation requires the keys/delete |
| | 585 | | /// permission. |
| | 586 | | /// </remarks> |
| | 587 | | /// <param name="name">The name of the key.</param> |
| | 588 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 589 | | /// <returns> |
| | 590 | | /// A <see cref="DeleteKeyOperation"/> to wait on this long-running operation. |
| | 591 | | /// If the Key Vault is soft delete-enabled, you only need to wait for the operation to complete if you need to |
| | 592 | | /// otherwise, the key is deleted automatically on the <see cref="DeletedKey.ScheduledPurgeDate"/>. |
| | 593 | | /// </returns> |
| | 594 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 595 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 596 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 597 | | public virtual async Task<DeleteKeyOperation> StartDeleteKeyAsync(string name, CancellationToken cancellationTok |
| | 598 | | { |
| 28 | 599 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 600 | |
|
| 24 | 601 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(StartDeleteKey)}"); |
| 24 | 602 | | scope.AddAttribute("key", name); |
| 24 | 603 | | scope.Start(); |
| | 604 | |
|
| | 605 | | try |
| | 606 | | { |
| 46 | 607 | | Response<DeletedKey> response = await _pipeline.SendRequestAsync(RequestMethod.Delete, () => new Deleted |
| 22 | 608 | | return new DeleteKeyOperation(_pipeline, response); |
| | 609 | | } |
| 2 | 610 | | catch (Exception e) |
| | 611 | | { |
| 2 | 612 | | scope.Failed(e); |
| 2 | 613 | | throw; |
| | 614 | | } |
| 22 | 615 | | } |
| | 616 | |
|
| | 617 | | /// <summary> |
| | 618 | | /// Lists the deleted keys in the specified vault. |
| | 619 | | /// </summary> |
| | 620 | | /// <remarks> |
| | 621 | | /// Retrieves a list of the keys in the Key Vault that contains the public part of a deleted key. |
| | 622 | | /// This operation includes deletion-specific information. |
| | 623 | | /// The Get Deleted Keys operation is applicable |
| | 624 | | /// for vaults enabled for soft-delete. While the operation can be invoked on |
| | 625 | | /// any vault, it will return an error if invoked on a non soft-delete enabled |
| | 626 | | /// vault. This operation requires the keys/list permission. |
| | 627 | | /// </remarks> |
| | 628 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 629 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 630 | | public virtual Pageable<DeletedKey> GetDeletedKeys(CancellationToken cancellationToken = default) |
| | 631 | | { |
| 2 | 632 | | Uri firstPageUri = _pipeline.CreateFirstPageUri(DeletedKeysPath); |
| | 633 | |
|
| 12 | 634 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 635 | | } |
| | 636 | |
|
| | 637 | | /// <summary> |
| | 638 | | /// Lists the deleted keys in the specified vault. |
| | 639 | | /// </summary> |
| | 640 | | /// <remarks> |
| | 641 | | /// Retrieves a list of the keys in the Key Vault that contains the public part of a deleted key. |
| | 642 | | /// This operation includes deletion-specific information. |
| | 643 | | /// The Get Deleted Keys operation is applicable |
| | 644 | | /// for vaults enabled for soft-delete. While the operation can be invoked on |
| | 645 | | /// any vault, it will return an error if invoked on a non soft-delete enabled |
| | 646 | | /// vault. This operation requires the keys/list permission. |
| | 647 | | /// </remarks> |
| | 648 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 649 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 650 | | public virtual AsyncPageable<DeletedKey> GetDeletedKeysAsync(CancellationToken cancellationToken = default) |
| | 651 | | { |
| 2 | 652 | | Uri firstPageUri = _pipeline.CreateFirstPageUri(DeletedKeysPath); |
| | 653 | |
|
| 12 | 654 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 655 | | } |
| | 656 | |
|
| | 657 | | /// <summary> |
| | 658 | | /// Permanently deletes the specified key. |
| | 659 | | /// </summary> |
| | 660 | | /// <remarks> |
| | 661 | | /// The Purge Deleted Key operation is applicable for soft-delete enabled |
| | 662 | | /// vaults. While the operation can be invoked on any vault, it will return an |
| | 663 | | /// error if invoked on a non soft-delete enabled vault. This operation |
| | 664 | | /// requires the keys/purge permission. |
| | 665 | | /// </remarks> |
| | 666 | | /// <param name="name">The name of the key.</param> |
| | 667 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 668 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 669 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 670 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 671 | | public virtual Response PurgeDeletedKey(string name, CancellationToken cancellationToken = default) |
| | 672 | | { |
| 4 | 673 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 674 | |
|
| 0 | 675 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(PurgeDeletedKey)}"); |
| 0 | 676 | | scope.AddAttribute("key", name); |
| 0 | 677 | | scope.Start(); |
| | 678 | |
|
| | 679 | | try |
| | 680 | | { |
| 0 | 681 | | return _pipeline.SendRequest(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name); |
| | 682 | | } |
| 0 | 683 | | catch (Exception e) |
| | 684 | | { |
| 0 | 685 | | scope.Failed(e); |
| 0 | 686 | | throw; |
| | 687 | | } |
| 0 | 688 | | } |
| | 689 | |
|
| | 690 | | /// <summary> |
| | 691 | | /// Permanently deletes the specified key. |
| | 692 | | /// </summary> |
| | 693 | | /// <remarks> |
| | 694 | | /// The Purge Deleted Key operation is applicable for soft-delete enabled |
| | 695 | | /// vaults. While the operation can be invoked on any vault, it will return an |
| | 696 | | /// error if invoked on a non soft-delete enabled vault. This operation |
| | 697 | | /// requires the keys/purge permission. |
| | 698 | | /// </remarks> |
| | 699 | | /// <param name="name">The name of the key.</param> |
| | 700 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 701 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 702 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 703 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 704 | | public virtual async Task<Response> PurgeDeletedKeyAsync(string name, CancellationToken cancellationToken = defa |
| | 705 | | { |
| 4 | 706 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 707 | |
|
| 0 | 708 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(PurgeDeletedKey)}"); |
| 0 | 709 | | scope.AddAttribute("key", name); |
| 0 | 710 | | scope.Start(); |
| | 711 | |
|
| | 712 | | try |
| | 713 | | { |
| 0 | 714 | | return await _pipeline.SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name). |
| | 715 | | } |
| 0 | 716 | | catch (Exception e) |
| | 717 | | { |
| 0 | 718 | | scope.Failed(e); |
| 0 | 719 | | throw; |
| | 720 | | } |
| 0 | 721 | | } |
| | 722 | |
|
| | 723 | | /// <summary> |
| | 724 | | /// Recovers the deleted key to its latest version. |
| | 725 | | /// </summary> |
| | 726 | | /// <remarks> |
| | 727 | | /// The Recover Deleted Key operation is applicable for deleted keys in |
| | 728 | | /// soft-delete enabled vaults. It recovers the deleted key back to its latest |
| | 729 | | /// version under /keys. An attempt to recover an non-deleted key will return |
| | 730 | | /// an error. Consider this the inverse of the delete operation on soft-delete |
| | 731 | | /// enabled vaults. This operation requires the keys/recover permission. |
| | 732 | | /// </remarks> |
| | 733 | | /// <param name="name">The name of the key.</param> |
| | 734 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 735 | | /// <returns>A <see cref="RecoverDeletedKeyOperation"/> to wait on this long-running operation.</returns> |
| | 736 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 737 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 738 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 739 | | public virtual RecoverDeletedKeyOperation StartRecoverDeletedKey(string name, CancellationToken cancellationToke |
| | 740 | | { |
| 12 | 741 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 742 | |
|
| 8 | 743 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(StartRecoverDeletedKey)}") |
| 8 | 744 | | scope.AddAttribute("key", name); |
| 8 | 745 | | scope.Start(); |
| | 746 | |
|
| | 747 | | try |
| | 748 | | { |
| 14 | 749 | | Response<KeyVaultKey> response = _pipeline.SendRequest(RequestMethod.Post, () => new KeyVaultKey(name), |
| 6 | 750 | | return new RecoverDeletedKeyOperation(_pipeline, response); |
| | 751 | | } |
| 2 | 752 | | catch (Exception e) |
| | 753 | | { |
| 2 | 754 | | scope.Failed(e); |
| 2 | 755 | | throw; |
| | 756 | | } |
| 6 | 757 | | } |
| | 758 | |
|
| | 759 | | /// <summary> |
| | 760 | | /// Recovers the deleted key to its latest version. |
| | 761 | | /// </summary> |
| | 762 | | /// <remarks> |
| | 763 | | /// The Recover Deleted Key operation is applicable for deleted keys in |
| | 764 | | /// soft-delete enabled vaults. It recovers the deleted key back to its latest |
| | 765 | | /// version under /keys. An attempt to recover an non-deleted key will return |
| | 766 | | /// an error. Consider this the inverse of the delete operation on soft-delete |
| | 767 | | /// enabled vaults. This operation requires the keys/recover permission. |
| | 768 | | /// </remarks> |
| | 769 | | /// <param name="name">The name of the key.</param> |
| | 770 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 771 | | /// <returns>A <see cref="RecoverDeletedKeyOperation"/> to wait on this long-running operation.</returns> |
| | 772 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 773 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 774 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 775 | | public virtual async Task<RecoverDeletedKeyOperation> StartRecoverDeletedKeyAsync(string name, CancellationToken |
| | 776 | | { |
| 12 | 777 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 778 | |
|
| 8 | 779 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(StartRecoverDeletedKey)}") |
| 8 | 780 | | scope.AddAttribute("key", name); |
| 8 | 781 | | scope.Start(); |
| | 782 | |
|
| | 783 | | try |
| | 784 | | { |
| 14 | 785 | | Response<KeyVaultKey> response = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new KeyVault |
| 6 | 786 | | return new RecoverDeletedKeyOperation(_pipeline, response); |
| | 787 | | } |
| 2 | 788 | | catch (Exception e) |
| | 789 | | { |
| 2 | 790 | | scope.Failed(e); |
| 2 | 791 | | throw; |
| | 792 | | } |
| 6 | 793 | | } |
| | 794 | |
|
| | 795 | | /// <summary> |
| | 796 | | /// Requests that a backup of the specified key be downloaded to the client. |
| | 797 | | /// </summary> |
| | 798 | | /// <remarks> |
| | 799 | | /// The Key Backup operation exports a key from Azure Key Vault in a protected |
| | 800 | | /// form. Note that this operation does NOT return the actual key in a form that |
| | 801 | | /// can be used outside the Azure Key Vault system, the returned key |
| | 802 | | /// is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. |
| | 803 | | /// The intent of this operation is to allow a client to GENERATE a key in one |
| | 804 | | /// Azure Key Vault instance, BACKUP the key, and then RESTORE it into another |
| | 805 | | /// Azure Key Vault instance. The BACKUP operation may be used to export, in |
| | 806 | | /// protected form, any key type from Azure Key Vault. Individual versions of a |
| | 807 | | /// key cannot be backed up. BACKUP / RESTORE can be performed within |
| | 808 | | /// geographical boundaries only; meaning that a BACKUP from one geographical |
| | 809 | | /// area cannot be restored to another geographical area. For example, a backup |
| | 810 | | /// from the US geographical area cannot be restored in an EU geographical |
| | 811 | | /// area. This operation requires the key/backup permission. |
| | 812 | | /// </remarks> |
| | 813 | | /// <param name="name">The name of the key.</param> |
| | 814 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 815 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 816 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 817 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 818 | | public virtual Response<byte[]> BackupKey(string name, CancellationToken cancellationToken = default) |
| | 819 | | { |
| 8 | 820 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 821 | |
|
| 4 | 822 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(BackupKey)}"); |
| 4 | 823 | | scope.AddAttribute("key", name); |
| 4 | 824 | | scope.Start(); |
| | 825 | |
|
| | 826 | | try |
| | 827 | | { |
| 6 | 828 | | Response<KeyBackup> backup = _pipeline.SendRequest(RequestMethod.Post, () => new KeyBackup(), cancellati |
| | 829 | |
|
| 2 | 830 | | return Response.FromValue(backup.Value.Value, backup.GetRawResponse()); |
| | 831 | | } |
| 2 | 832 | | catch (Exception e) |
| | 833 | | { |
| 2 | 834 | | scope.Failed(e); |
| 2 | 835 | | throw; |
| | 836 | | } |
| 2 | 837 | | } |
| | 838 | |
|
| | 839 | | /// <summary> |
| | 840 | | /// Requests that a backup of the specified key be downloaded to the client. |
| | 841 | | /// </summary> |
| | 842 | | /// <remarks> |
| | 843 | | /// The Key Backup operation exports a key from Azure Key Vault in a protected |
| | 844 | | /// form. Note that this operation does NOT return the actual key in a form that |
| | 845 | | /// can be used outside the Azure Key Vault system, the returned key |
| | 846 | | /// is either protected to a Azure Key Vault HSM or to Azure Key Vault itself. |
| | 847 | | /// The intent of this operation is to allow a client to GENERATE a key in one |
| | 848 | | /// Azure Key Vault instance, BACKUP the key, and then RESTORE it into another |
| | 849 | | /// Azure Key Vault instance. The BACKUP operation may be used to export, in |
| | 850 | | /// protected form, any key type from Azure Key Vault. Individual versions of a |
| | 851 | | /// key cannot be backed up. BACKUP / RESTORE can be performed within |
| | 852 | | /// geographical boundaries only; meaning that a BACKUP from one geographical |
| | 853 | | /// area cannot be restored to another geographical area. For example, a backup |
| | 854 | | /// from the US geographical area cannot be restored in an EU geographical |
| | 855 | | /// area. This operation requires the key/backup permission. |
| | 856 | | /// </remarks> |
| | 857 | | /// <param name="name">The name of the key.</param> |
| | 858 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 859 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 860 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 861 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 862 | | public virtual async Task<Response<byte[]>> BackupKeyAsync(string name, CancellationToken cancellationToken = de |
| | 863 | | { |
| 8 | 864 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 865 | |
|
| 4 | 866 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(BackupKey)}"); |
| 4 | 867 | | scope.AddAttribute("key", name); |
| 4 | 868 | | scope.Start(); |
| | 869 | |
|
| | 870 | | try |
| | 871 | | { |
| 6 | 872 | | Response<KeyBackup> backup = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new KeyBackup(), |
| | 873 | |
|
| 2 | 874 | | return Response.FromValue(backup.Value.Value, backup.GetRawResponse()); |
| | 875 | | } |
| 2 | 876 | | catch (Exception e) |
| | 877 | | { |
| 2 | 878 | | scope.Failed(e); |
| 2 | 879 | | throw; |
| | 880 | | } |
| 2 | 881 | | } |
| | 882 | |
|
| | 883 | | /// <summary> |
| | 884 | | /// Restores a backed up key to a vault. |
| | 885 | | /// </summary> |
| | 886 | | /// <remarks> |
| | 887 | | /// Imports a previously backed up key into Azure Key Vault, restoring the key, |
| | 888 | | /// its key identifier, attributes, and access control policies. The RESTORE |
| | 889 | | /// operation may be used to import a previously backed up key. Individual |
| | 890 | | /// versions of a key cannot be restored. The key is restored in its entirety |
| | 891 | | /// with the same key name as it had when it was backed up. If the key name is |
| | 892 | | /// not available in the target Key Vault, the RESTORE operation will be |
| | 893 | | /// rejected. While the key name is retained during restore, the final key |
| | 894 | | /// identifier will change if the key is restored to a different vault. Restore |
| | 895 | | /// will restore all versions and preserve version identifiers. The RESTORE |
| | 896 | | /// operation is subject to security constraints: The target Key Vault must be |
| | 897 | | /// owned by the same Microsoft Azure Subscription as the source Key Vault The |
| | 898 | | /// user must have RESTORE permission in the target Key Vault. This operation |
| | 899 | | /// requires the keys/restore permission. |
| | 900 | | /// </remarks> |
| | 901 | | /// <param name="backup">The backup blob associated with a key.</param> |
| | 902 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 903 | | /// <exception cref="ArgumentException"><paramref name="backup"/> is an empty string.</exception> |
| | 904 | | /// <exception cref="ArgumentNullException"><paramref name="backup"/> is null.</exception> |
| | 905 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 906 | | public virtual Response<KeyVaultKey> RestoreKeyBackup(byte[] backup, CancellationToken cancellationToken = defau |
| | 907 | | { |
| 4 | 908 | | Argument.AssertNotNull(backup, nameof(backup)); |
| | 909 | |
|
| 2 | 910 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(RestoreKeyBackup)}"); |
| 2 | 911 | | scope.Start(); |
| | 912 | |
|
| | 913 | | try |
| | 914 | | { |
| 0 | 915 | | return _pipeline.SendRequest(RequestMethod.Post, new KeyBackup { Value = backup }, () => new KeyVaultKey |
| | 916 | | } |
| 2 | 917 | | catch (Exception e) |
| | 918 | | { |
| 2 | 919 | | scope.Failed(e); |
| 2 | 920 | | throw; |
| | 921 | | } |
| 0 | 922 | | } |
| | 923 | |
|
| | 924 | | /// <summary> |
| | 925 | | /// Restores a backed up key to a vault. |
| | 926 | | /// </summary> |
| | 927 | | /// <remarks> |
| | 928 | | /// Imports a previously backed up key into Azure Key Vault, restoring the key, |
| | 929 | | /// its key identifier, attributes, and access control policies. The RESTORE |
| | 930 | | /// operation may be used to import a previously backed up key. Individual |
| | 931 | | /// versions of a key cannot be restored. The key is restored in its entirety |
| | 932 | | /// with the same key name as it had when it was backed up. If the key name is |
| | 933 | | /// not available in the target Key Vault, the RESTORE operation will be |
| | 934 | | /// rejected. While the key name is retained during restore, the final key |
| | 935 | | /// identifier will change if the key is restored to a different vault. Restore |
| | 936 | | /// will restore all versions and preserve version identifiers. The RESTORE |
| | 937 | | /// operation is subject to security constraints: The target Key Vault must be |
| | 938 | | /// owned by the same Microsoft Azure Subscription as the source Key Vault The |
| | 939 | | /// user must have RESTORE permission in the target Key Vault. This operation |
| | 940 | | /// requires the keys/restore permission. |
| | 941 | | /// </remarks> |
| | 942 | | /// <param name="backup">The backup blob associated with a key.</param> |
| | 943 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 944 | | /// <exception cref="ArgumentException"><paramref name="backup"/> is an empty string.</exception> |
| | 945 | | /// <exception cref="ArgumentNullException"><paramref name="backup"/> is null.</exception> |
| | 946 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 947 | | public virtual async Task<Response<KeyVaultKey>> RestoreKeyBackupAsync(byte[] backup, CancellationToken cancella |
| | 948 | | { |
| 4 | 949 | | Argument.AssertNotNull(backup, nameof(backup)); |
| | 950 | |
|
| 2 | 951 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(RestoreKeyBackup)}"); |
| 2 | 952 | | scope.Start(); |
| | 953 | |
|
| | 954 | | try |
| | 955 | | { |
| 0 | 956 | | return await _pipeline.SendRequestAsync(RequestMethod.Post, new KeyBackup { Value = backup }, () => new |
| | 957 | | } |
| 2 | 958 | | catch (Exception e) |
| | 959 | | { |
| 2 | 960 | | scope.Failed(e); |
| 2 | 961 | | throw; |
| | 962 | | } |
| 0 | 963 | | } |
| | 964 | |
|
| | 965 | | /// <summary> |
| | 966 | | /// Imports an externally created key, stores it, and returns key parameters |
| | 967 | | /// and attributes to the client. |
| | 968 | | /// </summary> |
| | 969 | | /// <remarks> |
| | 970 | | /// The import key operation may be used to import any key type into an Azure |
| | 971 | | /// Key Vault. If the named key already exists, Azure Key Vault creates a new |
| | 972 | | /// version of the key. This operation requires the keys/import permission. |
| | 973 | | /// </remarks> |
| | 974 | | /// <param name="name">The name of the key.</param> |
| | 975 | | /// <param name="keyMaterial">The <see cref="JsonWebKey"/> being imported.</param> |
| | 976 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 977 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 978 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="keyMaterial"/> is null.</ |
| | 979 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 980 | | public virtual Response<KeyVaultKey> ImportKey(string name, JsonWebKey keyMaterial, CancellationToken cancellati |
| | 981 | | { |
| 24 | 982 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| 18 | 983 | | Argument.AssertNotNull(keyMaterial, nameof(keyMaterial)); |
| | 984 | |
|
| 18 | 985 | | var importKeyOptions = new ImportKeyOptions(name, keyMaterial); |
| | 986 | |
|
| 18 | 987 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(ImportKey)}"); |
| 18 | 988 | | scope.AddAttribute("key", name); |
| 18 | 989 | | scope.Start(); |
| | 990 | |
|
| | 991 | | try |
| | 992 | | { |
| 36 | 993 | | return _pipeline.SendRequest(RequestMethod.Put, importKeyOptions, () => new KeyVaultKey(name), cancellat |
| | 994 | | } |
| 0 | 995 | | catch (Exception e) |
| | 996 | | { |
| 0 | 997 | | scope.Failed(e); |
| 0 | 998 | | throw; |
| | 999 | | } |
| 18 | 1000 | | } |
| | 1001 | |
|
| | 1002 | | /// <summary> |
| | 1003 | | /// Imports an externally created key, stores it, and returns key parameters |
| | 1004 | | /// and attributes to the client. |
| | 1005 | | /// </summary> |
| | 1006 | | /// <remarks> |
| | 1007 | | /// The import key operation may be used to import any key type into an Azure |
| | 1008 | | /// Key Vault. If the named key already exists, Azure Key Vault creates a new |
| | 1009 | | /// version of the key. This operation requires the keys/import permission. |
| | 1010 | | /// </remarks> |
| | 1011 | | /// <param name="name">The name of the key.</param> |
| | 1012 | | /// <param name="keyMaterial">The <see cref="JsonWebKey"/> being imported.</param> |
| | 1013 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 1014 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 1015 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="keyMaterial"/> is null.</ |
| | 1016 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 1017 | | public virtual async Task<Response<KeyVaultKey>> ImportKeyAsync(string name, JsonWebKey keyMaterial, Cancellatio |
| | 1018 | | { |
| 24 | 1019 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| 18 | 1020 | | Argument.AssertNotNull(keyMaterial, nameof(keyMaterial)); |
| | 1021 | |
|
| 18 | 1022 | | var importKeyOptions = new ImportKeyOptions(name, keyMaterial); |
| | 1023 | |
|
| 18 | 1024 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(ImportKey)}"); |
| 18 | 1025 | | scope.AddAttribute("key", name); |
| 18 | 1026 | | scope.Start(); |
| | 1027 | |
|
| | 1028 | | try |
| | 1029 | | { |
| 36 | 1030 | | return await _pipeline.SendRequestAsync(RequestMethod.Put, importKeyOptions, () => new KeyVaultKey(name) |
| | 1031 | | } |
| 0 | 1032 | | catch (Exception e) |
| | 1033 | | { |
| 0 | 1034 | | scope.Failed(e); |
| 0 | 1035 | | throw; |
| | 1036 | | } |
| 18 | 1037 | | } |
| | 1038 | |
|
| | 1039 | | /// <summary> |
| | 1040 | | /// Imports an externally created key, stores it, and returns key parameters |
| | 1041 | | /// and attributes to the client. |
| | 1042 | | /// </summary> |
| | 1043 | | /// <remarks> |
| | 1044 | | /// The import key operation may be used to import any key type into an Azure |
| | 1045 | | /// Key Vault. If the named key already exists, Azure Key Vault creates a new |
| | 1046 | | /// version of the key. This operation requires the keys/import permission. |
| | 1047 | | /// </remarks> |
| | 1048 | | /// <param name="importKeyOptions">The key import configuration object containing information about the <see cre |
| | 1049 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 1050 | | /// <exception cref="ArgumentNullException"><paramref name="importKeyOptions"/> is null.</exception> |
| | 1051 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 1052 | | public virtual Response<KeyVaultKey> ImportKey(ImportKeyOptions importKeyOptions, CancellationToken cancellation |
| | 1053 | | { |
| 2 | 1054 | | Argument.AssertNotNull(importKeyOptions, nameof(importKeyOptions)); |
| | 1055 | |
|
| 0 | 1056 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(ImportKey)}"); |
| 0 | 1057 | | scope.AddAttribute("key", importKeyOptions.Name); |
| 0 | 1058 | | scope.Start(); |
| | 1059 | |
|
| | 1060 | | try |
| | 1061 | | { |
| | 1062 | |
|
| 0 | 1063 | | return _pipeline.SendRequest(RequestMethod.Put, importKeyOptions, () => new KeyVaultKey(importKeyOptions |
| | 1064 | | } |
| 0 | 1065 | | catch (Exception e) |
| | 1066 | | { |
| 0 | 1067 | | scope.Failed(e); |
| 0 | 1068 | | throw; |
| | 1069 | | } |
| 0 | 1070 | | } |
| | 1071 | |
|
| | 1072 | | /// <summary> |
| | 1073 | | /// Imports an externally created key, stores it, and returns key parameters |
| | 1074 | | /// and attributes to the client. |
| | 1075 | | /// </summary> |
| | 1076 | | /// <remarks> |
| | 1077 | | /// The import key operation may be used to import any key type into an Azure |
| | 1078 | | /// Key Vault. If the named key already exists, Azure Key Vault creates a new |
| | 1079 | | /// version of the key. This operation requires the keys/import permission. |
| | 1080 | | /// </remarks> |
| | 1081 | | /// <param name="importKeyOptions">The key import configuration object containing information about the <see cre |
| | 1082 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 1083 | | /// <exception cref="ArgumentNullException"><paramref name="importKeyOptions"/> is null.</exception> |
| | 1084 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 1085 | | public virtual async Task<Response<KeyVaultKey>> ImportKeyAsync(ImportKeyOptions importKeyOptions, CancellationT |
| | 1086 | | { |
| 2 | 1087 | | Argument.AssertNotNull(importKeyOptions, nameof(importKeyOptions)); |
| | 1088 | |
|
| 0 | 1089 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(KeyClient)}.{nameof(ImportKey)}"); |
| 0 | 1090 | | scope.AddAttribute("key", importKeyOptions.Name); |
| 0 | 1091 | | scope.Start(); |
| | 1092 | |
|
| | 1093 | | try |
| | 1094 | | { |
| 0 | 1095 | | return await _pipeline.SendRequestAsync(RequestMethod.Put, importKeyOptions, () => new KeyVaultKey(impor |
| | 1096 | | } |
| 0 | 1097 | | catch (Exception e) |
| | 1098 | | { |
| 0 | 1099 | | scope.Failed(e); |
| 0 | 1100 | | throw; |
| | 1101 | | } |
| 0 | 1102 | | } |
| | 1103 | | } |
| | 1104 | | } |