Skip to content

Commit

Permalink
Add isPublic to IConfigurationUnitProcessorDetails (#3145)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msftrubengu committed Apr 11, 2023
1 parent 6f0bf7b commit d9d6379
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/TestConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -180,6 +196,11 @@ internal sealed class ConfigurationUnitProcessorDetails : IConfigurationUnitProc
/// </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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +30,8 @@ public class ConfigurationDetailsTests
/// <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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d9d6379

Please sign in to comment.