winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d9d637923f43d0a03a43bd21502fb0210d147b08
parent 6f0bf7b624769768093504b00591e7e2d6b378a3
Author: Ruben Guerrero <rubengu@microsoft.com>
Date:   Tue, 11 Apr 2023 15:32:08 -0700

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.
Diffstat:
Msrc/AppInstallerCLITests/TestConfiguration.h | 3+++
Msrc/Microsoft.Management.Configuration.Processor/Unit/ConfigurationUnitProcessorDetails.cs | 21+++++++++++++++++++++
Msrc/Microsoft.Management.Configuration.UnitTests/Helpers/TestConfigurationUnitProcessorDetails.cs | 2++
Msrc/Microsoft.Management.Configuration.UnitTests/Tests/ConfigurationDetailsTests.cs | 6++++--
Msrc/Microsoft.Management.Configuration/Microsoft.Management.Configuration.idl | 3+++
5 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/AppInstallerCLITests/TestConfiguration.h b/src/AppInstallerCLITests/TestConfiguration.h @@ -98,6 +98,9 @@ namespace TestCommon winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::Management::Configuration::IConfigurationUnitSettingDetails> SettingsValue; winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Configuration::IConfigurationUnitSettingDetails> Settings() const { return (SettingsValue ? SettingsValue.GetView() : nullptr); } + + bool IsPublicValue; + bool IsPublic() const { return IsPublicValue; } }; struct TestConfigurationUnitProcessor : winrt::implements<TestConfigurationUnitProcessor, winrt::Microsoft::Management::Configuration::IConfigurationUnitProcessor> diff --git 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 /// </summary> internal sealed class ConfigurationUnitProcessorDetails : IConfigurationUnitProcessorDetails { + private static readonly IEnumerable<string> PublicRepositories = new string[] + { + "https://www.powershellgallery.com/api/v2", + }; + /// <summary> /// Initializes a new instance of the <see cref="ConfigurationUnitProcessorDetails"/> class. /// </summary> @@ -80,6 +86,16 @@ namespace Microsoft.Management.Configuration.Processor.Unit 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 @@ namespace Microsoft.Management.Configuration.Processor.Unit /// </summary> public IReadOnlyList<IConfigurationUnitSettingDetails>? Settings { get; } + /// <summary> + /// Gets a value indicating whether the module comes from a public repository. + /// </summary> + 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 @@ -63,6 +63,8 @@ namespace Microsoft.Management.Configuration.UnitTests.Helpers 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 @@ -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 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests /// <summary> /// Initializes a new instance of the <see cref="ConfigurationDetailsTests"/> class. /// </summary> + /// <param name="fixture">Fixture.</param> + /// <param name="log">log.</param> public ConfigurationDetailsTests(UnitTestFixture fixture, ITestOutputHelper log) { this.fixture = fixture; @@ -163,6 +164,7 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests 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 @@ namespace Microsoft.Management.Configuration.UnitTests.Tests 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 @@ -122,6 +122,9 @@ namespace Microsoft.Management.Configuration Windows.Foundation.Collections.IVectorView<IInspectable> SigningInformation{ get; }; // The settings information for the unit of configuration. Windows.Foundation.Collections.IVectorView<IConfigurationUnitSettingDetails> 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.