< Summary

Class:Azure.Security.KeyVault.Certificates.CertificateOperationProperties
Assembly:Azure.Security.KeyVault.Certificates
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\CertificateOperationProperties.cs
Covered lines:47
Uncovered lines:13
Coverable lines:60
Total lines:187
Line coverage:78.3% (47 of 60)
Covered branches:48
Total branches:50
Branch coverage:96% (48 of 50)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
get_Id()-100%100%
get_Name()-100%100%
get_VaultUri()-0%100%
get_IssuerName()-0%100%
set_IssuerName(...)-0%100%
get_CertificateType()-0%100%
set_CertificateType(...)-0%100%
get_CertificateTransparency()-0%100%
set_CertificateTransparency(...)-0%100%
get_Csr()-100%100%
get_CancellationRequested()-0%100%
get_RequestId()-0%100%
get_Status()-100%100%
get_StatusDetails()-0%100%
get_Target()-0%100%
get_Error()-100%100%
Azure.Security.KeyVault.IJsonDeserializable.ReadProperties(...)-100%100%
ParseId(...)-71.43%66.67%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Certificates\src\CertificateOperationProperties.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6using System.Text.Json;
 7using Azure.Core;
 8
 9namespace Azure.Security.KeyVault.Certificates
 10{
 11    /// <summary>
 12    /// Properties pertaining to the status of a certificate operation.
 13    /// </summary>
 14    public class CertificateOperationProperties : IJsonDeserializable
 15    {
 16        private const string IdPropertyName = "id";
 17        private const string IssuerProperyName = "issuer";
 18        private const string CsrPropertyName = "csr";
 19        private const string CancellationRequestedPropertyName = "cancellation_requested";
 20        private const string RequestIdPropertyName = "request_id";
 21        private const string StatusPropertyName = "status";
 22        private const string StatusDetailsPropertyName = "status_details";
 23        private const string TargetPropertyName = "target";
 24        private const string ErrorPropertyName = "error";
 25        private const string Collection = "certificates/";
 26
 27        private IssuerParameters _issuer;
 28
 74229        internal CertificateOperationProperties()
 30        {
 74231        }
 32
 1633        internal CertificateOperationProperties(Uri vaultUri, string name)
 34        {
 1635            VaultUri = vaultUri;
 1636            Name = name;
 37
 1638            RequestUriBuilder builder = new RequestUriBuilder
 1639            {
 1640                Scheme = vaultUri.Scheme,
 1641                Host = vaultUri.Host,
 1642                Port = vaultUri.Port,
 1643                Path = Collection + name,
 1644            };
 45
 1646            Id = builder.ToUri();
 1647        }
 48
 49        /// <summary>
 50        /// Gets the identifier of the certificate operation.
 51        /// </summary>
 157652        public Uri Id { get; internal set; }
 53
 54        /// <summary>
 55        /// Gets the name of the certificate to which the operation applies.
 56        /// </summary>
 148057        public string Name { get; internal set; }
 58
 59        /// <summary>
 60        /// Gets the <see cref="Uri"/> of the vault executing the certificate operation.
 61        /// </summary>
 062        public Uri VaultUri { get; internal set; }
 63
 64        /// <summary>
 65        /// Gets the name of the <see cref="CertificateIssuer"/> for the certificate to create.
 66        /// </summary>
 67        public string IssuerName
 68        {
 069            get => _issuer.IssuerName;
 070            internal set => _issuer.IssuerName = value;
 71        }
 72
 73        /// <summary>
 74        /// Gets the type of the certificate to create.
 75        /// </summary>
 76        public string CertificateType
 77        {
 078            get => _issuer.CertificateType;
 079            internal set => _issuer.CertificateType = value;
 80        }
 81
 82        /// <summary>
 83        /// Gets a value indicating whether the certificate will be published to the certificate transparency list when 
 84        /// </summary>
 85        public bool? CertificateTransparency
 86        {
 087            get => _issuer.CertificateTransparency;
 088            internal set => _issuer.CertificateTransparency = value;
 89        }
 90
 91        /// <summary>
 92        /// Gets the certificate signing request (CSR) that is being used in the certificate operation.
 93        /// </summary>
 74694        public byte[] Csr { get; internal set; }
 95
 96        /// <summary>
 97        /// Gets a value indicating whether a cancellation has been requested for the operation.
 98        /// </summary>
 099        public bool CancellationRequested { get; internal set; }
 100
 101        /// <summary>
 102        /// Gets the request identifier of the certificate operation.
 103        /// </summary>
 0104        public string RequestId { get; internal set; }
 105
 106        /// <summary>
 107        /// Gets the current status of the operation.
 108        /// </summary>
 2106109        public string Status { get; internal set; }
 110
 111        /// <summary>
 112        /// Gets extended details on the status of the operation.
 113        /// </summary>
 0114        public string StatusDetails { get; internal set; }
 115
 116        /// <summary>
 117        /// Gets the location which will contain the result of the certificate operation.
 118        /// </summary>
 0119        public string Target { get; internal set; }
 120
 121        /// <summary>
 122        /// Gets any errors encountered during the processing of the certificate operation.
 123        /// </summary>
 690124        public CertificateOperationError Error { get; internal set; }
 125
 126        void IJsonDeserializable.ReadProperties(JsonElement json)
 127        {
 11856128            foreach (JsonProperty prop in json.EnumerateObject())
 129            {
 5186130                switch (prop.Name)
 131                {
 132                    case IdPropertyName:
 742133                        var id = prop.Value.GetString();
 742134                        Id = new Uri(id);
 742135                        ParseId(Id);
 742136                        break;
 137
 138                    case IssuerProperyName:
 742139                        _issuer.ReadProperties(prop.Value);
 742140                        break;
 141
 142                    case CsrPropertyName:
 742143                        Csr = prop.Value.GetBytesFromBase64();
 742144                        break;
 145
 146                    case CancellationRequestedPropertyName:
 742147                        CancellationRequested = prop.Value.GetBoolean();
 742148                        break;
 149
 150                    case RequestIdPropertyName:
 742151                        RequestId = prop.Value.GetString();
 742152                        break;
 153
 154                    case StatusPropertyName:
 742155                        Status = prop.Value.GetString();
 742156                        break;
 157
 158                    case StatusDetailsPropertyName:
 702159                        StatusDetails = prop.Value.GetString();
 702160                        break;
 161
 162                    case TargetPropertyName:
 28163                        Target = prop.Value.GetString();
 28164                        break;
 165
 166                    case ErrorPropertyName:
 4167                        Error = new CertificateOperationError();
 4168                        ((IJsonDeserializable)Error).ReadProperties(prop.Value);
 169                        break;
 170                }
 171            }
 742172        }
 173
 174        private void ParseId(Uri idToParse)
 175        {
 176            // We expect an identifier with either 3 or 4 segments: host + collection + name [+ version]
 742177            if (idToParse.Segments.Length != 3 && idToParse.Segments.Length != 4)
 0178                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}. 
 179
 742180            if (!string.Equals(idToParse.Segments[1], Collection, StringComparison.OrdinalIgnoreCase))
 0181                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}. 
 182
 742183            VaultUri = new Uri($"{idToParse.Scheme}://{idToParse.Authority}");
 742184            Name = idToParse.Segments[2].Trim('/');
 742185        }
 186    }
 187}