|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using Microsoft.ApplicationInsights; |
5 | 7 | using NuGet.Services.Validation; |
6 | 8 |
|
7 | 9 | namespace Validation.PackageSigning.ValidateCertificate |
8 | 10 | { |
9 | 11 | public class TelemetryService : ITelemetryService |
10 | 12 | { |
| 13 | + private const string PackageSignatureMayBeInvalidated = "PackageSignatureMayBeInvalidated"; |
| 14 | + private const string PackageSignatureShouldBeInvalidated = "PackageSignatureShouldBeInvalidated"; |
| 15 | + private const string UnableToValidateCertificate = "UnableToValidateCertificate"; |
| 16 | + |
| 17 | + private const string PackageId = "PackageId"; |
| 18 | + private const string PackageNormalizedVersion = "PackageNormalizedVersion"; |
| 19 | + private const string PackageSignatureId = "PackageSignatureId"; |
| 20 | + private const string CertificateId = "CertificateId"; |
| 21 | + private const string CertificateThumbprint = "CertificateThumbprint"; |
| 22 | + |
| 23 | + private readonly TelemetryClient _telemetryClient; |
| 24 | + |
| 25 | + public TelemetryService(TelemetryClient telemetryClient) |
| 26 | + { |
| 27 | + _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); |
| 28 | + } |
| 29 | + |
11 | 30 | public void TrackPackageSignatureMayBeInvalidatedEvent(PackageSignature signature) |
12 | 31 | { |
13 | | - // TODO |
14 | | - throw new NotImplementedException(); |
| 32 | + _telemetryClient.TrackMetric( |
| 33 | + PackageSignatureMayBeInvalidated, |
| 34 | + 1, |
| 35 | + new Dictionary<string, string> |
| 36 | + { |
| 37 | + { PackageId, signature.PackageSigningState.PackageId }, |
| 38 | + { PackageNormalizedVersion, signature.PackageSigningState.PackageNormalizedVersion }, |
| 39 | + { PackageSignatureId, signature.Key.ToString() } |
| 40 | + }); |
15 | 41 | } |
16 | 42 |
|
17 | 43 | public void TrackPackageSignatureShouldBeInvalidatedEvent(PackageSignature signature) |
18 | 44 | { |
19 | | - // TODO |
20 | | - throw new NotImplementedException(); |
| 45 | + _telemetryClient.TrackMetric( |
| 46 | + PackageSignatureShouldBeInvalidated, |
| 47 | + 1, |
| 48 | + new Dictionary<string, string> |
| 49 | + { |
| 50 | + { PackageId, signature.PackageSigningState.PackageId }, |
| 51 | + { PackageNormalizedVersion, signature.PackageSigningState.PackageNormalizedVersion }, |
| 52 | + { PackageSignatureId, signature.Key.ToString() } |
| 53 | + }); |
21 | 54 | } |
22 | 55 |
|
23 | 56 | public void TrackUnableToValidateCertificateEvent(EndCertificate certificate) |
24 | 57 | { |
25 | | - // TODO |
26 | | - throw new NotImplementedException(); |
| 58 | + _telemetryClient.TrackMetric( |
| 59 | + PackageSignatureMayBeInvalidated, |
| 60 | + 1, |
| 61 | + new Dictionary<string, string> |
| 62 | + { |
| 63 | + { CertificateId, certificate.Key.ToString() }, |
| 64 | + { CertificateThumbprint, certificate.Thumbprint } |
| 65 | + }); |
27 | 66 | } |
28 | 67 | } |
29 | 68 | } |
0 commit comments