< Summary

Class:Azure.Template.MiniSecretClient
Assembly:Azure.Template
File(s):C:\Git\azure-sdk-for-net\sdk\template\Azure.Template\src\MiniSecretClient.cs
Covered lines:22
Uncovered lines:8
Coverable lines:30
Total lines:92
Line coverage:73.3% (22 of 30)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_RestClient()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%100%
.ctor()-100%100%
.ctor(...)-100%100%
GetSecretAsync()-57.14%100%
GetSecret(...)-57.14%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\template\Azure.Template\src\MiniSecretClient.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.Core.Pipeline;
 9using Azure.Template.Models;
 10
 11namespace Azure.Template
 12{
 13    /// <summary>
 14    /// The sample secrets client.
 15    /// </summary>
 16    public class MiniSecretClient
 17    {
 18        private readonly ClientDiagnostics _clientDiagnostics;
 19        private readonly HttpPipeline _pipeline;
 420        internal ServiceRestClient RestClient { get; }
 21
 22        /// <summary>
 23        /// Initializes a new instance of the <see cref="MiniSecretClient"/>.
 24        /// </summary>
 025        public MiniSecretClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new MiniSecretCli
 26        {
 027        }
 28
 29        /// <summary>
 30        /// Initializes a new instance of the <see cref="MiniSecretClient"/>.
 31        /// </summary>
 432        public MiniSecretClient(Uri endpoint, TokenCredential credential, MiniSecretClientOptions options): this(
 433            new ClientDiagnostics(options),
 434            HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, "https://vault.azure.net/
 435            endpoint.ToString(),
 436            options.Version)
 37        {
 438        }
 39
 40        /// <summary> Initializes a new instance of MiniSecretClient for mocking. </summary>
 441        protected MiniSecretClient()
 42        {
 443        }
 44        /// <summary> Initializes a new instance of MiniSecretClient. </summary>
 45        /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param>
 46        /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param>
 47        /// <param name="vaultBaseUrl"> The vault name, for example https://myvault.vault.azure.net. </param>
 48        /// <param name="apiVersion"> Api Version. </param>
 449        internal MiniSecretClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string vaultBaseUrl, strin
 50        {
 451            RestClient = new ServiceRestClient(clientDiagnostics, pipeline, vaultBaseUrl, apiVersion);
 452            _clientDiagnostics = clientDiagnostics;
 453            _pipeline = pipeline;
 454        }
 55
 56        /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t
 57        /// <param name="secretName"> The name of the secret. </param>
 58        /// <param name="cancellationToken"> The cancellation token to use. </param>
 59        public virtual async Task<Response<SecretBundle>> GetSecretAsync(string secretName, CancellationToken cancellati
 60        {
 261            using var scope = _clientDiagnostics.CreateScope("MiniSecretClient.GetSecret");
 262            scope.Start();
 63            try
 64            {
 265                return await RestClient.GetSecretAsync(secretName, cancellationToken).ConfigureAwait(false);
 66            }
 067            catch (Exception e)
 68            {
 069                scope.Failed(e);
 070                throw;
 71            }
 272        }
 73
 74        /// <summary> The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires t
 75        /// <param name="secretName"> The name of the secret. </param>
 76        /// <param name="cancellationToken"> The cancellation token to use. </param>
 77        public virtual Response<SecretBundle> GetSecret(string secretName, CancellationToken cancellationToken = default
 78        {
 279            using var scope = _clientDiagnostics.CreateScope("MiniSecretClient.GetSecret");
 280            scope.Start();
 81            try
 82            {
 283                return RestClient.GetSecret(secretName, cancellationToken);
 84            }
 085            catch (Exception e)
 86            {
 087                scope.Failed(e);
 088                throw;
 89            }
 290        }
 91    }
 92}