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 result.rank and ruleConfiguration.defaultRank #1167

Merged
3 commits merged into from
Dec 26, 2018
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
18 changes: 14 additions & 4 deletions src/Sarif/Autogenerated/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public SarifNodeKind SarifNodeKind
[JsonConverter(typeof(EnumConverter))]
public BaselineState BaselineState { get; set; }

/// <summary>
/// A number representing the priority or importance of the result.
/// </summary>
[DataMember(Name = "rank", IsRequired = false, EmitDefaultValue = false)]
public double Rank { get; set; }

/// <summary>
/// A set of files relevant to the result.
/// </summary>
Expand Down Expand Up @@ -237,6 +243,9 @@ public Result()
/// <param name="baselineState">
/// An initialization value for the <see cref="P: BaselineState" /> property.
/// </param>
/// <param name="rank">
/// An initialization value for the <see cref="P: Rank" /> property.
/// </param>
/// <param name="attachments">
/// An initialization value for the <see cref="P: Attachments" /> property.
/// </param>
Expand All @@ -255,9 +264,9 @@ public Result()
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public Result(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
public Result(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, double rank, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(ruleId, level, message, analysisTarget, locations, instanceGuid, correlationGuid, occurrenceCount, partialFingerprints, fingerprints, stacks, codeFlows, graphs, graphTraversals, relatedLocations, suppressionStates, baselineState, attachments, hostedViewerUri, workItemUris, conversionProvenance, fixes, properties);
Init(ruleId, level, message, analysisTarget, locations, instanceGuid, correlationGuid, occurrenceCount, partialFingerprints, fingerprints, stacks, codeFlows, graphs, graphTraversals, relatedLocations, suppressionStates, baselineState, rank, attachments, hostedViewerUri, workItemUris, conversionProvenance, fixes, properties);
}

/// <summary>
Expand All @@ -276,7 +285,7 @@ public Result(Result other)
throw new ArgumentNullException(nameof(other));
}

Init(other.RuleId, other.Level, other.Message, other.AnalysisTarget, other.Locations, other.InstanceGuid, other.CorrelationGuid, other.OccurrenceCount, other.PartialFingerprints, other.Fingerprints, other.Stacks, other.CodeFlows, other.Graphs, other.GraphTraversals, other.RelatedLocations, other.SuppressionStates, other.BaselineState, other.Attachments, other.HostedViewerUri, other.WorkItemUris, other.ConversionProvenance, other.Fixes, other.Properties);
Init(other.RuleId, other.Level, other.Message, other.AnalysisTarget, other.Locations, other.InstanceGuid, other.CorrelationGuid, other.OccurrenceCount, other.PartialFingerprints, other.Fingerprints, other.Stacks, other.CodeFlows, other.Graphs, other.GraphTraversals, other.RelatedLocations, other.SuppressionStates, other.BaselineState, other.Rank, other.Attachments, other.HostedViewerUri, other.WorkItemUris, other.ConversionProvenance, other.Fixes, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
Expand All @@ -297,7 +306,7 @@ private ISarifNode DeepCloneCore()
return new Result(this);
}

