Skip to content

Commit

Permalink
additional-fields to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsandeep committed Sep 16, 2021
1 parent 19e0f39 commit bfb0a99
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
6 changes: 3 additions & 3 deletions SYNTAX-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,20 @@ Valid values:

<div class="dd">

<code>additional-fields</code> <i>map[string]string</i>
<code>metadata</code> <i>map[string]string</i>

</div>
<div class="dt">

AdditionalFields regarding metadata of the template.
Metadata regarding metadata of the template.



Examples:


```yaml
additional-fields:
metadata:
customField1: customValue1
```

Expand Down
2 changes: 1 addition & 1 deletion nuclei-jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/severity.Holder"
},
"additional-fields": {
"metadata": {
"patternProperties": {
".*": {
"type": "string"
Expand Down
1 change: 0 additions & 1 deletion v2/cmd/cve-annotate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func getCVEData(client *nvd.Client, filePath, data string) {
newInfoBlock = strings.ReplaceAll(newInfoBlock, severityMatches[0][0], "severity: "+newSeverity)
fmt.Printf("Adjusting severity for %s from %s=>%s (%.2f)\n", filePath, severityValue, newSeverity, cvssScore)
}
// Start with additional-fields as that is the one most likely to break stuff.
if !strings.Contains(infoBlockClean, "classification") && (cvssScore != 0 && cvssMetrics != "") {
changed = true
newInfoBlock = newInfoBlock + fmt.Sprintf("\n classification:\n cvss-metrics: %s\n cvss-score: %.2f\n cve-id: %s", cvssMetrics, cvssScore, cveName)
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ type Info struct {
// - critical
SeverityHolder severity.Holder `json:"severity,omitempty" yaml:"severity,omitempty"`
// description: |
// AdditionalFields regarding metadata of the template.
// Metadata of the template.
//
// examples:
// - value: >
// map[string]string{"customField1":"customValue1"}
AdditionalFields map[string]string `json:"additional-fields,omitempty" yaml:"additional-fields,omitempty" jsonschema:"title=additional metadata for the template,description=Additional metadata fields for the template"`
Metadata map[string]string `json:"metadata,omitempty" yaml:"metadata,omitempty" jsonschema:"title=additional metadata for the template,description=Additional metadata fields for the template"`

// description: |
// Classification contains classification information about the template.
Expand Down
6 changes: 3 additions & 3 deletions v2/pkg/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestUnmarshal(t *testing.T) {
assert.Equal(t, info.Tags.ToSlice(), tags)
assert.Equal(t, info.SeverityHolder.Severity, severity.Critical)
assert.Equal(t, info.Reference.ToSlice(), references)
assert.Equal(t, info.AdditionalFields, dynamicKeysMap)
assert.Equal(t, info.Metadata, dynamicKeysMap)
return info
}

Expand All @@ -90,7 +90,7 @@ func TestUnmarshal(t *testing.T) {
tags: ` + strings.Join(tags, ", ") + `
severity: critical
reference: ` + strings.Join(references, ", ") + `
additional-fields:
metadata:
` + dynamicKey1 + `: ` + dynamicKeysMap[dynamicKey1] + `
` + dynamicKey2 + `: ` + dynamicKeysMap[dynamicKey2] + `
`
Expand All @@ -106,7 +106,7 @@ func TestUnmarshal(t *testing.T) {
reference:
- ` + references[0] + ` # comments are not unmarshalled
- ` + references[1] + `
additional-fields:
metadata:
` + dynamicKey1 + `: ` + dynamicKeysMap[dynamicKey1] + `
` + dynamicKey2 + `: ` + dynamicKeysMap[dynamicKey2] + `
`
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/reporting/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func ToMarkdownTableString(templateInfo *model.Info) string {
}

toMarkDownTable(fields)
toMarkDownTable(utils.NewInsertionOrderedStringMap(templateInfo.AdditionalFields))
toMarkDownTable(utils.NewInsertionOrderedStringMap(templateInfo.Metadata))

return builder.String()
}
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/reporting/format/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestToMarkdownTableString(t *testing.T) {
SeverityHolder: severity.Holder{Severity: severity.High},
Tags: stringslice.StringSlice{Value: []string{"cve", "misc"}},
Reference: stringslice.StringSlice{Value: "reference1"},
AdditionalFields: map[string]string{
Metadata: map[string]string{
"customDynamicKey1": "customDynamicValue1",
"customDynamicKey2": "customDynamicValue2",
},
Expand Down
6 changes: 3 additions & 3 deletions v2/pkg/templates/templates_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ func init() {
"high",
"critical",
}
MODELInfoDoc.Fields[6].Name = "additional-fields"
MODELInfoDoc.Fields[6].Name = "metadata"
MODELInfoDoc.Fields[6].Type = "map[string]string"
MODELInfoDoc.Fields[6].Note = ""
MODELInfoDoc.Fields[6].Description = "AdditionalFields regarding metadata of the template."
MODELInfoDoc.Fields[6].Comments[encoder.LineComment] = "AdditionalFields regarding metadata of the template."
MODELInfoDoc.Fields[6].Description = "Metadata of the template."
MODELInfoDoc.Fields[6].Comments[encoder.LineComment] = "Metadata of the template."

MODELInfoDoc.Fields[6].AddExample("", map[string]string{"customField1": "customValue1"})
MODELInfoDoc.Fields[7].Name = "classification"
Expand Down

0 comments on commit bfb0a99

Please sign in to comment.