< Summary

Class:Azure.Messaging.EventHubs.EventHubSharedKeyCredential
Assembly:Azure.Messaging.EventHubs.Processor
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Authorization\EventHubSharedKeyCredential.cs
Covered lines:0
Uncovered lines:20
Coverable lines:20
Total lines:119
Line coverage:0% (0 of 20)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_SharedAccessKeyName()-0%100%
get_SharedAccessKey()-0%100%
get_SharedAccessSignatureCredential()-0%100%
.ctor(...)-0%100%
GetToken(...)-0%100%
GetTokenAsync(...)-0%100%
UpdateSharedAccessKey(...)-0%0%
AsSharedAccessSignatureCredential(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Authorization\EventHubSharedKeyCredential.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading;
 6using System.Threading.Tasks;
 7using Azure.Core;
 8using Azure.Messaging.EventHubs.Authorization;
 9
 10namespace Azure.Messaging.EventHubs
 11{
 12    /// <summary>
 13    ///   Provides a credential based on a shared access signature for a given
 14    ///   Event Hub instance.
 15    /// </summary>
 16    ///
 17    /// <seealso cref="Azure.Core.TokenCredential" />
 18    ///
 19    internal sealed class EventHubSharedKeyCredential : TokenCredential
 20    {
 21        /// <summary>
 22        ///   The name of the shared access key to be used for authorization, as
 23        ///   reported by the Azure portal.
 24        /// </summary>
 25        ///
 026        private string SharedAccessKeyName { get; set; }
 27
 28        /// <summary>
 29        ///   The value of the shared access key to be used for authorization, as
 30        ///   reported by the Azure portal.
 31        /// </summary>
 32        ///
 033        private string SharedAccessKey { get; set; }
 34
 35        /// <summary>
 36        ///   A reference to a corresponding SharedAccessSignatureCredential.
 37        /// </summary>
 38        ///
 039        private SharedAccessSignatureCredential SharedAccessSignatureCredential { get; set; }
 40
 41        /// <summary>
 42        ///   Initializes a new instance of the <see cref="EventHubSharedKeyCredential"/> class.
 43        /// </summary>
 44        ///
 45        /// <param name="sharedAccessKeyName">The name of the shared access key to be used for authorization, as reporte
 46        /// <param name="sharedAccessKey">The value of the shared access key to be used for authorization, as reported b
 47        ///
 048        public EventHubSharedKeyCredential(string sharedAccessKeyName,
 049                                           string sharedAccessKey)
 50        {
 051            Argument.AssertNotNullOrEmpty(sharedAccessKeyName, nameof(sharedAccessKeyName));
 052            Argument.AssertNotNullOrEmpty(sharedAccessKey, nameof(sharedAccessKey));
 53
 054            SharedAccessKeyName = sharedAccessKeyName;
 055            SharedAccessKey = sharedAccessKey;
 056        }
 57
 58        /// <summary>
 59        ///   Retrieves the token that represents the shared access signature credential, for
 60        ///   use in authorization against an Event Hub.
 61        /// </summary>
 62        ///
 63        /// <param name="requestContext">The details of the authentication request.</param>
 64        /// <param name="cancellationToken">The token used to request cancellation of the operation.</param>
 65        ///
 66        /// <returns>The token representing the shared access signature for this credential.</returns>
 67        ///
 068        public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) =>
 69
 70        /// <summary>
 71        ///   Retrieves the token that represents the shared access signature credential, for
 72        ///   use in authorization against an Event Hub.
 73        /// </summary>
 74        ///
 75        /// <param name="requestContext">The details of the authentication request.</param>
 76        /// <param name="cancellationToken">The token used to request cancellation of the operation.</param>
 77        ///
 78        /// <returns>The token representing the shared access signature for this credential.</returns>
 79        ///
 080        public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cance
 81
 82        /// <summary>
 83        ///   Allows the rotation of Shared Access Signatures.
 84        /// </summary>
 85        ///
 86        /// <param name="keyName">The name of the shared access key that the signature should be based on.</param>
 87        /// <param name="keyValue">The value of the shared access key for the signature.</param>
 88        ///
 89        public void UpdateSharedAccessKey(string keyName,
 90                                          string keyValue)
 91        {
 092            Argument.AssertNotNullOrEmpty(keyName, nameof(keyName));
 093            Argument.AssertNotNullOrEmpty(keyValue, nameof(keyValue));
 94
 095            SharedAccessKeyName = keyName;
 096            SharedAccessKey = keyValue;
 97
 098            SharedAccessSignatureCredential?.UpdateSharedAccessKey(keyName, keyValue);
 099        }
 100
 101        /// <summary>
 102        ///   Coverts to shared access signature credential.
 103        ///   It retains a reference to the generated SharedAccessSignatureCredential.
 104        /// </summary>
 105        ///
 106        /// <param name="eventHubResource">The Event Hubs resource to which the token is intended to serve as authorizat
 107        /// <param name="signatureValidityDuration">The duration that the signature should be considered valid; if not s
 108        ///
 109        /// <returns>A new <see cref="SharedAccessSignatureCredential" /> based on the requested shared access key.</ret
 110        ///
 111        internal SharedAccessSignatureCredential AsSharedAccessSignatureCredential(string eventHubResource,
 112                                                                                   TimeSpan? signatureValidityDuration =
 113        {
 0114            SharedAccessSignatureCredential = new SharedAccessSignatureCredential(new SharedAccessSignature(eventHubReso
 115
 0116            return SharedAccessSignatureCredential;
 117        }
 118    }
 119}