11using Fossa . API . Core . Repositories ;
2+ using Fossa . API . Core . Telemetry ;
23using Fossa . Licensing ;
34using Microsoft . Extensions . Hosting ;
45using TIKSN . Deployment ;
@@ -12,17 +13,20 @@ public class SystemLicenseRetriever : ISystemLicenseRetriever
1213 private readonly IHostEnvironment _hostEnvironment ;
1314 private readonly ILicenseFactory < SystemEntitlements , SystemLicenseEntitlements > _licenseFactory ;
1415 private readonly ILicenseFileRepository _licenseFileRepository ;
16+ private readonly ISystemLicenseMetricsRecorder _systemLicenseMetricsRecorder ;
1517 private readonly ISystemPropertiesQueryRepository _systemPropertiesQueryRepository ;
1618
1719 public SystemLicenseRetriever (
1820 ILicenseFileRepository licenseFileRepository ,
1921 ILicenseFactory < SystemEntitlements , SystemLicenseEntitlements > licenseFactory ,
22+ ISystemLicenseMetricsRecorder systemLicenseMetricsRecorder ,
2023 ICertificateProvider certificateProvider ,
2124 IHostEnvironment hostEnvironment ,
2225 ISystemPropertiesQueryRepository systemPropertiesQueryRepository )
2326 {
2427 _licenseFileRepository = licenseFileRepository ?? throw new ArgumentNullException ( nameof ( licenseFileRepository ) ) ;
2528 _licenseFactory = licenseFactory ?? throw new ArgumentNullException ( nameof ( licenseFactory ) ) ;
29+ _systemLicenseMetricsRecorder = systemLicenseMetricsRecorder ?? throw new ArgumentNullException ( nameof ( systemLicenseMetricsRecorder ) ) ;
2630 _certificateProvider = certificateProvider ?? throw new ArgumentNullException ( nameof ( certificateProvider ) ) ;
2731 _hostEnvironment = hostEnvironment ?? throw new ArgumentNullException ( nameof ( hostEnvironment ) ) ;
2832 _systemPropertiesQueryRepository = systemPropertiesQueryRepository ?? throw new ArgumentNullException ( nameof ( systemPropertiesQueryRepository ) ) ;
@@ -41,12 +45,16 @@ public async Task<Validation<Error, License<SystemEntitlements>>> GetAsync(Cance
4145
4246 var licenseValidation = _licenseFactory . Create ( licenseData , certificate ) ;
4347
44- return licenseValidation
48+ licenseValidation = licenseValidation
4549 . Validate (
4650 license => license . Entitlements . SystemId == systemPropertiesEntity . SystemID ,
4751 11751858 , "Current System License is issued to another system." )
4852 . Validate (
4953 license => _hostEnvironment . MatchesEnvironment ( license . Entitlements . EnvironmentName ) ,
5054 19509088 , "Current System License is issued for another deployment environment." ) ;
55+
56+ _systemLicenseMetricsRecorder . Record ( licenseValidation ) ;
57+
58+ return licenseValidation ;
5159 }
5260}
0 commit comments