forked from owenrumney/go-sarif
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start working through new attributes
- start working through new attributes - start thinking about the fluent API for creating the report - reference some of the spec
- Loading branch information
1 parent
fda5757
commit 38b8007
Showing
9 changed files
with
237 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package models | ||
|
||
type artifact struct { // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541049 | ||
Location *artifactLocation `json:"location,omitempty"` | ||
ParentIndex *uint `json:"parentIndex,omitempty"` | ||
Offset *uint `json:"offset,omitempty"` | ||
Length int `json:"length"` | ||
Roles []string `json:"roles,omitempty"` | ||
MimeType *string `json:"mimeType,omitempty"` | ||
Contents *artifactContent `json:"contents,omitempty"` | ||
Encoding *string `json:"encoding,omitempty"` | ||
SourceLanguage *string `json:"sourceLanguage,omitempty"` | ||
Hashes map[string]string `json:"hashes,omitempty"` | ||
LastModifiedTimeUtc *string `json:"lastModifiedTimeUtc,omitempty"` | ||
Description *Message `json:"description,omitempty"` | ||
} | ||
|
||
type artifactLocation struct { // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10540865 | ||
URI *string `json:"uri,omitempty"` | ||
URIBaseId *string `json:"uriBaseId,omitempty"` | ||
Index *uint `json:"index,omitempty"` | ||
Description *Message `json:"description,omitempty"` | ||
} | ||
|
||
type ArtifactLocationBuilder struct { | ||
artifactLocation *artifactLocation | ||
} | ||
|
||
func (alb *ArtifactLocationBuilder) WithUri(uri string) *ArtifactLocationBuilder { | ||
alb.artifactLocation.URI = &uri | ||
return alb | ||
} | ||
|
||
func (alb *ArtifactLocationBuilder) WithIndex(index uint) *ArtifactLocationBuilder { | ||
alb.artifactLocation.Index = &index | ||
return alb | ||
} | ||
|
||
func (alb *ArtifactLocationBuilder) WithUriBaseId(uriBaseId string) *ArtifactLocationBuilder { | ||
alb.artifactLocation.URIBaseId = &uriBaseId | ||
return alb | ||
} | ||
|
||
func (alb *ArtifactLocationBuilder) WithDescription(messageBuilder MessageBuilder) *ArtifactLocationBuilder { | ||
alb.artifactLocation.Description = messageBuilder.Get() | ||
return alb | ||
} | ||
|
||
type artifactContent struct { // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10540860 | ||
Text *string `json:"text,omitempty"` | ||
Binary *string `json:"binary,omitempty"` | ||
Rendered *multiformatMessageString `json:"rendered,omitempty"` | ||
} | ||
|
||
type ArtifactBuilder struct { | ||
run *Run | ||
artifact *artifact | ||
} | ||
|
||
func (run *Run) NewArtifactBuilder() *ArtifactBuilder { | ||
return &ArtifactBuilder{ | ||
run: run, | ||
artifact: &artifact{ | ||
Length: -1, | ||
}, | ||
} | ||
} | ||
|
||
func (ab *ArtifactBuilder) Add() *Run { | ||
ab.run.Artifacts = append(ab.run.Artifacts, ab.artifact) | ||
return ab.run | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package models | ||
|
||
type location struct { | ||
Id *uint `json:"id,omitempty"` | ||
PhysicalLocation *physicalLocation `json:"physicalLocation,omitempty"` | ||
LogicalLocations []*logicalLocation `json:"logicalLocations,omitempty"` | ||
Message *Message `json:"message,omitempty"` | ||
Annotations []*region `json:"annotations,omitempty"` | ||
Relationships []*locationRelationship `json:"relationships,omitempty"` | ||
} | ||
|
||
type physicalLocation struct { | ||
ArtifactLocation *artifactLocation `json:"artifactLocation,omitempty"` | ||
Region *region `json:"region,omitempty"` | ||
ContextRegion *region `json:"contextRegion,omitempty"` | ||
Address *address `json:"address,omitempty"` | ||
} | ||
|
||
type logicalLocation struct { | ||
Index *uint `json:"index,omitempty"` | ||
Name *string `json:"name,omitempty"` | ||
FullyQualifiedName *string `json:"fullyQualifiedName,omitempty"` | ||
DecoratedName *string `json:"decoratedName,omitempty"` | ||
Kind *string `json:"kind,omitempty"` | ||
ParentIndex *uint `json:"parentIndex,omitempty"` | ||
} | ||
|
||
type locationRelationship struct { | ||
Target uint `json:"target"` | ||
Kinds []string `json:"kinds,omitempty"` | ||
Description *Message `json:"description,omitempty"` | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package models | ||
|
||
type MessageBuilder struct { | ||
message *Message | ||
} | ||
|
||
func (m *MessageBuilder) WithText(text string) *MessageBuilder { | ||
m.message.Text = &text | ||
return m | ||
} | ||
|
||
func (m *MessageBuilder) WithMarkdown(markdown string) *MessageBuilder { | ||
m.message.Markdown = &markdown | ||
return m | ||
} | ||
|
||
func (m *MessageBuilder) WithId(id string) *MessageBuilder { | ||
m.message.Id = &id | ||
return m | ||
} | ||
|
||
func (m *MessageBuilder) WithArguments(args []string) *MessageBuilder { | ||
m.message.Arguments = args | ||
return m | ||
} | ||
|
||
func (m *MessageBuilder) Get() *Message { | ||
return m.message | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package models | ||
|
||
type region struct { // https://docs.oasis-open.org/sarif/sarif/v2.1.0/csprd01/sarif-v2.1.0-csprd01.html#_Toc10541123 | ||
StartLine *int `json:"startLine,omitempty"` | ||
StartColumn *int `json:"startColumn,omitempty"` | ||
EndLine *int `json:"endLine,omitempty"` | ||
EndColumn *int `json:"endColumn,omitempty"` | ||
CharOffset *int `json:"charOffset,omitempty"` | ||
CharLength *int `json:"charLength,omitempty"` | ||
ByteOffset *int `json:"byteOffset,omitempty"` | ||
ByteLength *int `json:"byteLength,omitempty"` | ||
Snippet *artifactContent `json:"snippet,omitempty"` | ||
Message *Message `json:"message,omitempty"` | ||
SourceLanguage *string `json:"sourceLanguage,omitempty"` | ||
} | ||
|
||
type RegionBuilder struct { | ||
region *region | ||
} | ||
|
||
func NewRegionBuilder() *RegionBuilder { | ||
return &RegionBuilder{ | ||
region: ®ion{}, | ||
} | ||
} | ||
|
||
func (rb *RegionBuilder) Get() *region { | ||
return rb.region | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.