| 1 | package sarif |
| 2 | |
| 3 | // Result represents the results block in the sarif report |
| 4 | type Result struct { |
| 5 | PropertyBag |
| 6 | Guid *string `json:"guid,omitempty"` |
| 7 | CorrelationGuid *string `json:"correlationGuid,omitempty"` |
| 8 | RuleID *string `json:"ruleId,omitempty"` |
| 9 | RuleIndex *uint `json:"ruleIndex,omitempty"` |
| 10 | Rule *ReportingDescriptorReference `json:"rule,omitempty"` |
| 11 | Taxa []*ReportingDescriptorReference `json:"taxa,omitempty"` |
| 12 | Kind *string `json:"kind,omitempty"` |
| 13 | Level *string `json:"level,omitempty"` |
| 14 | Message Message `json:"message"` |
| 15 | Locations []*Location `json:"locations,omitempty"` |
| 16 | AnalysisTarget *ArtifactLocation `json:"analysisTarget,omitempty"` |
| 17 | // WebRequest *webRequest `json:"webRequest,omitempty"` |
| 18 | // WebResponse *webResponse `json:"webResponse,omitempty"` |
| 19 | Fingerprints map[string]interface{} `json:"fingerprints,omitempty"` |
| 20 | PartialFingerprints map[string]interface{} `json:"partialFingerprints,omitempty"` |
| 21 | // CodeFlows []*codeFlows `json:"codeFlows,omitempty"` |
| 22 | // Graphs []*graphs `json:"graphs,omitempty"` |
| 23 | // GraphTraversals []*graphTraversals `json:"graphTraversals,omitempty"` |
| 24 | // Stacks []*stack `json:"stacks,omitempty"` |
| 25 | RelatedLocations []*Location `json:"relatedLocations,omitempty"` |
| 26 | Suppressions []*Suppression `json:"suppressions,omitempty"` |
| 27 | BaselineState *string `json:"baselineState,omitempty"` |
| 28 | Rank *float32 `json:"rank,omitempty"` |
| 29 | // Attachments []*attachment `json:"attachments,omitempty"` |
| 30 | WorkItemUris []string `json:"workItemUris,omitempty"` // can be null |
| 31 | HostedViewerUri *string `json:"hostedViewerUri,omitempty"` |
| 32 | // Provenance *resultProvenance `json:"provenance,omitempty"` |
| 33 | Fixes []*Fix `json:"fixes,omitempty"` |
| 34 | OccurrenceCount *uint `json:"occurrenceCount,omitempty"` |
| 35 | Properties Properties `json:"properties,omitempty"` |
| 36 | } |
| 37 | |
| 38 | func newRuleResult(ruleID string) *Result { |
| 39 | return &Result{ |
| 40 | RuleID: &ruleID, |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // WithGuid ... |
| 45 | func (r *Result) WithGuid(guid string) *Result { |
| 46 | r.Guid = &guid |
| 47 | return r |
| 48 | } |
| 49 | |
| 50 | // WithCorrelationGuid ... |
| 51 | func (r *Result) WithCorrelationGuid(correlationGuid string) *Result { |
| 52 | r.CorrelationGuid = &correlationGuid |
| 53 | return r |
| 54 | } |
| 55 | |
| 56 | // WithRuleIndex ... |
| 57 | func (r *Result) WithRuleIndex(ruleIndex int) *Result { |
| 58 | index := uint(ruleIndex) |
| 59 | r.RuleIndex = &index |
| 60 | return r |
| 61 | } |
| 62 | |
| 63 | // WithRule ... |
| 64 | func (r *Result) WithRule(rdp *ReportingDescriptorReference) *Result { |
| 65 | r.Rule = rdp |
| 66 | return r |
| 67 | } |
| 68 | |
| 69 | // WithTaxa ... |
| 70 | func (r *Result) WithTaxa(rdp *ReportingDescriptorReference) *Result { |
| 71 | r.Taxa = append(r.Taxa, rdp) |
| 72 | return r |
| 73 | } |
| 74 | |
| 75 | // WithKind ... |
| 76 | func (r *Result) WithKind(kind string) *Result { |
| 77 | r.Kind = &kind |
| 78 | return r |
| 79 | } |
| 80 | |
| 81 | // WithLevel ... |
| 82 | func (r *Result) WithLevel(level string) *Result { |
| 83 | r.Level = &level |
| 84 | return r |
| 85 | } |
| 86 | |
| 87 | // WithMessage ... |
| 88 | func (r *Result) WithMessage(message *Message) *Result { |
| 89 | r.Message = *message |
| 90 | return r |
| 91 | } |
| 92 | |
| 93 | // WithLocation ... |
| 94 | func (r *Result) WithLocation(location *Location) *Result { |
| 95 | r.Locations = append(r.Locations, location) |
| 96 | return r |
| 97 | } |
| 98 | |
| 99 | // WithAnalysisTarget ... |
| 100 | func (r *Result) WithAnalysisTarget(target *ArtifactLocation) *Result { |
| 101 | r.AnalysisTarget = target |
| 102 | return r |
| 103 | } |
| 104 | |
| 105 | // WithFingerPrints ... |
| 106 | func (r *Result) WithFingerPrints(fingerPrints map[string]interface{}) *Result { |
| 107 | r.Fingerprints = fingerPrints |
| 108 | return r |
| 109 | } |
| 110 | |
| 111 | // WithPartialFingerPrints ... |
| 112 | func (r *Result) WithPartialFingerPrints(fingerPrints map[string]interface{}) *Result { |
| 113 | r.PartialFingerprints = fingerPrints |
| 114 | return r |
| 115 | } |
| 116 | |
| 117 | // WithRelatedLocation ... |
| 118 | func (r *Result) WithRelatedLocation(location *Location) *Result { |
| 119 | r.RelatedLocations = append(r.RelatedLocations, location) |
| 120 | return r |
| 121 | } |
| 122 | |
| 123 | // WithSuppression ... |
| 124 | func (r *Result) WithSuppression(suppression *Suppression) *Result { |
| 125 | r.Suppressions = append(r.Suppressions, suppression) |
| 126 | return r |
| 127 | } |
| 128 | |
| 129 | // WithBaselineState ... |
| 130 | func (r *Result) WithBaselineState(state string) *Result { |
| 131 | r.BaselineState = &state |
| 132 | return r |
| 133 | } |
| 134 | |
| 135 | // WithRank ... |
| 136 | func (r *Result) WithRank(rank float32) *Result { |
| 137 | r.Rank = &rank |
| 138 | return r |
| 139 | } |
| 140 | |
| 141 | // WithWorkItemUri ... |
| 142 | func (r *Result) WithWorkItemUri(workItemUri string) *Result { |
| 143 | r.WorkItemUris = append(r.WorkItemUris, workItemUri) |
| 144 | return r |
| 145 | } |
| 146 | |
| 147 | // WithHostedViewerUri ... |
| 148 | func (r *Result) WithHostedViewerUri(hostedViewerUri string) *Result { |
| 149 | r.HostedViewerUri = &hostedViewerUri |
| 150 | return r |
| 151 | } |
| 152 | |
| 153 | // WithFix ... |
| 154 | func (r *Result) WithFix(fix *Fix) *Result { |
| 155 | r.Fixes = append(r.Fixes, fix) |
| 156 | return r |
| 157 | } |
| 158 | |
| 159 | // WithOccurrenceCount ... |
| 160 | func (r *Result) WithOccurrenceCount(occurrenceCount int) *Result { |
| 161 | count := uint(occurrenceCount) |
| 162 | r.OccurrenceCount = &count |
| 163 | return r |
| 164 | } |
| 165 | |
| 166 | // WithProperties specifies properties for a rule and returns the updated rule |
| 167 | func (r *Result) WithProperties(properties Properties) *Result { |
| 168 | r.Properties = properties |
| 169 | return r |
| 170 | } |
| 171 | |
| 172 | // AttachPropertyBag adds a property bag to a rule |
| 173 | func (r *Result) AttachPropertyBag(pb *PropertyBag) { |
| 174 | r.Properties = pb.Properties |
| 175 | } |