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 isPublic to IConfigurationUnitProcessorDetails #3145

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ psModuleInfo is null &&
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 @@ psModuleInfo is null &&
/// </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