Skip to content

Commit

Permalink
Uuid Changes (#2555)
Browse files Browse the repository at this point in the history
* Updated Json schema to use `uuid`, and updated C# object model to use `Guid?` instead of `string`.

* Add a test

* Update PR number

* Use Nullable.Compare
  • Loading branch information
shaopeng-gh committed Nov 3, 2022
1 parent 1ca20ca commit c0121cb
Show file tree
Hide file tree
Showing 234 changed files with 509 additions and 557 deletions.
2 changes: 2 additions & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SARIF Package Release History (SDK, Driver, Converters, and Multitool)

## **v3.1.0** (UNRELEASED)

* BREAKING: For `Guid` properties defined in SARIF spec, updated Json schema to use `uuid`, and updated C# object model to use `Guid?` instead of `string`. [#2555](https://github.com/microsoft/sarif-sdk/pull/2555)
* FEATURE: Provide mechanism to populate `SarifLogger` with a `FileRegionsCache` instance.
* BUGFIX: Another attempt to resolve 'InvalidOperationException' with message `Collection was modified; enumeration operation may not execute` in `MultithreadedAnalyzeCommandBase`, raised when analyzing with the `--hashes` switch. [#2459](https://github.com/microsoft/sarif-sdk/pull/2549). There was a previous attempt to fix this in [#2447](https://github.com/microsoft/sarif-sdk/pull/2447).
* FEATURE: Allow initialization of file regions cache in `InsertOptionalDataVisitor` (previously initialized exclusively from `FileRegionsCache.Instance`).
Expand Down
10 changes: 5 additions & 5 deletions src/Samples/SarifToCsv/SarifCsvColumnWriters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public static Action<WriteContext> GetWriter(string columnName)

// Result Basic Properties
writers["BaselineState"] = (c) => { c.Writer.Write(c.Result.BaselineState.ToString()); };
writers["CorrelationGuid"] = (c) => { c.Writer.Write(c.Result.CorrelationGuid ?? ""); };
writers["CorrelationGuid"] = (c) => { c.Writer.Write(c.Result.CorrelationGuid?.ToString(SarifConstants.GuidFormat) ?? ""); };
writers["Fingerprints"] = (c) => { c.Writer.Write(String.Join("; ", c.Result.Fingerprints?.Values ?? Array.Empty<string>())); };
writers["HostedViewerUri"] = (c) => { c.Writer.Write(c.Result.HostedViewerUri?.ToString() ?? ""); };
writers["Guid"] = (c) => { c.Writer.Write(c.Result.Guid ?? ""); };
writers["Guid"] = (c) => { c.Writer.Write(c.Result.Guid?.ToString(SarifConstants.GuidFormat) ?? ""); };
writers["Kind"] = (c) => { c.Writer.Write(c.Result.Kind.ToString()); };
writers["Level"] = (c) => { c.Writer.Write(c.Result.Level.ToString()); };
writers["Message.Text"] = (c) => { c.Writer.Write(c.Result.Message?.Text ?? ""); };
Expand Down Expand Up @@ -142,10 +142,10 @@ public static Action<WriteContext> GetWriter(string columnName)
writers["Location.Region.Tags"] = (c) => { c.Writer.Write(String.Join("; ", ((IEnumerable<string>)c.PLoc?.Region?.Tags) ?? Array.Empty<string>())); };

// Run Identity Properties
writers["Run.BaselineGuid"] = (c) => { c.Writer.Write(c.Run?.BaselineGuid ?? ""); };
writers["Run.AutomationDetails.CorrelationGuid"] = (c) => { c.Writer.Write(c.Run?.AutomationDetails?.CorrelationGuid ?? ""); };
writers["Run.BaselineGuid"] = (c) => { c.Writer.Write(c.Run?.BaselineGuid?.ToString(SarifConstants.GuidFormat) ?? ""); };
writers["Run.AutomationDetails.CorrelationGuid"] = (c) => { c.Writer.Write(c.Run?.AutomationDetails?.CorrelationGuid?.ToString(SarifConstants.GuidFormat) ?? ""); };
writers["Run.AutomationDetails.Id"] = (c) => { c.Writer.Write(c.Run?.AutomationDetails?.Id ?? ""); };
writers["Run.AutomationDetails.Guid"] = (c) => { c.Writer.Write(c.Run?.AutomationDetails?.Guid ?? ""); };
writers["Run.AutomationDetails.Guid"] = (c) => { c.Writer.Write(c.Run?.AutomationDetails?.Guid?.ToString(SarifConstants.GuidFormat) ?? ""); };

// Run Basics
writers["Run.Tool.Name"] = (c) => { c.Writer.Write(c.Run?.Tool?.Driver?.Name ?? ""); };
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Converters/FlawFinderConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm
Version = flawFinderCsvResults?.FirstOrDefault()?.ToolVersion,
InformationUri = new Uri(ToolInformationUri),
Rules = rules,
SupportedTaxonomies = new List<ToolComponentReference>() { new ToolComponentReference() { Name = "CWE", Guid = "FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5" } }
SupportedTaxonomies = new List<ToolComponentReference>() { new ToolComponentReference() { Name = "CWE", Guid = Guid.Parse("FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5") } }
}
},
ExternalPropertyFileReferences = new ExternalPropertyFileReferences()
Expand All @@ -61,7 +61,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm
{
Uri = new Uri("https://raw.githubusercontent.com/sarif-standard/taxonomies/main/CWE_v4.4.sarif"),
},
Guid = "FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5"
Guid = Guid.Parse("FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5")
}
}
},
Expand Down Expand Up @@ -131,7 +131,7 @@ private static IList<ReportingDescriptor> ExtractRules(IList<FlawFinderCsvResult
ToolComponent = new ToolComponentReference()
{
Name = "CWE",
Guid = "FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5"
Guid = Guid.Parse("FFC64C90-42B6-44CE-8BEB-F6B7DAE649E5")
}
},
Kinds = new List<string>() { s.EndsWith("!") ? "incomparable" : "relevant" },
Expand Down
10 changes: 7 additions & 3 deletions src/Sarif.Converters/FortifyFprConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class FortifyFprConverter : ToolFileConverterBase
private readonly ToolComponent CweToolComponent = new ToolComponent
{
Name = "CWE",
Guid = "25F72D7E-8A92-459D-AD67-64853F788765",
Guid = Guid.Parse("25F72D7E-8A92-459D-AD67-64853F788765"),
Organization = "MITRE",
ShortDescription = new MultiformatMessageString
{
Expand Down Expand Up @@ -184,11 +184,13 @@ private string ExtractFvdl(XmlReader reader)

private Run CreateSarifRun()
{
bool isIdGuid = Guid.TryParse(_runId, out Guid idGuid);

var run = new Run()
{
AutomationDetails = new RunAutomationDetails
{
Guid = _runId,
Guid = isIdGuid ? idGuid : (Guid?)null,
Id = _automationId + "/"
},
Artifacts = _files.OrderBy(d => d.Value.Item2)
Expand Down Expand Up @@ -1266,10 +1268,12 @@ private ReportingDescriptor FindOrCreateRule(string ruleGuid, out int ruleIndex)
}
else
{
bool isGuid = Guid.TryParse(NormalizeGuid(ruleGuid), out Guid parsedGuid);

ReportingDescriptor rule = new ReportingDescriptor
{
Id = ruleGuid,
Guid = NormalizeGuid(ruleGuid)
Guid = isGuid ? parsedGuid : (Guid?)null
};

rule.DefaultConfiguration = new ReportingConfiguration();
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Converters/HdfConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm
Version = hdfFile.Version,
InformationUri = new Uri(ToolInformationUri),
Rules = rulesAndResults.Item1,
SupportedTaxonomies = new List<ToolComponentReference>() { new ToolComponentReference() { Name = "NIST SP800-53 v5", Guid = "AAFBAB93-5201-419E-8443-D4925C542398" } }
SupportedTaxonomies = new List<ToolComponentReference>() { new ToolComponentReference() { Name = "NIST SP800-53 v5", Guid = Guid.Parse("AAFBAB93-5201-419E-8443-D4925C542398") } }
}
},
ExternalPropertyFileReferences = new ExternalPropertyFileReferences()
Expand All @@ -54,7 +54,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm
{
Uri = new Uri("https://raw.githubusercontent.com/sarif-standard/taxonomies/main/NIST_SP800-53_v5.sarif"),
},
Guid = "AAFBAB93-5201-419E-8443-D4925C542398"
Guid = Guid.Parse("AAFBAB93-5201-419E-8443-D4925C542398")
}
}
},
Expand Down Expand Up @@ -111,7 +111,7 @@ private static (ReportingDescriptor, IList<Result>) SarifRuleAndResultFromHdfCon
ToolComponent = new ToolComponentReference()
{
Name = "NIST",
Guid = "AAFBAB93-5201-419E-8443-D4925C542398"
Guid = Guid.Parse("AAFBAB93-5201-419E-8443-D4925C542398")
}
},
Kinds = new List<string>() { "relevant" },
Expand Down
3 changes: 2 additions & 1 deletion src/Sarif.Driver/Sdk/CommonOptionsBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;

