Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Add logging through to Azure services #808

wants to merge 17 commits into from

Conversation

clairernovotny
Copy link
Member

Refactored to use Azure services via DI as that also configures it to work with ILogger.

- 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.
- 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
@clairernovotny clairernovotny marked this pull request as ready for review December 13, 2024 17:06
@clairernovotny clairernovotny requested a review from a team as a code owner December 13, 2024 17:06

namespace Sign.Core
{
internal class SigningException : Exception
Copy link
Collaborator

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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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()
Copy link
Collaborator

@dtivel dtivel Jan 6, 2025

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>

Suggested change
public void AddServices_AddedServicesAreAdded()
public void AddServices_Always_AddedServicesAreAdded()

}

[Fact]
public void AddServices_AddedIfAddedServicesAreAlsoPresent()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void AddServices_AddedIfAddedServicesAreAlsoPresent()
public void AddServices_WhenAddedServicesAreAlreadyPresent_ServicesAdded()

}

[Fact]
public void Create_NoAddedServices()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
Copy link
Collaborator

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void Constructor_WhenTokenCredentialIsNull_Throws()
public void Constructor_WhenCertificateProfileClientIsNull_Throws()

@@ -102,16 +65,9 @@ public void GetCertificateProvider_WhenServiceProviderIsNull_Throws()
[Fact]
public void GetCertificateProvider_ReturnsSameInstance()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void GetCertificateProvider_ReturnsSameInstance()
public void GetCertificateProvider_Always_ReturnsSameInstance()

@@ -76,22 +46,15 @@ public void GetSignatureAlgorithmProvider_WhenServiceProviderIsNull_Throws()
[Fact]
public void GetSignatureAlgorithmProvider_ReturnsSameInstance()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void GetSignatureAlgorithmProvider_ReturnsSameInstance()
public void GetSignatureAlgorithmProvider_Always_ReturnsSameInstance()

Comment on lines +29 to +30
"a", sp.GetRequiredService<ILogger<KeyVaultService>>()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"a", sp.GetRequiredService<ILogger<KeyVaultService>>()
);
"a",
sp.GetRequiredService<ILogger<KeyVaultService>>());

Comment on lines +83 to +86
serviceProvider.GetRequiredService<CertificateProfileClient>(),
accountName,
certificateProfileName,
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
serviceProvider.GetRequiredService<CertificateProfileClient>(),
accountName,
certificateProfileName,
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>());
serviceProvider.GetRequiredService<CertificateProfileClient>(),
accountName,
certificateProfileName,
serviceProvider.GetRequiredService<ILogger<TrustedSigningService>>());

Copy link
Collaborator

@dtivel dtivel left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants