| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Threading; |
| | 6 | | using System.Threading.Tasks; |
| | 7 | | using Azure.Core; |
| | 8 | | using Azure.Core.Pipeline; |
| | 9 | |
|
| | 10 | | namespace Azure.Security.KeyVault.Secrets |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// The SecretClient provides synchronous and asynchronous methods to manage <see cref="KeyVaultSecret"/> in the Azu |
| | 14 | | /// supports creating, retrieving, updating, deleting, purging, backing up, restoring, and listing <see cref="KeyVau |
| | 15 | | /// The client also supports listing <see cref="DeletedSecret"/> for a soft-delete enabled Azure Key Vault. |
| | 16 | | /// </summary> |
| | 17 | | public class SecretClient |
| | 18 | | { |
| | 19 | | internal const string SecretsPath = "/secrets/"; |
| | 20 | | internal const string DeletedSecretsPath = "/deletedsecrets/"; |
| | 21 | |
|
| | 22 | | private readonly KeyVaultPipeline _pipeline; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Initializes a new instance of the <see cref="SecretClient"/> class for mocking. |
| | 26 | | /// </summary> |
| 168 | 27 | | protected SecretClient() |
| | 28 | | { |
| | 29 | |
|
| 168 | 30 | | } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Initializes a new instance of the <see cref="SecretClient"/> class for the specified vault. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="vaultUri">A <see cref="Uri"/> to the vault on which the client operates. Appears as "DNS Name" |
| | 36 | | /// <param name="credential">A <see cref="TokenCredential"/> used to authenticate requests to the vault, such as |
| | 37 | | /// <exception cref="ArgumentNullException"><paramref name="vaultUri"/> or <paramref name="credential"/> is null |
| | 38 | | public SecretClient(Uri vaultUri, TokenCredential credential) |
| 0 | 39 | | : this(vaultUri, credential, null) |
| | 40 | | { |
| | 41 | |
|
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Initializes a new instance of the <see cref="SecretClient"/> class for the specified vault. |
| | 46 | | /// </summary> |
| | 47 | | /// <param name="vaultUri">A <see cref="Uri"/> to the vault on which the client operates. Appears as "DNS Name" |
| | 48 | | /// <param name="credential">A <see cref="TokenCredential"/> used to authenticate requests to the vault, such as |
| | 49 | | /// <param name="options"><see cref="SecretClientOptions"/> that allow to configure the management of the reques |
| | 50 | | /// <exception cref="ArgumentNullException"><paramref name="vaultUri"/> or <paramref name="credential"/> is null |
| 178 | 51 | | public SecretClient(Uri vaultUri, TokenCredential credential, SecretClientOptions options) |
| | 52 | | { |
| 178 | 53 | | Argument.AssertNotNull(vaultUri, nameof(vaultUri)); |
| 178 | 54 | | Argument.AssertNotNull(credential, nameof(credential)); |
| | 55 | |
|
| 178 | 56 | | options ??= new SecretClientOptions(); |
| 178 | 57 | | string apiVersion = options.GetVersionString(); |
| | 58 | |
|
| 178 | 59 | | HttpPipeline pipeline = HttpPipelineBuilder.Build(options, |
| 178 | 60 | | new ChallengeBasedAuthenticationPolicy(credential)); |
| | 61 | |
|
| 178 | 62 | | _pipeline = new KeyVaultPipeline(vaultUri, apiVersion, pipeline, new ClientDiagnostics(options)); |
| 178 | 63 | | } |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Gets the <see cref="Uri"/> of the vault used to create this instance of the <see cref="SecretClient"/>. |
| | 67 | | /// </summary> |
| 16 | 68 | | public virtual Uri VaultUri => _pipeline.VaultUri; |
| | 69 | |
|
| | 70 | | /// <summary> |
| | 71 | | /// Get a specified secret from a given key vault. |
| | 72 | | /// </summary> |
| | 73 | | /// <remarks> |
| | 74 | | /// The get operation is applicable to any secret stored in Azure Key Vault. |
| | 75 | | /// This operation requires the secrets/get permission. |
| | 76 | | /// </remarks> |
| | 77 | | /// <param name="name">The name of the secret.</param> |
| | 78 | | /// <param name="version">The version of the secret.</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.</exception> |
| | 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 async Task<Response<KeyVaultSecret>> GetSecretAsync(string name, string version = null, Cancellat |
| | 84 | | { |
| 86 | 85 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 86 | |
|
| 82 | 87 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(GetSecret)}"); |
| 82 | 88 | | scope.AddAttribute("secret", name); |
| 82 | 89 | | scope.Start(); |
| | 90 | |
|
| | 91 | | try |
| | 92 | | { |
| 156 | 93 | | return await _pipeline.SendRequestAsync(RequestMethod.Get, () => new KeyVaultSecret(), cancellationToken |
| | 94 | | } |
| 8 | 95 | | catch (Exception e) |
| | 96 | | { |
| 8 | 97 | | scope.Failed(e); |
| 8 | 98 | | throw; |
| | 99 | | } |
| 74 | 100 | | } |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// Get a specified secret from a given key vault. |
| | 104 | | /// </summary> |
| | 105 | | /// <remarks> |
| | 106 | | /// The get operation is applicable to any secret stored in Azure Key Vault. |
| | 107 | | /// This operation requires the secrets/get permission. |
| | 108 | | /// </remarks> |
| | 109 | | /// <param name="name">The name of the secret.</param> |
| | 110 | | /// <param name="version">The version of the secret.</param> |
| | 111 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 112 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 113 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 114 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 115 | | public virtual Response<KeyVaultSecret> GetSecret(string name, string version = null, CancellationToken cancella |
| | 116 | | { |
| 20 | 117 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 118 | |
|
| 16 | 119 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(GetSecret)}"); |
| 16 | 120 | | scope.AddAttribute("secret", name); |
| 16 | 121 | | scope.Start(); |
| | 122 | |
|
| | 123 | | try |
| | 124 | | { |
| 26 | 125 | | return _pipeline.SendRequest(RequestMethod.Get, () => new KeyVaultSecret(), cancellationToken, SecretsPa |
| | 126 | | } |
| 6 | 127 | | catch (Exception e) |
| | 128 | | { |
| 6 | 129 | | scope.Failed(e); |
| 6 | 130 | | throw; |
| | 131 | | } |
| 10 | 132 | | } |
| | 133 | |
|
| | 134 | | /// <summary> |
| | 135 | | /// Lists the properties of all versions of the specified secret. You can use the returned <see cref="SecretProp |
| | 136 | | /// </summary> |
| | 137 | | /// <remarks> |
| | 138 | | /// The full secret identifier and attributes are provided in the response. No |
| | 139 | | /// values are returned for the secrets. This operations requires the |
| | 140 | | /// secrets/list permission. |
| | 141 | | /// </remarks> |
| | 142 | | /// <param name="name">The name of the secret.</param> |
| | 143 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 144 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 145 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 146 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 147 | | public virtual AsyncPageable<SecretProperties> GetPropertiesOfSecretVersionsAsync(string name, CancellationToken |
| | 148 | | { |
| 8 | 149 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 150 | |
|
| 4 | 151 | | Uri firstPageUri = new Uri(VaultUri, $"{SecretsPath}{name}/versions?api-version={_pipeline.ApiVersion}"); |
| | 152 | |
|
| 110 | 153 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 154 | | } |
| | 155 | |
|
| | 156 | | /// <summary> |
| | 157 | | /// Lists the properties of all versions of the specified secret. You can use the returned <see cref="SecretProp |
| | 158 | | /// </summary> |
| | 159 | | /// <remarks> |
| | 160 | | /// The full secret identifier and attributes are provided in the response. No |
| | 161 | | /// values are returned for the secrets. This operations requires the |
| | 162 | | /// secrets/list permission. |
| | 163 | | /// </remarks> |
| | 164 | | /// <param name="name">The name of the secret.</param> |
| | 165 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 166 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 167 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 168 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 169 | | public virtual Pageable<SecretProperties> GetPropertiesOfSecretVersions(string name, CancellationToken cancellat |
| | 170 | | { |
| 8 | 171 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 172 | |
|
| 4 | 173 | | Uri firstPageUri = new Uri(VaultUri, $"{SecretsPath}{name}/versions?api-version={_pipeline.ApiVersion}"); |
| | 174 | |
|
| 110 | 175 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 176 | | } |
| | 177 | |
|
| | 178 | | /// <summary> |
| | 179 | | /// Lists the properties of all secrets in the specified vault. You can use the returned <see cref="SecretProper |
| | 180 | | /// </summary> |
| | 181 | | /// <remarks> |
| | 182 | | /// The Get Secrets operation is applicable to the entire vault. However, only |
| | 183 | | /// the base secret identifier and its attributes are provided in the response. |
| | 184 | | /// Individual secret versions are not listed in the response. This operation |
| | 185 | | /// requires the secrets/list permission. |
| | 186 | | /// </remarks> |
| | 187 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 188 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 189 | | public virtual AsyncPageable<SecretProperties> GetPropertiesOfSecretsAsync(CancellationToken cancellationToken = |
| | 190 | | { |
| 2 | 191 | | Uri firstPageUri = new Uri(VaultUri, SecretsPath + $"?api-version={_pipeline.ApiVersion}"); |
| | 192 | |
|
| 108 | 193 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 194 | | } |
| | 195 | |
|
| | 196 | | /// <summary> |
| | 197 | | /// Lists the properties of all secrets in the specified vault. You can use the returned <see cref="SecretProper |
| | 198 | | /// </summary> |
| | 199 | | /// <remarks> |
| | 200 | | /// The Get Secrets operation is applicable to the entire vault. However, only |
| | 201 | | /// the base secret identifier and its attributes are provided in the response. |
| | 202 | | /// Individual secret versions are not listed in the response. This operation |
| | 203 | | /// requires the secrets/list permission. |
| | 204 | | /// </remarks> |
| | 205 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 206 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 207 | | public virtual Pageable<SecretProperties> GetPropertiesOfSecrets(CancellationToken cancellationToken = default) |
| | 208 | | { |
| 2 | 209 | | Uri firstPageUri = new Uri(VaultUri, SecretsPath + $"?api-version={_pipeline.ApiVersion}"); |
| | 210 | |
|
| 108 | 211 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 212 | | } |
| | 213 | |
|
| | 214 | | /// <summary> |
| | 215 | | /// Updates the attributes associated with a specified secret. |
| | 216 | | /// </summary> |
| | 217 | | /// <remarks> |
| | 218 | | /// The update operation changes specified attributes of an existing stored |
| | 219 | | /// secret. Attributes that are not specified in the request are left |
| | 220 | | /// unchanged. The value of a secret itself cannot be changed. This operation |
| | 221 | | /// requires the secrets/set permission. |
| | 222 | | /// </remarks> |
| | 223 | | /// <param name="properties">The secret object with updated properties.</param> |
| | 224 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 225 | | /// <exception cref="ArgumentNullException"><paramref name="properties"/> or <see cref="SecretProperties.Version |
| | 226 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 227 | | public virtual async Task<Response<SecretProperties>> UpdateSecretPropertiesAsync(SecretProperties properties, C |
| | 228 | | { |
| 14 | 229 | | Argument.AssertNotNull(properties, nameof(properties)); |
| 12 | 230 | | Argument.AssertNotNull(properties.Version, nameof(properties.Version)); |
| | 231 | |
|
| 10 | 232 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(UpdateSecretProperties) |
| 10 | 233 | | scope.AddAttribute("secret", properties.Name); |
| 10 | 234 | | scope.Start(); |
| | 235 | |
|
| | 236 | | try |
| | 237 | | { |
| 20 | 238 | | return await _pipeline.SendRequestAsync(RequestMethod.Patch, properties, () => new SecretProperties(), c |
| | 239 | | } |
| 0 | 240 | | catch (Exception e) |
| | 241 | | { |
| 0 | 242 | | scope.Failed(e); |
| 0 | 243 | | throw; |
| | 244 | | } |
| 10 | 245 | | } |
| | 246 | |
|
| | 247 | | /// <summary> |
| | 248 | | /// Updates the attributes associated with a specified secret. |
| | 249 | | /// </summary> |
| | 250 | | /// <remarks> |
| | 251 | | /// The update operation changes specified attributes of an existing stored |
| | 252 | | /// secret. Attributes that are not specified in the request are left |
| | 253 | | /// unchanged. The value of a secret itself cannot be changed. This operation |
| | 254 | | /// requires the secrets/set permission. |
| | 255 | | /// </remarks> |
| | 256 | | /// <param name="properties">The secret object with updated properties.</param> |
| | 257 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 258 | | /// <exception cref="ArgumentNullException"><paramref name="properties"/> or <see cref="SecretProperties.Version |
| | 259 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 260 | | public virtual Response<SecretProperties> UpdateSecretProperties(SecretProperties properties, CancellationToken |
| | 261 | | { |
| 14 | 262 | | Argument.AssertNotNull(properties, nameof(properties)); |
| 12 | 263 | | Argument.AssertNotNull(properties.Version, nameof(properties.Version)); |
| | 264 | |
|
| 10 | 265 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(UpdateSecretProperties) |
| 10 | 266 | | scope.AddAttribute("secret", properties.Name); |
| 10 | 267 | | scope.Start(); |
| | 268 | |
|
| | 269 | | try |
| | 270 | | { |
| 20 | 271 | | return _pipeline.SendRequest(RequestMethod.Patch, properties, () => new SecretProperties(), cancellation |
| | 272 | | } |
| 0 | 273 | | catch (Exception e) |
| | 274 | | { |
| 0 | 275 | | scope.Failed(e); |
| 0 | 276 | | throw; |
| | 277 | | } |
| 10 | 278 | | } |
| | 279 | |
|
| | 280 | | /// <summary> |
| | 281 | | /// Sets a secret in a specified key vault. |
| | 282 | | /// </summary> |
| | 283 | | /// <remarks> |
| | 284 | | /// The set operation adds a secret to the Azure Key Vault. If the named secret |
| | 285 | | /// already exists, Azure Key Vault creates a new version of that secret. This |
| | 286 | | /// operation requires the secrets/set permission. |
| | 287 | | /// </remarks> |
| | 288 | | /// <param name="secret">The Secret object containing information about the secret and its properties. The prope |
| | 289 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 290 | | /// <exception cref="ArgumentNullException"><paramref name="secret"/> is null.</exception> |
| | 291 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 292 | | public virtual async Task<Response<KeyVaultSecret>> SetSecretAsync(KeyVaultSecret secret, CancellationToken canc |
| | 293 | | { |
| 334 | 294 | | Argument.AssertNotNull(secret, nameof(secret)); |
| | 295 | |
|
| 332 | 296 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(SetSecret)}"); |
| 332 | 297 | | scope.AddAttribute("secret", secret.Name); |
| 332 | 298 | | scope.Start(); |
| | 299 | |
|
| | 300 | | try |
| | 301 | | { |
| 664 | 302 | | return await _pipeline.SendRequestAsync(RequestMethod.Put, secret, () => new KeyVaultSecret(), cancellat |
| | 303 | | } |
| 0 | 304 | | catch (Exception e) |
| | 305 | | { |
| 0 | 306 | | scope.Failed(e); |
| 0 | 307 | | throw; |
| | 308 | | } |
| 332 | 309 | | } |
| | 310 | |
|
| | 311 | | /// <summary> |
| | 312 | | /// Sets a secret in a specified key vault. |
| | 313 | | /// </summary> |
| | 314 | | /// <remarks> |
| | 315 | | /// The set operation adds a secret to the Azure Key Vault. If the named secret |
| | 316 | | /// already exists, Azure Key Vault creates a new version of that secret. This |
| | 317 | | /// operation requires the secrets/set permission. |
| | 318 | | /// </remarks> |
| | 319 | | /// <param name="secret">The Secret object containing information about the secret and its properties. The prope |
| | 320 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 321 | | /// <exception cref="ArgumentNullException"><paramref name="secret"/> is null.</exception> |
| | 322 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 323 | | public virtual Response<KeyVaultSecret> SetSecret(KeyVaultSecret secret, CancellationToken cancellationToken = d |
| | 324 | | { |
| 334 | 325 | | Argument.AssertNotNull(secret, nameof(secret)); |
| | 326 | |
|
| 332 | 327 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(SetSecret)}"); |
| 332 | 328 | | scope.AddAttribute("secret", secret.Name); |
| 332 | 329 | | scope.Start(); |
| | 330 | |
|
| | 331 | | try |
| | 332 | | { |
| 664 | 333 | | return _pipeline.SendRequest(RequestMethod.Put, secret, () => new KeyVaultSecret(), cancellationToken, S |
| | 334 | | } |
| 0 | 335 | | catch (Exception e) |
| | 336 | | { |
| 0 | 337 | | scope.Failed(e); |
| 0 | 338 | | throw; |
| | 339 | | } |
| 332 | 340 | | } |
| | 341 | |
|
| | 342 | | /// <summary> |
| | 343 | | /// Sets a secret in a specified key vault. |
| | 344 | | /// </summary> |
| | 345 | | /// <remarks> |
| | 346 | | /// The set operation adds a secret to the Azure Key Vault. If the named secret |
| | 347 | | /// already exists, Azure Key Vault creates a new version of that secret. This |
| | 348 | | /// operation requires the secrets/set permission. |
| | 349 | | /// </remarks> |
| | 350 | | /// <param name="name">The name of the secret. It must not be null.</param> |
| | 351 | | /// <param name="value">The value of the secret. It must not be null.</param> |
| | 352 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 353 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 354 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 355 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 356 | | public virtual async Task<Response<KeyVaultSecret>> SetSecretAsync(string name, string value, CancellationToken |
| | 357 | | { |
| 332 | 358 | | return await SetSecretAsync(new KeyVaultSecret(name, value), cancellationToken).ConfigureAwait(false); |
| 326 | 359 | | } |
| | 360 | |
|
| | 361 | | /// <summary> |
| | 362 | | /// Sets a secret in a specified key vault. |
| | 363 | | /// </summary> |
| | 364 | | /// <remarks> |
| | 365 | | /// The set operation adds a secret to the Azure Key Vault. If the named secret |
| | 366 | | /// already exists, Azure Key Vault creates a new version of that secret. This |
| | 367 | | /// operation requires the secrets/set permission. |
| | 368 | | /// </remarks> |
| | 369 | | /// <param name="name">The name of the secret.</param> |
| | 370 | | /// <param name="value">The value of the secret.</param> |
| | 371 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 372 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 373 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 374 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 375 | | public virtual Response<KeyVaultSecret> SetSecret(string name, string value, CancellationToken cancellationToken |
| | 376 | | { |
| 332 | 377 | | return SetSecret(new KeyVaultSecret(name, value), cancellationToken); |
| | 378 | | } |
| | 379 | |
|
| | 380 | | /// <summary> |
| | 381 | | /// Deletes a secret from a specified key vault. |
| | 382 | | /// </summary> |
| | 383 | | /// <remarks> |
| | 384 | | /// The delete operation applies to any secret stored in Azure Key Vault. |
| | 385 | | /// Delete cannot be applied to an individual version of a secret. This |
| | 386 | | /// operation requires the secrets/delete permission. |
| | 387 | | /// </remarks> |
| | 388 | | /// <param name="name">The name of the secret.</param> |
| | 389 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 390 | | /// <returns> |
| | 391 | | /// A <see cref="DeleteSecretOperation"/> to wait on this long-running operation. |
| | 392 | | /// If the Key Vault is soft delete-enabled, you only need to wait for the operation to complete if you need to |
| | 393 | | /// otherwise, the secret is deleted automatically on the <see cref="DeletedSecret.ScheduledPurgeDate"/>. |
| | 394 | | /// </returns> |
| | 395 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 396 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 397 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 398 | | public virtual async Task<DeleteSecretOperation> StartDeleteSecretAsync(string name, CancellationToken cancellat |
| | 399 | | { |
| 114 | 400 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 401 | |
|
| 110 | 402 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(StartDeleteSecret)}"); |
| 110 | 403 | | scope.AddAttribute("secret", name); |
| 110 | 404 | | scope.Start(); |
| | 405 | |
|
| | 406 | | try |
| | 407 | | { |
| 218 | 408 | | Response<DeletedSecret> response = await _pipeline.SendRequestAsync(RequestMethod.Delete, () => new Dele |
| 108 | 409 | | return new DeleteSecretOperation(_pipeline, response); |
| | 410 | | } |
| 2 | 411 | | catch (Exception e) |
| | 412 | | { |
| 2 | 413 | | scope.Failed(e); |
| 2 | 414 | | throw; |
| | 415 | | } |
| 108 | 416 | | } |
| | 417 | |
|
| | 418 | | /// <summary> |
| | 419 | | /// Deletes a secret from a specified key vault. |
| | 420 | | /// </summary> |
| | 421 | | /// <remarks> |
| | 422 | | /// The delete operation applies to any secret stored in Azure Key Vault. |
| | 423 | | /// Delete cannot be applied to an individual version of a secret. This |
| | 424 | | /// operation requires the secrets/delete permission. |
| | 425 | | /// </remarks> |
| | 426 | | /// <param name="name">The name of the secret.</param> |
| | 427 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 428 | | /// <returns> |
| | 429 | | /// A <see cref="DeleteSecretOperation"/> to wait on this long-running operation. |
| | 430 | | /// If the Key Vault is soft delete-enabled, you only need to wait for the operation to complete if you need to |
| | 431 | | /// otherwise, the secret is deleted automatically on the <see cref="DeletedSecret.ScheduledPurgeDate"/>. |
| | 432 | | /// </returns> |
| | 433 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 434 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 435 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 436 | | public virtual DeleteSecretOperation StartDeleteSecret(string name, CancellationToken cancellationToken = defaul |
| | 437 | | { |
| 114 | 438 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 439 | |
|
| 110 | 440 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(StartDeleteSecret)}"); |
| 110 | 441 | | scope.AddAttribute("secret", name); |
| 110 | 442 | | scope.Start(); |
| | 443 | |
|
| | 444 | | try |
| | 445 | | { |
| 218 | 446 | | Response<DeletedSecret> response = _pipeline.SendRequest(RequestMethod.Delete, () => new DeletedSecret() |
| 108 | 447 | | return new DeleteSecretOperation(_pipeline, response); |
| | 448 | | } |
| 2 | 449 | | catch (Exception e) |
| | 450 | | { |
| 2 | 451 | | scope.Failed(e); |
| 2 | 452 | | throw; |
| | 453 | | } |
| 108 | 454 | | } |
| | 455 | |
|
| | 456 | | /// <summary> |
| | 457 | | /// Gets the specified deleted secret. |
| | 458 | | /// </summary> |
| | 459 | | /// <remarks> |
| | 460 | | /// The Get Deleted Secret operation returns the specified deleted secret along |
| | 461 | | /// with its attributes. This operation requires the secrets/get permission. |
| | 462 | | /// </remarks> |
| | 463 | | /// <param name="name">The name of the secret.</param> |
| | 464 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 465 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 466 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 467 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 468 | | public virtual async Task<Response<DeletedSecret>> GetDeletedSecretAsync(string name, CancellationToken cancella |
| | 469 | | { |
| 8 | 470 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 471 | |
|
| 4 | 472 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(GetDeletedSecret)}"); |
| 4 | 473 | | scope.AddAttribute("secret", name); |
| 4 | 474 | | scope.Start(); |
| | 475 | |
|
| | 476 | | try |
| | 477 | | { |
| 6 | 478 | | return await _pipeline.SendRequestAsync(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, |
| | 479 | | } |
| 2 | 480 | | catch (Exception e) |
| | 481 | | { |
| 2 | 482 | | scope.Failed(e); |
| 2 | 483 | | throw; |
| | 484 | | } |
| 2 | 485 | | } |
| | 486 | |
|
| | 487 | | /// <summary> |
| | 488 | | /// Gets the specified deleted secret. |
| | 489 | | /// </summary> |
| | 490 | | /// <remarks> |
| | 491 | | /// The Get Deleted Secret operation returns the specified deleted secret along |
| | 492 | | /// with its attributes. This operation requires the secrets/get permission. |
| | 493 | | /// </remarks> |
| | 494 | | /// <param name="name">The name of the secret.</param> |
| | 495 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 496 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 497 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 498 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 499 | | public virtual Response<DeletedSecret> GetDeletedSecret(string name, CancellationToken cancellationToken = defau |
| | 500 | | { |
| 8 | 501 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 502 | |
|
| 4 | 503 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(GetDeletedSecret)}"); |
| 4 | 504 | | scope.AddAttribute("secret", name); |
| 4 | 505 | | scope.Start(); |
| | 506 | |
|
| | 507 | | try |
| | 508 | | { |
| 6 | 509 | | return _pipeline.SendRequest(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, DeletedSec |
| | 510 | | } |
| 2 | 511 | | catch (Exception e) |
| | 512 | | { |
| 2 | 513 | | scope.Failed(e); |
| 2 | 514 | | throw; |
| | 515 | | } |
| 2 | 516 | | } |
| | 517 | |
|
| | 518 | | /// <summary> |
| | 519 | | /// Lists deleted secrets for the specified vault. |
| | 520 | | /// </summary> |
| | 521 | | /// <remarks> |
| | 522 | | /// The Get Deleted Secrets operation returns the secrets that have been |
| | 523 | | /// deleted for a vault enabled for soft-delete. This operation requires the |
| | 524 | | /// secrets/list permission. |
| | 525 | | /// </remarks> |
| | 526 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 527 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 528 | | public virtual AsyncPageable<DeletedSecret> GetDeletedSecretsAsync(CancellationToken cancellationToken = default |
| | 529 | | { |
| 2 | 530 | | Uri firstPageUri = new Uri(VaultUri, DeletedSecretsPath + $"?api-version={_pipeline.ApiVersion}"); |
| | 531 | |
|
| 120 | 532 | | return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => _pipeline.GetPageAsync(firstPageUri, nextLin |
| | 533 | | } |
| | 534 | |
|
| | 535 | | /// <summary> |
| | 536 | | /// Lists deleted secrets for the specified vault. |
| | 537 | | /// </summary> |
| | 538 | | /// <remarks> |
| | 539 | | /// The Get Deleted Secrets operation returns the secrets that have been |
| | 540 | | /// deleted for a vault enabled for soft-delete. This operation requires the |
| | 541 | | /// secrets/list permission. |
| | 542 | | /// </remarks> |
| | 543 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 544 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 545 | | public virtual Pageable<DeletedSecret> GetDeletedSecrets(CancellationToken cancellationToken = default) |
| | 546 | | { |
| 2 | 547 | | Uri firstPageUri = new Uri(VaultUri, DeletedSecretsPath + $"?api-version={_pipeline.ApiVersion}"); |
| | 548 | |
|
| 120 | 549 | | return PageResponseEnumerator.CreateEnumerable(nextLink => _pipeline.GetPage(firstPageUri, nextLink, () => n |
| | 550 | | } |
| | 551 | |
|
| | 552 | | /// <summary> |
| | 553 | | /// Recovers the deleted secret to the latest version. |
| | 554 | | /// </summary> |
| | 555 | | /// <remarks> |
| | 556 | | /// Recovers the deleted secret in the specified vault. This operation can only |
| | 557 | | /// be performed on a soft-delete enabled vault. This operation requires the |
| | 558 | | /// secrets/recover permission. |
| | 559 | | /// </remarks> |
| | 560 | | /// <param name="name">The name of the secret.</param> |
| | 561 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 562 | | /// <returns>A <see cref="RecoverDeletedSecretOperation"/> to wait on this long-running operation.</returns> |
| | 563 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 564 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 565 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 566 | | public virtual async Task<RecoverDeletedSecretOperation> StartRecoverDeletedSecretAsync(string name, Cancellatio |
| | 567 | | { |
| 8 | 568 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 569 | |
|
| 4 | 570 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(StartRecoverDeletedSecr |
| 4 | 571 | | scope.AddAttribute("secret", name); |
| 4 | 572 | | scope.Start(); |
| | 573 | |
|
| | 574 | | try |
| | 575 | | { |
| 6 | 576 | | Response<SecretProperties> response = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new Sec |
| 2 | 577 | | return new RecoverDeletedSecretOperation(_pipeline, response); |
| | 578 | | } |
| 2 | 579 | | catch (Exception e) |
| | 580 | | { |
| 2 | 581 | | scope.Failed(e); |
| 2 | 582 | | throw; |
| | 583 | | } |
| 2 | 584 | | } |
| | 585 | |
|
| | 586 | | /// <summary> |
| | 587 | | /// Recovers the deleted secret to the latest version. |
| | 588 | | /// </summary> |
| | 589 | | /// <remarks> |
| | 590 | | /// Recovers the deleted secret in the specified vault. This operation can only |
| | 591 | | /// be performed on a soft-delete enabled vault. This operation requires the |
| | 592 | | /// secrets/recover permission. |
| | 593 | | /// </remarks> |
| | 594 | | /// <param name="name">The name of the secret.</param> |
| | 595 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 596 | | /// <returns>A <see cref="RecoverDeletedSecretOperation"/> to wait on this long-running operation.</returns> |
| | 597 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 598 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 599 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 600 | | public virtual RecoverDeletedSecretOperation StartRecoverDeletedSecret(string name, CancellationToken cancellati |
| | 601 | | { |
| 8 | 602 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 603 | |
|
| 4 | 604 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(StartRecoverDeletedSecr |
| 4 | 605 | | scope.AddAttribute("secret", name); |
| 4 | 606 | | scope.Start(); |
| | 607 | |
|
| | 608 | | try |
| | 609 | | { |
| 6 | 610 | | Response<SecretProperties> response = _pipeline.SendRequest(RequestMethod.Post, () => new SecretProperti |
| 2 | 611 | | return new RecoverDeletedSecretOperation(_pipeline, response); |
| | 612 | | } |
| 2 | 613 | | catch (Exception e) |
| | 614 | | { |
| 2 | 615 | | scope.Failed(e); |
| 2 | 616 | | throw; |
| | 617 | | } |
| 2 | 618 | | } |
| | 619 | |
|
| | 620 | | /// <summary> |
| | 621 | | /// Permanently deletes the specified secret. |
| | 622 | | /// </summary> |
| | 623 | | /// <remarks> |
| | 624 | | /// The purge deleted secret operation removes the secret permanently, without |
| | 625 | | /// the possibility of recovery. This operation can only be enabled on a |
| | 626 | | /// soft-delete enabled vault. This operation requires the secrets/purge |
| | 627 | | /// permission. |
| | 628 | | /// </remarks> |
| | 629 | | /// <param name="name">The name of the secret.</param> |
| | 630 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 631 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 632 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 633 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 634 | | public virtual async Task<Response> PurgeDeletedSecretAsync(string name, CancellationToken cancellationToken = d |
| | 635 | | { |
| 4 | 636 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 637 | |
|
| 0 | 638 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(PurgeDeletedSecret)}"); |
| 0 | 639 | | scope.AddAttribute("secret", name); |
| 0 | 640 | | scope.Start(); |
| | 641 | |
|
| | 642 | | try |
| | 643 | | { |
| 0 | 644 | | return await _pipeline.SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedSecretsPath, nam |
| | 645 | | } |
| 0 | 646 | | catch (Exception e) |
| | 647 | | { |
| 0 | 648 | | scope.Failed(e); |
| 0 | 649 | | throw; |
| | 650 | | } |
| 0 | 651 | | } |
| | 652 | |
|
| | 653 | | /// <summary> |
| | 654 | | /// Permanently deletes the specified secret. |
| | 655 | | /// </summary> |
| | 656 | | /// <remarks> |
| | 657 | | /// The purge deleted secret operation removes the secret permanently, without |
| | 658 | | /// the possibility of recovery. This operation can only be enabled on a |
| | 659 | | /// soft-delete enabled vault. This operation requires the secrets/purge |
| | 660 | | /// permission. |
| | 661 | | /// </remarks> |
| | 662 | | /// <param name="name">The name of the secret.</param> |
| | 663 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 664 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 665 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 666 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 667 | | public virtual Response PurgeDeletedSecret(string name, CancellationToken cancellationToken = default) |
| | 668 | | { |
| 4 | 669 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 670 | |
|
| 0 | 671 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(PurgeDeletedSecret)}"); |
| 0 | 672 | | scope.AddAttribute("secret", name); |
| 0 | 673 | | scope.Start(); |
| | 674 | |
|
| | 675 | | try |
| | 676 | | { |
| 0 | 677 | | return _pipeline.SendRequest(RequestMethod.Delete, cancellationToken, DeletedSecretsPath, name); |
| | 678 | | } |
| 0 | 679 | | catch (Exception e) |
| | 680 | | { |
| 0 | 681 | | scope.Failed(e); |
| 0 | 682 | | throw; |
| | 683 | | } |
| 0 | 684 | | } |
| | 685 | |
|
| | 686 | | /// <summary> |
| | 687 | | /// Backs up the specified secret. |
| | 688 | | /// </summary> |
| | 689 | | /// <remarks> |
| | 690 | | /// Requests that a backup of the specified secret be downloaded to the client. |
| | 691 | | /// All versions of the secret will be downloaded. This operation requires the |
| | 692 | | /// secrets/backup permission. |
| | 693 | | /// </remarks> |
| | 694 | | /// <param name="name">The name of the secret.</param> |
| | 695 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 696 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 697 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 698 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 699 | | public virtual async Task<Response<byte[]>> BackupSecretAsync(string name, CancellationToken cancellationToken = |
| | 700 | | { |
| 4 | 701 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 702 | |
|
| 4 | 703 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(BackupSecret)}"); |
| 4 | 704 | | scope.AddAttribute("secret", name); |
| 4 | 705 | | scope.Start(); |
| | 706 | |
|
| | 707 | | try |
| | 708 | | { |
| 6 | 709 | | Response<SecretBackup> backup = await _pipeline.SendRequestAsync(RequestMethod.Post, () => new SecretBac |
| | 710 | |
|
| 2 | 711 | | return Response.FromValue(backup.Value.Value, backup.GetRawResponse()); |
| | 712 | | } |
| 2 | 713 | | catch (Exception e) |
| | 714 | | { |
| 2 | 715 | | scope.Failed(e); |
| 2 | 716 | | throw; |
| | 717 | | } |
| 2 | 718 | | } |
| | 719 | |
|
| | 720 | | /// <summary> |
| | 721 | | /// Backs up the specified secret. |
| | 722 | | /// </summary> |
| | 723 | | /// <remarks> |
| | 724 | | /// Requests that a backup of the specified secret be downloaded to the client. |
| | 725 | | /// All versions of the secret will be downloaded. This operation requires the |
| | 726 | | /// secrets/backup permission. |
| | 727 | | /// </remarks> |
| | 728 | | /// <param name="name">The name of the secret.</param> |
| | 729 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 730 | | /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception> |
| | 731 | | /// <exception cref="ArgumentNullException"><paramref name="name"/> is null.</exception> |
| | 732 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 733 | | public virtual Response<byte[]> BackupSecret(string name, CancellationToken cancellationToken = default) |
| | 734 | | { |
| 4 | 735 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 736 | |
|
| 4 | 737 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(BackupSecret)}"); |
| 4 | 738 | | scope.AddAttribute("secret", name); |
| 4 | 739 | | scope.Start(); |
| | 740 | |
|
| | 741 | | try |
| | 742 | | { |
| 6 | 743 | | Response<SecretBackup> backup = _pipeline.SendRequest(RequestMethod.Post, () => new SecretBackup(), canc |
| | 744 | |
|
| 2 | 745 | | return Response.FromValue(backup.Value.Value, backup.GetRawResponse()); |
| | 746 | | } |
| 2 | 747 | | catch (Exception e) |
| | 748 | | { |
| 2 | 749 | | scope.Failed(e); |
| 2 | 750 | | throw; |
| | 751 | | } |
| 2 | 752 | | } |
| | 753 | |
|
| | 754 | | /// <summary> |
| | 755 | | /// Restores a backed up secret to a vault. |
| | 756 | | /// </summary> |
| | 757 | | /// <remarks> |
| | 758 | | /// Restores a backed up secret, and all its versions, to a vault. This |
| | 759 | | /// operation requires the secrets/restore permission. |
| | 760 | | /// </remarks> |
| | 761 | | /// <param name="backup">The backup blob associated with a secret.</param> |
| | 762 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 763 | | /// <exception cref="ArgumentNullException"><paramref name="backup"/> is null.</exception> |
| | 764 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 765 | | public virtual async Task<Response<SecretProperties>> RestoreSecretBackupAsync(byte[] backup, CancellationToken |
| | 766 | | { |
| 4 | 767 | | Argument.AssertNotNull(backup, nameof(backup)); |
| | 768 | |
|
| 2 | 769 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(RestoreSecretBackup)}") |
| 2 | 770 | | scope.Start(); |
| | 771 | |
|
| | 772 | | try |
| | 773 | | { |
| 0 | 774 | | return await _pipeline.SendRequestAsync(RequestMethod.Post, new SecretBackup { Value = backup }, () => n |
| | 775 | | } |
| 2 | 776 | | catch (Exception e) |
| | 777 | | { |
| 2 | 778 | | scope.Failed(e); |
| 2 | 779 | | throw; |
| | 780 | | } |
| 0 | 781 | | } |
| | 782 | |
|
| | 783 | | /// <summary> |
| | 784 | | /// Restores a backed up secret to a vault. |
| | 785 | | /// </summary> |
| | 786 | | /// <remarks> |
| | 787 | | /// Restores a backed up secret, and all its versions, to a vault. This |
| | 788 | | /// operation requires the secrets/restore permission. |
| | 789 | | /// </remarks> |
| | 790 | | /// <param name="backup">The backup blob associated with a secret.</param> |
| | 791 | | /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> |
| | 792 | | /// <exception cref="ArgumentNullException"><paramref name="backup"/> is null.</exception> |
| | 793 | | /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> f |
| | 794 | | public virtual Response<SecretProperties> RestoreSecretBackup(byte[] backup, CancellationToken cancellationToken |
| | 795 | | { |
| 4 | 796 | | Argument.AssertNotNull(backup, nameof(backup)); |
| | 797 | |
|
| 2 | 798 | | using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(SecretClient)}.{nameof(RestoreSecretBackup)}") |
| 2 | 799 | | scope.Start(); |
| | 800 | |
|
| | 801 | | try |
| | 802 | | { |
| 0 | 803 | | return _pipeline.SendRequest(RequestMethod.Post, new SecretBackup { Value = backup }, () => new SecretPr |
| | 804 | | } |
| 2 | 805 | | catch (Exception e) |
| | 806 | | { |
| 2 | 807 | | scope.Failed(e); |
| 2 | 808 | | throw; |
| | 809 | | } |
| 0 | 810 | | } |
| | 811 | | } |
| | 812 | | } |