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

Enable auditing of nuget packages #414

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<PropertyGroup>
<LangVersion>12.0</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<WarningsAsErrors>NU1901;NU1902;NU1903;NU1904</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<NuGetAudit>true</NuGetAudit>
<NuGetAuditMode>all</NuGetAuditMode>
<NuGetAuditLevel>low</NuGetAuditLevel>
</PropertyGroup>

<PropertyGroup>
Expand Down
16 changes: 11 additions & 5 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<AvaloniaVersion>11.1.1</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
Expand All @@ -24,9 +25,14 @@
<PackageVersion Include="SharpCompress" Version="0.37.2" />
<PackageVersion Include="System.CodeDom" Version="8.0.0" />
<PackageVersion Include="System.Security.Permissions" Version="8.0.0" />
<PackageVersion Include="xunit" Version="2.8.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.0" />
<PackageVersion Include="XunitXml.TestLogger" Version="3.1.20" />
<PackageVersion Include="YamlDotNet" Version="15.3.0" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="XunitXml.TestLogger" Version="4.0.254" />
<PackageVersion Include="YamlDotNet" Version="16.0.0" />
<!-- Transitive dependencies -->
<PackageVersion Include="System.Formats.Asn1" Version="[8.0.1,)" />
</ItemGroup>
</Project>
</Project>
20 changes: 11 additions & 9 deletions src/Snap/Core/Yaml/TypeConverters/OsPlatformYamlTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
Expand All @@ -8,24 +8,26 @@ namespace Snap.Core.Yaml.TypeConverters;

internal sealed class OsPlatformYamlTypeConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
return type == typeof(OSPlatform);
}
public bool Accepts(Type type) => type == typeof(OSPlatform);

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var osPlatform = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
return TryCreateOsPlatform(osPlatform);
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var osPlatformStr = ((OSPlatform)value).ToString().ToLowerInvariant();
if (value is not OSPlatform osPlatform)
{
throw new ArgumentException("Value is not an OSPlatform", nameof(value));
}

var osPlatformStr = osPlatform.ToString().ToLowerInvariant();
emitter.Emit(new Scalar(osPlatformStr));
}

static OSPlatform TryCreateOsPlatform(string osPlatform)
{
if (string.IsNullOrWhiteSpace(osPlatform))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using NuGet.Versioning;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
Expand All @@ -13,15 +13,15 @@ public bool Accepts(Type type)
return type == typeof(SemanticVersion);
}

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var semanticVersionStr = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
SemanticVersion.TryParse(semanticVersionStr, out var semanticVersion);
return semanticVersion;
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var semanticVersionStr = ((SemanticVersion)value)?.ToNormalizedString() ?? string.Empty;
emitter.Emit(new Scalar(semanticVersionStr));
Expand Down
6 changes: 3 additions & 3 deletions src/Snap/Core/Yaml/TypeConverters/UriYamlTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
Expand All @@ -12,15 +12,15 @@ public bool Accepts(Type type)
return type == typeof(Uri);
}

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var uriStr = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
Uri.TryCreate(uriStr, UriKind.Absolute, out var uri);
return uri;
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var uriStr = ((Uri)value)?.ToString() ?? string.Empty;
emitter.Emit(new Scalar(uriStr));
Expand Down
Loading