| 1 |
package sarif |
| 2 |
|
| 3 |
import ( |
| 4 |
"time" |
| 5 |
) |
| 6 |
|
| 7 |
// ToolComponent ... |
| 8 |
type ToolComponent struct { |
| 9 |
AssociatedComponent *ToolComponentReference `json:"associatedComponent,omitempty"` |
| 10 |
Contents []interface{} `json:"contents,omitempty"` |
| 11 |
DottedQuadFileVersion *string `json:"dottedQuadFileVersion,omitempty"` |
| 12 |
DownloadURI *string `json:"downloadUri,omitempty"` |
| 13 |
FullDescription *MultiformatMessageString `json:"fullDescription,omitempty"` |
| 14 |
FullName *string `json:"fullName,omitempty"` |
| 15 |
GlobalMessageStrings map[string]*MultiformatMessageString `json:"globalMessageStrings,omitempty"` |
| 16 |
GUID *string `json:"guid,omitempty"` |
| 17 |
InformationURI *string `json:"informationUri,omitempty"` |
| 18 |
IsComprehensive *bool `json:"isComprehensive,omitempty"` |
| 19 |
Language *string `json:"language,omitempty"` |
| 20 |
LocalizedDataSemanticVersion *string `json:"localizedDataSemanticVersion,omitempty"` |
| 21 |
Locations []*ArtifactLocation `json:"locations,omitempty"` |
| 22 |
MinimumRequiredLocalizedDataSemanticVersion *string `json:"minimumRequiredLocalizedDataSemanticVersion,omitempty"` |
| 23 |
Name string `json:"name"` |
| 24 |
Notifications []*ReportingDescriptor `json:"notifications,omitempty"` |
| 25 |
Organization *string `json:"organization,omitempty"` |
| 26 |
Product *string `json:"product,omitempty"` |
| 27 |
ProductSuite *string `json:"productSuite,omitempty"` |
| 28 |
ReleaseDateUtc *time.Time `json:"releaseDateUtc,omitempty"` |
| 29 |
Rules []*ReportingDescriptor `json:"rules"` |
| 30 |
SemanticVersion *string `json:"semanticVersion,omitempty"` |
| 31 |
ShortDescription *MultiformatMessageString `json:"shortDescription,omitempty"` |
| 32 |
SupportedTaxonomies []*ToolComponentReference `json:"supportedTaxonomies,omitempty"` |
| 33 |
Taxa []*ReportingDescriptor `json:"taxa,omitempty"` |
| 34 |
TranslationMetadata *TranslationMetadata `json:"translationMetadata,omitempty"` // The tool component version, in whatever format the component natively provides. |
| 35 |
Version *string `json:"version,omitempty"` |
| 36 |
PropertyBag |
| 37 |
} |
| 38 |
|
| 39 |
// NewDriver creates a new Driver and returns a pointer to it |
| 40 |
func NewDriver(name string) *ToolComponent { |
| 41 |
return &ToolComponent{ |
| 42 |
Name: name, |
| 43 |
Rules: []*ReportingDescriptor{}, |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
// NewVersionedDriver creates a new VersionedDriver and returns a pointer to it |
| 48 |
func NewVersionedDriver(name, version string) *ToolComponent { |
| 49 |
return &ToolComponent{ |
| 50 |
Name: name, |
| 51 |
Version: &version, |
| 52 |
Rules: []*ReportingDescriptor{}, |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
// WithVersion specifies tool version, in whatever format it natively provides. Returns updated driver. |
| 57 |
func (driver *ToolComponent) WithVersion(version string) *ToolComponent { |
| 58 |
driver.Version = &version |
| 59 |
return driver |
| 60 |
} |
| 61 |
|
| 62 |
func (driver *ToolComponent) getOrCreateRule(rule *ReportingDescriptor) uint { |
| 63 |
for i, r := range driver.Rules { |
| 64 |
if r.ID == rule.ID { |
| 65 |
return uint(i) |
| 66 |
} |
| 67 |
} |
| 68 |
driver.Rules = append(driver.Rules, rule) |
| 69 |
return uint(len(driver.Rules) - 1) |
| 70 |
} |
| 71 |
|
| 72 |
// WithInformationURI sets the InformationURI |
| 73 |
func (driver *ToolComponent) WithInformationURI(informationURI string) *ToolComponent { |
| 74 |
driver.InformationURI = &informationURI |
| 75 |
return driver |
| 76 |
} |
| 77 |
|
| 78 |
// WithNotifications sets the Notifications |
| 79 |
func (driver *ToolComponent) WithNotifications(notifications []*ReportingDescriptor) *ToolComponent { |
| 80 |
driver.Notifications = notifications |
| 81 |
return driver |
| 82 |
} |
| 83 |
|
| 84 |
// AddNotification ... |
| 85 |
func (driver *ToolComponent) AddNotification(notification *ReportingDescriptor) { |
| 86 |
driver.Notifications = append(driver.Notifications, notification) |
| 87 |
} |
| 88 |
|
| 89 |
// WithRules sets the Rules |
| 90 |
func (driver *ToolComponent) WithRules(rules []*ReportingDescriptor) *ToolComponent { |
| 91 |
for _, rule := range rules { |
| 92 |
driver.getOrCreateRule(rule) |
| 93 |
} |
| 94 |
return driver |
| 95 |
} |
| 96 |
|
| 97 |
// AddRule ... |
| 98 |
func (driver *ToolComponent) AddRule(rule *ReportingDescriptor) { |
| 99 |
driver.getOrCreateRule(rule) |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
// WithTaxa sets the Taxa |
| 104 |
func (driver *ToolComponent) WithTaxa(taxa []*ReportingDescriptor) *ToolComponent { |
| 105 |
driver.Taxa = taxa |
| 106 |
return driver |
| 107 |
} |
| 108 |
|
| 109 |
// AddTaxa adds a single Taxa to the Taxa slice |
| 110 |
func (driver *ToolComponent) AddTaxa(taxa *ReportingDescriptor) { |
| 111 |
driver.Taxa = append(driver.Taxa, taxa) |
| 112 |
} |
| 113 |
|
| 114 |
// WithAssociatedComponent adds an associated component to the driver |
| 115 |
func (driver *ToolComponent) WithAssociatedComponent(associatedComponent *ToolComponentReference) *ToolComponent { |
| 116 |
driver.AssociatedComponent = associatedComponent |
| 117 |
return driver |
| 118 |
} |
| 119 |
|
| 120 |
// WithContents sets the contents slice to the provided value |
| 121 |
func (driver *ToolComponent) WithContents(contents []interface{}) *ToolComponent { |
| 122 |
driver.Contents = contents |
| 123 |
return driver |
| 124 |
} |
| 125 |
|
| 126 |
// AddContent adds a single content object to the Contents slice |
| 127 |
func (driver *ToolComponent) AddContent(content interface{}) { |
| 128 |
driver.Contents = append(driver.Contents, content) |
| 129 |
} |
| 130 |
|
| 131 |
// WithDottedQuadFileVersion ... |
| 132 |
func (driver *ToolComponent) WithDottedQuadFileVersion(version string) *ToolComponent { |
| 133 |
driver.DottedQuadFileVersion = &version |
| 134 |
return driver |
| 135 |
} |
| 136 |
|
| 137 |
// WithDownloadURI ... |
| 138 |
func (driver *ToolComponent) WithDownloadURI(downloadURI string) *ToolComponent { |
| 139 |
driver.DownloadURI = &downloadURI |
| 140 |
return driver |
| 141 |
} |
| 142 |
|
| 143 |
// WithFullDescription ... |
| 144 |
func (driver *ToolComponent) WithFullDescription(description *MultiformatMessageString) *ToolComponent { |
| 145 |
driver.FullDescription = description |
| 146 |
return driver |
| 147 |
} |
| 148 |
|
| 149 |
// WithFullName ... |
| 150 |
func (driver *ToolComponent) WithFullName(fullName string) *ToolComponent { |
| 151 |
driver.FullName = &fullName |
| 152 |
return driver |
| 153 |
} |
| 154 |
|
| 155 |
// WithGlobalMessageStrings ... |
| 156 |
func (driver *ToolComponent) WithGlobalMessageStrings(messageStrings map[string]*MultiformatMessageString) *ToolComponent { |
| 157 |
driver.GlobalMessageStrings = messageStrings |
| 158 |
return driver |
| 159 |
} |
| 160 |
|
| 161 |
// WithGUID ... |
| 162 |
func (driver *ToolComponent) WithGUID(guid string) *ToolComponent { |
| 163 |
driver.GUID = &guid |
| 164 |
return driver |
| 165 |
} |
| 166 |
|
| 167 |
// WithIsComprehensive ... |
| 168 |
func (driver *ToolComponent) WithIsComprehensive(isComprehensive bool) *ToolComponent { |
| 169 |
driver.IsComprehensive = &isComprehensive |
| 170 |
return driver |
| 171 |
} |
| 172 |
|
| 173 |
// WithLanguage ... |
| 174 |
func (driver *ToolComponent) WithLanguage(language string) *ToolComponent { |
| 175 |
driver.Language = &language |
| 176 |
return driver |
| 177 |
} |
| 178 |
|
| 179 |
// WithLocalizedDataSemanticVersion ... |
| 180 |
func (driver *ToolComponent) WithLocalizedDataSemanticVersion(version string) *ToolComponent { |
| 181 |
driver.LocalizedDataSemanticVersion = &version |
| 182 |
return driver |
| 183 |
} |
| 184 |
|
| 185 |
// WithLocations ... |
| 186 |
func (driver *ToolComponent) WithLocations(locations []*ArtifactLocation) *ToolComponent { |
| 187 |
driver.Locations = locations |
| 188 |
return driver |
| 189 |
} |
| 190 |
|
| 191 |
// AddLocation ... |
| 192 |
func (driver *ToolComponent) AddLocation(location *ArtifactLocation) { |
| 193 |
driver.Locations = append(driver.Locations, location) |
| 194 |
} |
| 195 |
|
| 196 |
// WithMinimumRequiredLocalizedDataSemanticVersion ... |
| 197 |
func (driver *ToolComponent) WithMinimumRequiredLocalizedDataSemanticVersion(version string) *ToolComponent { |
| 198 |
driver.MinimumRequiredLocalizedDataSemanticVersion = &version |
| 199 |
return driver |
| 200 |
} |
| 201 |
|
| 202 |
// WithOrganization ... |
| 203 |
func (driver *ToolComponent) WithOrganization(organization string) *ToolComponent { |
| 204 |
driver.Organization = &organization |
| 205 |
return driver |
| 206 |
} |
| 207 |
|
| 208 |
// WithProduct ... |
| 209 |
func (driver *ToolComponent) WithProduct(product string) *ToolComponent { |
| 210 |
driver.Product = &product |
| 211 |
return driver |
| 212 |
} |
| 213 |
|
| 214 |
// WithProductSuite ... |
| 215 |
func (driver *ToolComponent) WithProductSuite(suite string) *ToolComponent { |
| 216 |
driver.ProductSuite = &suite |
| 217 |
return driver |
| 218 |
} |
| 219 |
|
| 220 |
// WithReleaseDateUTC ... |
| 221 |
func (driver *ToolComponent) WithReleaseDateUTC(releaseDate *time.Time) *ToolComponent { |
| 222 |
driver.ReleaseDateUtc = releaseDate |
| 223 |
return driver |
| 224 |
} |
| 225 |
|
| 226 |
// WithSemanticVersion ... |
| 227 |
func (driver *ToolComponent) WithSemanticVersion(version string) *ToolComponent { |
| 228 |
driver.SemanticVersion = &version |
| 229 |
return driver |
| 230 |
} |
| 231 |
|
| 232 |
// WithShortDescription ... |
| 233 |
func (driver *ToolComponent) WithShortDescription(description *MultiformatMessageString) *ToolComponent { |
| 234 |
driver.ShortDescription = description |
| 235 |
return driver |
| 236 |
} |
| 237 |
|
| 238 |
// WithSupportedTaxonomies ... |
| 239 |
func (driver *ToolComponent) WithSupportedTaxonomies(taxonomies []*ToolComponentReference) *ToolComponent { |
| 240 |
driver.SupportedTaxonomies = taxonomies |
| 241 |
return driver |
| 242 |
} |
| 243 |
|
| 244 |
// AddSupportedTaxonomie ... |
| 245 |
func (driver *ToolComponent) AddSupportedTaxonomie(taxonomy *ToolComponentReference) { |
| 246 |
driver.SupportedTaxonomies = append(driver.SupportedTaxonomies, taxonomy) |
| 247 |
} |
| 248 |
|
| 249 |
// WithTranslationMetadata ... |
| 250 |
func (driver *ToolComponent) WithTranslationMetadata(metadata *TranslationMetadata) *ToolComponent { |
| 251 |
driver.TranslationMetadata = metadata |
| 252 |
return driver |
| 253 |
} |
| 254 |
|
| 255 |
func (driver *ToolComponent) getRuleIndex(id *string) int { |
| 256 |
for i, rule := range driver.Rules { |
| 257 |
if rule.ID == *id { |
| 258 |
return i |
| 259 |
} |
| 260 |
} |
| 261 |
return -1 |
| 262 |
} |