using CommandLine;
Expand Down Expand Up @@ -100,7 +101,7 @@ public class CommonOptionsBase
[Option(
"automationGuid",
HelpText = "A guid that will be persisted to the 'Run.AutomationDetails.Guid' property. See section '3.17.4' of the SARIF specification for more information.")]
public string AutomationGuid { get; set; }
public Guid? AutomationGuid { get; set; }

public Formatting Formatting => this.PrettyPrint || (!this.PrettyPrint && !this.Minify)
? Formatting.Indented
Expand Down
4 changes: 2 additions & 2 deletions src/Sarif.Multitool.Library/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.CodeAnalysis.Sarif.Multitool
{
public static class Extensions
{
public static bool RefersToDriver(this ToolComponentReference toolComponent, string driverGuid)
public static bool RefersToDriver(this ToolComponentReference toolComponent, Guid? driverGuid)
{
if (toolComponent.Index == -1)
{
Expand All @@ -17,7 +17,7 @@ public static bool RefersToDriver(this ToolComponentReference toolComponent, str
}
else
{
return toolComponent.Guid.Equals(driverGuid, StringComparison.OrdinalIgnoreCase);
return toolComponent.Guid == driverGuid;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class OptimizeFileSize : SarifValidationSkimmerBase
nameof(RuleResources.SARIF2004_OptimizeFileSize_Warning_PreferRuleId_Text)
};

private string driverGuid;
private Guid? driverGuid;

protected override void Analyze(Run run, string runPointer)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Sarif.Multitool.Library/Sarif.Multitool.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Kusto.Data" Version="10.0.3" />
<PackageReference Include="Microsoft.Json.Pointer" Version="1.1.4" />
<PackageReference Include="Microsoft.Json.Schema" Version="1.1.4" />
<PackageReference Include="Microsoft.Json.Schema.Validation" Version="1.1.4" />
<PackageReference Include="Microsoft.Json.Pointer" Version="2.1.0" />
<PackageReference Include="Microsoft.Json.Schema" Version="2.1.0" />
<PackageReference Include="Microsoft.Json.Schema.Validation" Version="2.1.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Threading.Channels" Version="5.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// A physical or virtual address, or a range of addresses, in an 'addressable region' (memory or a binary file).
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
public partial class Address : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<Address> ValueComparer => AddressEqualityComparer.Instance;
Expand Down
31 changes: 5 additions & 26 deletions src/Sarif/Autogenerated/AddressComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type Address for sorting.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class AddressComparer : IComparer<Address>
{
internal static readonly AddressComparer Instance = new AddressComparer();
Expand All @@ -32,27 +32,13 @@ public int Compare(Address left, Address right)
return compareResult;
}

// TryReferenceCompares is an autogenerated extension method
// that will properly handle the case when 'left' is null.
if (left.RelativeAddress.TryReferenceCompares(right.RelativeAddress, out compareResult))
{
return compareResult;
}

compareResult = left.RelativeAddress.Value.CompareTo(right.RelativeAddress.Value);
compareResult = left.RelativeAddress.CompareTo(right.RelativeAddress);
if (compareResult != 0)
{
return compareResult;
}

// TryReferenceCompares is an autogenerated extension method
// that will properly handle the case when 'left' is null.
if (left.Length.TryReferenceCompares(right.Length, out compareResult))
{
return compareResult;
}

compareResult = left.Length.Value.CompareTo(right.Length.Value);
compareResult = left.Length.CompareTo(right.Length);
if (compareResult != 0)
{
return compareResult;
Expand All @@ -76,14 +62,7 @@ public int Compare(Address left, Address right)
return compareResult;
}

// TryReferenceCompares is an autogenerated extension method
// that will properly handle the case when 'left' is null.
if (left.OffsetFromParent.TryReferenceCompares(right.OffsetFromParent, out compareResult))
{
return compareResult;
}

compareResult = left.OffsetFromParent.Value.CompareTo(right.OffsetFromParent.Value);
compareResult = left.OffsetFromParent.CompareTo(right.OffsetFromParent);
if (compareResult != 0)
{
return compareResult;
Expand All @@ -110,4 +89,4 @@ public int Compare(Address left, Address right)
return compareResult;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/AddressEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type Address for equality.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class AddressEqualityComparer : IEqualityComparer<Address>
{
internal static readonly AddressEqualityComparer Instance = new AddressEqualityComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/Artifact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// A single artifact. In some cases, this artifact might be nested within another artifact.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
public partial class Artifact : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<Artifact> ValueComparer => ArtifactEqualityComparer.Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// A change to a single artifact.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
public partial class ArtifactChange : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<ArtifactChange> ValueComparer => ArtifactChangeEqualityComparer.Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactChangeComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type ArtifactChange for sorting.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactChangeComparer : IComparer<ArtifactChange>
{
internal static readonly ArtifactChangeComparer Instance = new ArtifactChangeComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactChangeEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type ArtifactChange for equality.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactChangeEqualityComparer : IEqualityComparer<ArtifactChange>
{
internal static readonly ArtifactChangeEqualityComparer Instance = new ArtifactChangeEqualityComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type Artifact for sorting.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactComparer : IComparer<Artifact>
{
internal static readonly ArtifactComparer Instance = new ArtifactComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// Represents the contents of an artifact.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
public partial class ArtifactContent : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<ArtifactContent> ValueComparer => ArtifactContentEqualityComparer.Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactContentComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type ArtifactContent for sorting.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactContentComparer : IComparer<ArtifactContent>
{
internal static readonly ArtifactContentComparer Instance = new ArtifactContentComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactContentEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type ArtifactContent for equality.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactContentEqualityComparer : IEqualityComparer<ArtifactContent>
{
internal static readonly ArtifactContentEqualityComparer Instance = new ArtifactContentEqualityComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// <summary>
/// Defines methods to support the comparison of objects of type Artifact for equality.
/// </summary>
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
internal sealed class ArtifactEqualityComparer : IEqualityComparer<Artifact>
{
internal static readonly ArtifactEqualityComparer Instance = new ArtifactEqualityComparer();
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/ArtifactLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Sarif
/// Specifies the location of an artifact.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.5.0")]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "2.1.0.0")]
public partial class ArtifactLocation : PropertyBagHolder, ISarifNode
{
public static IEqualityComparer<ArtifactLocation> ValueComparer => ArtifactLocationEqualityComparer.Instance;
Expand Down
Loading

0 comments on commit c0121cb

Please sign in to comment.