-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging through to Azure services #808
base: main
Are you sure you want to change the base?
Conversation
- Introduced a private field `servicesToAdd` in `ServiceProviderFactory` to store additional services. - Added `AddServices` method to `ServiceProviderFactory` to add services via an `Action<IServiceCollection>` parameter. - Updated `Create` method to include `servicesToAdd` if not null. - Added `ServiceProviderFactoryTests` to verify new functionality. - Tests include null check, service addition, and service provider creation. - Defined `ITestService`, `TestService`, `ITestService2`, and `TestService2` for testing purposes.
Introduce Microsoft.Extensions.Azure package and refactor TrustedSigningService to use dependency injection for CertificateProfileClient. Update TrustedSigningServiceProvider to rely on service provider for instances. Add localized string resources for "Certificate Details" in multiple languages. Update tests to reflect changes and remove obsolete tests. Log detailed certificate information in TrustedSigningService.
src/Sign.SignatureProviders.TrustedSigning/TrustedSigningService.cs
Outdated
Show resolved
Hide resolved
8d010cc
to
8463ad2
Compare
…existing ones to match.
8463ad2
to
67fb84e
Compare
…ly disposed of after use.
- Updated `AzureKeyVaultCommand.cs` to construct and validate URIs for certificates and keys using Azure SDK, and configured Azure clients and services with dependency injection so logging forwards through. - Added `InvalidKeyVaultUrl` localized string in `AzureKeyVaultResources.Designer.cs` and updated `AzureKeyVaultResources.resx`. - Refactored `KeyVaultService.cs` to use `CertificateClient` and `CryptographyClient` for simplified service operations. - Simplified `KeyVaultServiceProvider.cs` by using dependency injection for `KeyVaultService` retrieval. - Removed `PrivateAssets` attribute from `Azure.Security.KeyVault.Certificates` and `Azure.Security.KeyVault.Keys` in `Sign.SignatureProviders.KeyVault.csproj` for runtime availability.
Also avoids unused parameter error
Co-authored-by: Damon Tivel <[email protected]>
…e when signing fails
|
||
namespace Sign.Core | ||
{ | ||
internal class SigningException : Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sealed
Also, add a blank line between members.
@@ -117,6 +117,9 @@ | |||
<resheader name="writer"> | |||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||
</resheader> | |||
<data name="CertificateDetails" xml:space="preserve"> | |||
<value>Certificate Details:</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<value>Certificate Details:</value> | |
<value>Certificate details:</value> |
This is to be consistent with https://github.com/dotnet/sign/pull/808/files#diff-04854b03e08087d8a503b4b9480e748e19826ee8603241c1cdb3eeb05eaaf80dR121.
Be sure to regenerate .xlf files.
} | ||
|
||
[Fact] | ||
public void AddServices_AddedServicesAreAdded() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name convention is <MemberName>_<Condition>_<Result>
public void AddServices_AddedServicesAreAdded() | |
public void AddServices_Always_AddedServicesAreAdded() |
} | ||
|
||
[Fact] | ||
public void AddServices_AddedIfAddedServicesAreAlsoPresent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void AddServices_AddedIfAddedServicesAreAlsoPresent() | |
public void AddServices_WhenAddedServicesAreAlreadyPresent_ServicesAdded() |
} | ||
|
||
[Fact] | ||
public void Create_NoAddedServices() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void Create_NoAddedServices() | |
public void Create_WithNoAddedServices_ReturnsDefault() |
[Fact] | ||
public void GetSignatureAlgorithmProvider_WhenServiceProviderIsNull_Throws() | ||
{ | ||
TrustedSigningServiceProvider provider = new(TokenCredential, EndpointUrl, AccountName, CertificateProfileName); | ||
TrustedSigningServiceProvider provider = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all tests do this, you could promote this to a field and make the bodies of the tests more succinct.
private readonly TrustedSigningServiceProvider _provider = new();
private const string AccountName = "a"; | ||
private const string CertificateProfileName = "b"; | ||
private readonly static ILogger<TrustedSigningService> Logger = Mock.Of<ILogger<TrustedSigningService>>(); | ||
private static readonly ILogger<TrustedSigningService> Logger = Mock.Of<ILogger<TrustedSigningService>>(); | ||
|
||
[Fact] | ||
public void Constructor_WhenTokenCredentialIsNull_Throws() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void Constructor_WhenTokenCredentialIsNull_Throws() | |
public void Constructor_WhenCertificateProfileClientIsNull_Throws() |
@@ -102,16 +65,9 @@ public void GetCertificateProvider_WhenServiceProviderIsNull_Throws() | |||
[Fact] | |||
public void GetCertificateProvider_ReturnsSameInstance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void GetCertificateProvider_ReturnsSameInstance() | |
public void GetCertificateProvider_Always_ReturnsSameInstance() |
@@ -76,22 +46,15 @@ public void GetSignatureAlgorithmProvider_WhenServiceProviderIsNull_Throws() | |||
[Fact] | |||
public void GetSignatureAlgorithmProvider_ReturnsSameInstance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void GetSignatureAlgorithmProvider_ReturnsSameInstance() | |
public void GetSignatureAlgorithmProvider_Always_ReturnsSameInstance() |
"a", sp.GetRequiredService<ILogger<KeyVaultService>>() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a", sp.GetRequiredService<ILogger<KeyVaultService>>() | |
); | |
"a", | |
sp.GetRequiredService<ILogger<KeyVaultService>>()); |
serviceProvider.GetRequiredService<CertificateProfileClient>(), | ||
accountName, | ||
certificateProfileName, | ||
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serviceProvider.GetRequiredService<CertificateProfileClient>(), | |
accountName, | |
certificateProfileName, | |
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>()); | |
serviceProvider.GetRequiredService<CertificateProfileClient>(), | |
accountName, | |
certificateProfileName, | |
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor feedback. Looks good!
Refactored to use Azure services via DI as that also configures it to work with ILogger.