private void Init(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
private void Init(string ruleId, ResultLevel level, Message message, FileLocation analysisTarget, IEnumerable<Location> locations, string instanceGuid, string correlationGuid, int occurrenceCount, IDictionary<string, string> partialFingerprints, IDictionary<string, string> fingerprints, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IDictionary<string, Graph> graphs, IEnumerable<GraphTraversal> graphTraversals, IEnumerable<Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, double rank, IEnumerable<Attachment> attachments, Uri hostedViewerUri, IEnumerable<Uri> workItemUris, IEnumerable<PhysicalLocation> conversionProvenance, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties)
{
RuleId = ruleId;
Level = level;
Expand Down Expand Up @@ -425,6 +434,7 @@ private void Init(string ruleId, ResultLevel level, Message message, FileLocatio

SuppressionStates = suppressionStates;
BaselineState = baselineState;
Rank = rank;
if (attachments != null)
{
var destination_5 = new List<Attachment>();
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/Autogenerated/ResultEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public bool Equals(Result left, Result right)
return false;
}

if (left.Rank != right.Rank)
{
return false;
}

if (!object.ReferenceEquals(left.Attachments, right.Attachments))
{
if (left.Attachments == null || right.Attachments == null)
Expand Down Expand Up @@ -520,6 +525,7 @@ public int GetHashCode(Result obj)

result = (result * 31) + obj.SuppressionStates.GetHashCode();
result = (result * 31) + obj.BaselineState.GetHashCode();
result = (result * 31) + obj.Rank.GetHashCode();
if (obj.Attachments != null)
{
foreach (var value_16 in obj.Attachments)
Expand Down
18 changes: 14 additions & 4 deletions src/Sarif/Autogenerated/RuleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public SarifNodeKind SarifNodeKind
[JsonConverter(typeof(EnumConverter))]
public RuleConfigurationDefaultLevel DefaultLevel { get; set; }

/// <summary>
/// Specifies the default priority or importance of the result.
/// </summary>
[DataMember(Name = "defaultRank", IsRequired = false, EmitDefaultValue = false)]
public double DefaultRank { get; set; }

/// <summary>
/// Contains configuration information specific to this rule.
/// </summary>
Expand Down Expand Up @@ -74,15 +80,18 @@ public RuleConfiguration()
/// <param name="defaultLevel">
/// An initialization value for the <see cref="P: DefaultLevel" /> property.
/// </param>
/// <param name="defaultRank">
/// An initialization value for the <see cref="P: DefaultRank" /> property.
/// </param>
/// <param name="parameters">
/// An initialization value for the <see cref="P: Parameters" /> property.
/// </param>
/// <param name="properties">
/// An initialization value for the <see cref="P: Properties" /> property.
/// </param>
public RuleConfiguration(bool enabled, RuleConfigurationDefaultLevel defaultLevel, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
public RuleConfiguration(bool enabled, RuleConfigurationDefaultLevel defaultLevel, double defaultRank, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(enabled, defaultLevel, parameters, properties);
Init(enabled, defaultLevel, defaultRank, parameters, properties);
}

/// <summary>
Expand All @@ -101,7 +110,7 @@ public RuleConfiguration(RuleConfiguration other)
throw new ArgumentNullException(nameof(other));
}

Init(other.Enabled, other.DefaultLevel, other.Parameters, other.Properties);
Init(other.Enabled, other.DefaultLevel, other.DefaultRank, other.Parameters, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
Expand All @@ -122,10 +131,11 @@ private ISarifNode DeepCloneCore()
return new RuleConfiguration(this);
}

private void Init(bool enabled, RuleConfigurationDefaultLevel defaultLevel, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
private void Init(bool enabled, RuleConfigurationDefaultLevel defaultLevel, double defaultRank, IDictionary<string, SerializedPropertyInfo> parameters, IDictionary<string, SerializedPropertyInfo> properties)
{
Enabled = enabled;
DefaultLevel = defaultLevel;
DefaultRank = defaultRank;
if (parameters != null)
{
Parameters = new Dictionary<string, SerializedPropertyInfo>(parameters);
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/Autogenerated/RuleConfigurationEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public bool Equals(RuleConfiguration left, RuleConfiguration right)
return false;
}

if (left.DefaultRank != right.DefaultRank)
{
return false;
}

if (!object.ReferenceEquals(left.Parameters, right.Parameters))
{
if (left.Parameters == null || right.Parameters == null || left.Parameters.Count != right.Parameters.Count)
Expand Down Expand Up @@ -97,6 +102,7 @@ public int GetHashCode(RuleConfiguration obj)
{
result = (result * 31) + obj.Enabled.GetHashCode();
result = (result * 31) + obj.DefaultLevel.GetHashCode();
result = (result * 31) + obj.DefaultRank.GetHashCode();
if (obj.Parameters != null)
{
// Use xor for dictionaries to be order-independent.
Expand Down
6 changes: 6 additions & 0 deletions src/Sarif/NotYetAutoGenerated/ResultEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public bool Equals(Result left, Result right)
return false;
}

if (left.Rank != right.Rank)
{
return false;
}

if (!object.ReferenceEquals(left.Attachments, right.Attachments))
{
if (left.Attachments == null || right.Attachments == null)
Expand Down Expand Up @@ -520,6 +525,7 @@ public int GetHashCode(Result obj)

result = (result * 31) + obj.SuppressionStates.GetHashCode();
result = (result * 31) + obj.BaselineState.GetHashCode();
result = (result * 31) + obj.Rank.GetHashCode();
if (obj.Attachments != null)
{
foreach (var value_16 in obj.Attachments)
Expand Down
17 changes: 16 additions & 1 deletion src/Sarif/Schemata/sarif-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,13 @@
]
},

"rank": {
"description": "A number representing the priority or importance of the result.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or impo [](start = 61, length = 7)

why do you need this? are you comfortable deleting 'or importance'? importance is a slippery slope that pulls in the severity of vulns, the level of exposure, etc. rank is a relative ordering. i think 'priority' sufficiently communicates what we're after.

"type":"number",
"minimum": 0.0,
"maximum": 100.0
},

"attachments": {
"description": "A set of files relevant to the result.",
"type": "array",
Expand Down Expand Up @@ -1438,11 +1445,19 @@
},

"defaultLevel": {
"description": "Specifies the default severity level of the result.",
"description": "Specifies the default severity level for results generated by this rule.",
"default": "warning",
"enum": [ "note", "warning", "error" ]
},

"defaultRank": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultRank [](start = 9, length = 11)

my apologies. I have, yet again, completely misunderstood your proposal in context of the TC. I never thought we were applying a defaultRank to a rule. This doesn't make sense: ranks are generally computed values that are applied to all results. Ranks are generally available or not.

when you discussed a default rank, I thought you are asking 'what is the default value of result.rank' if it isn't explicit? in this case, i have argued that the default s/be 0. so what I expected in this case was that we would not have a new ruleConfiguration property but we would have another explanatory sentence in the spec.

"description": "Specifies the default priority or importance for results generated by this rule.",
"type":"number",
"minimum": 0.0,
"maximum": 100.0,
"default": 0.0
},

"parameters": {
"description": "Contains configuration information specific to this rule.",
"$ref": "#/definitions/propertyBag"
Expand Down