From d9d637923f43d0a03a43bd21502fb0210d147b08 Mon Sep 17 00:00:00 2001 From: Ruben Guerrero Date: Tue, 11 Apr 2023 15:32:08 -0700 Subject: [PATCH] Add isPublic to IConfigurationUnitProcessorDetails (#3145) Add a new property IsPublic to IConfigurationUnitProcessorDetails. Set it to true if the repository source location is one of the public repositories. For now, it's only the PSGallery source. --- src/AppInstallerCLITests/TestConfiguration.h | 3 +++ .../Unit/ConfigurationUnitProcessorDetails.cs | 21 +++++++++++++++++++ .../TestConfigurationUnitProcessorDetails.cs | 2 ++ .../Tests/ConfigurationDetailsTests.cs | 6 ++++-- .../Microsoft.Management.Configuration.idl | 3 +++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLITests/TestConfiguration.h b/src/AppInstallerCLITests/TestConfiguration.h index 8193f0a919..0d18770f54 100644 --- a/src/AppInstallerCLITests/TestConfiguration.h +++ b/src/AppInstallerCLITests/TestConfiguration.h @@ -98,6 +98,9 @@ namespace TestCommon winrt::Windows::Foundation::Collections::IVector SettingsValue; winrt::Windows::Foundation::Collections::IVectorView Settings() const { return (SettingsValue ? SettingsValue.GetView() : nullptr); } + + bool IsPublicValue; + bool IsPublic() const { return IsPublicValue; } }; struct TestConfigurationUnitProcessor : winrt::implements diff --git a/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs b/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs index 8f759a3c9e..78acbdfdbb 100644 --- a/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs +++ b/src/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs @@ -8,6 +8,7 @@ namespace Microsoft.Management.Configuration.Processor.Unit { using System; using System.Collections.Generic; + using System.Linq; using System.Management.Automation; using System.Reflection; using Microsoft.Management.Configuration; @@ -19,6 +20,11 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// internal sealed class ConfigurationUnitProcessorDetails : IConfigurationUnitProcessorDetails { + private static readonly IEnumerable PublicRepositories = new string[] + { + "https://www.powershellgallery.com/api/v2", + }; + /// /// Initializes a new instance of the class. /// @@ -80,6 +86,16 @@ internal sealed class ConfigurationUnitProcessorDetails : IConfigurationUnitProc this.TrySetPropertyAsString(getModuleInfo, "Repository", nameof(this.ModuleSource)); this.TrySetPropertyFromDateTimeToDateTimeOffset(getModuleInfo, "PublishedDate", nameof(this.PublishedDate)); + var repoSourceLocation = getModuleInfo.Properties["RepositorySourceLocation"]; + if (repoSourceLocation is not null) + { + string? repoSourceLocationValue = repoSourceLocation.Value as string; + if (repoSourceLocationValue is not null) + { + this.IsPublic = PublicRepositories.Any(r => r == repoSourceLocationValue); + } + } + if (psModuleInfo is null) { // Type is not the same as this PSModuleType. @@ -180,6 +196,11 @@ internal sealed class ConfigurationUnitProcessorDetails : IConfigurationUnitProc /// public IReadOnlyList? Settings { get; } + /// + /// Gets a value indicating whether the module comes from a public repository. + /// + public bool IsPublic { get; private set; } + private void TrySetPropertyAsString(PSObject getModuleInfo, string getModuleInfoProperty, string propertyName) { Type meType = typeof(ConfigurationUnitProcessorDetails); diff --git a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs index 554dcb8960..aaff5b5875 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs @@ -63,6 +63,8 @@ internal TestConfigurationUnitProcessorDetails(ConfigurationUnit unit, Configura public string? UnitName { get; internal set; } public string? Version { get; internal set; } + + public bool IsPublic { get; internal set; } #pragma warning restore SA1600 // Elements should be documented } } diff --git a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs index 7d6c648e56..25b674e2ca 100644 --- a/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs +++ b/src/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs @@ -14,7 +14,6 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests using Microsoft.Management.Configuration.Processor.Helpers; using Microsoft.Management.Configuration.Processor.Unit; using Microsoft.Management.Configuration.UnitTests.Fixtures; - using Microsoft.Management.Configuration.UnitTests.Helpers; using Windows.Security.Cryptography.Certificates; using Xunit; using Xunit.Abstractions; @@ -31,6 +30,8 @@ public class ConfigurationDetailsTests /// /// Initializes a new instance of the class. /// + /// Fixture. + /// log. public ConfigurationDetailsTests(UnitTestFixture fixture, ITestOutputHelper log) { this.fixture = fixture; @@ -163,6 +164,7 @@ public void ConfigurationUnitProcessorDetails_CreationTest(bool hasDscInfo, bool Assert.Equal("0.0.0.1", details.Version); Assert.Equal("Luffytaro", details.Author); Assert.Equal("Microsoft Corporation", details.Publisher); + Assert.True(details.IsPublic); } if (hasCerts) @@ -207,7 +209,7 @@ private PSObject CreateGetModuleInfo() IconUri = "https://www.contoso.com/icons/icon.png", Name = "xSimpleTestResource", Description = "PowerShell module with DSC resources for unit tests", - RepositorySourceLocation = "https://github.com/microsoft/winget-cli", + RepositorySourceLocation = "https://www.powershellgallery.com/api/v2", Version = "0.0.0.1", Author = "Luffytaro", CompanyName = "Microsoft Corporation", diff --git a/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl b/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl index f0958d3467..26fba940c1 100644 --- a/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl +++ b/src/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl @@ -122,6 +122,9 @@ namespace Microsoft.Management.Configuration Windows.Foundation.Collections.IVectorView SigningInformation{ get; }; // The settings information for the unit of configuration. Windows.Foundation.Collections.IVectorView Settings{ get; }; + // Does it comes from a public repository + Boolean IsPublic{ get; }; + } // Defines how the configuration unit is to be used within the configuration system.