| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using Azure.Core.Pipeline; |
| | | 5 | | |
| | | 6 | | namespace Azure.Core |
| | | 7 | | { |
| | | 8 | | internal class AzureKeyCredentialPolicy : HttpPipelineSynchronousPolicy |
| | | 9 | | { |
| | | 10 | | private readonly string _name; |
| | | 11 | | private readonly AzureKeyCredential _credential; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="AzureKeyCredentialPolicy"/> class. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="credential">The <see cref="AzureKeyCredential"/> used to authenticate requests.</param> |
| | | 17 | | /// <param name="name">The name of the key header used for the credential.</param> |
| | 0 | 18 | | public AzureKeyCredentialPolicy(AzureKeyCredential credential, string name) |
| | | 19 | | { |
| | 0 | 20 | | Argument.AssertNotNull(credential, nameof(credential)); |
| | 0 | 21 | | Argument.AssertNotNullOrEmpty(name, nameof(name)); |
| | 0 | 22 | | _credential = credential; |
| | 0 | 23 | | _name = name; |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc/> |
| | | 27 | | public override void OnSendingRequest(HttpMessage message) |
| | | 28 | | { |
| | 0 | 29 | | base.OnSendingRequest(message); |
| | 0 | 30 | | message.Request.Headers.SetValue(_name, _credential.Key); |
| | 0 | 31 | | } |
| | | 32 | | } |
| | | 33 | | } |