Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
package cmd
import (
2022-08-02 08:26:26 +02:00
"context"
2021-02-10 16:18:00 +01:00
"encoding/json"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"time"
2021-02-03 14:52:48 +01:00
piperDocker "github.com/SAP/jenkins-library/pkg/docker"
2022-03-17 15:32:48 +01:00
piperGithub "github.com/SAP/jenkins-library/pkg/github"
2021-02-03 14:52:48 +01:00
piperhttp "github.com/SAP/jenkins-library/pkg/http"
ws "github.com/SAP/jenkins-library/pkg/whitesource"
2020-11-02 08:51:58 +01:00
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"github.com/SAP/jenkins-library/pkg/command"
2022-08-09 13:56:01 +02:00
"github.com/SAP/jenkins-library/pkg/format"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"github.com/SAP/jenkins-library/pkg/log"
2021-02-03 14:52:48 +01:00
"github.com/SAP/jenkins-library/pkg/npm"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"github.com/SAP/jenkins-library/pkg/piperutils"
2021-02-10 16:18:00 +01:00
"github.com/SAP/jenkins-library/pkg/reporting"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"github.com/SAP/jenkins-library/pkg/telemetry"
2021-06-23 15:05:00 +02:00
"github.com/SAP/jenkins-library/pkg/toolrecord"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
"github.com/SAP/jenkins-library/pkg/versioning"
2021-02-03 14:52:48 +01:00
"github.com/pkg/errors"
2021-10-13 10:39:45 +02:00
"github.com/xuri/excelize/v2"
2022-08-02 08:26:26 +02:00
"github.com/google/go-github/v45/github"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
)
2021-02-10 16:18:00 +01:00
// ScanOptions is just used to make the lines less long
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
type ScanOptions = whitesourceExecuteScanOptions
2021-06-30 11:11:41 +02:00
// WhiteSource defines the functions that are expected by the step implementation to
// be available from the WhiteSource system.
2020-09-18 11:54:45 +02:00
type whitesource interface {
GetProductByName ( productName string ) ( ws . Product , error )
2020-10-29 09:21:01 +01:00
CreateProduct ( productName string ) ( string , error )
SetProductAssignments ( productToken string , membership , admins , alertReceivers * ws . Assignment ) error
2020-09-18 11:54:45 +02:00
GetProjectsMetaInfo ( productToken string ) ( [ ] ws . Project , error )
GetProjectToken ( productToken , projectName string ) ( string , error )
GetProjectByToken ( projectToken string ) ( ws . Project , error )
GetProjectRiskReport ( projectToken string ) ( [ ] byte , error )
GetProjectVulnerabilityReport ( projectToken string , format string ) ( [ ] byte , error )
GetProjectAlerts ( projectToken string ) ( [ ] ws . Alert , error )
2021-02-10 16:18:00 +01:00
GetProjectAlertsByType ( projectToken , alertType string ) ( [ ] ws . Alert , error )
2020-09-18 11:54:45 +02:00
GetProjectLibraryLocations ( projectToken string ) ( [ ] ws . Library , error )
2022-08-09 13:56:01 +02:00
GetProjectHierarchy ( projectToken string , includeInHouse bool ) ( [ ] ws . Library , error )
2020-09-18 11:54:45 +02:00
}
type whitesourceUtils interface {
2020-10-20 09:49:26 +02:00
ws . Utils
2021-11-15 07:48:40 +01:00
piperutils . FileUtils
2022-08-02 08:26:26 +02:00
GetArtifactCoordinates ( buildTool , buildDescriptorFile string , options * versioning . Options ) ( versioning . Coordinates , error )
2020-09-29 12:44:31 +02:00
Now ( ) time . Time
2022-08-02 08:26:26 +02:00
GetIssueService ( ) * github . IssuesService
GetSearchService ( ) * github . SearchService
2020-09-18 11:54:45 +02:00
}
type whitesourceUtilsBundle struct {
* piperhttp . Client
* command . Command
* piperutils . Files
2020-09-29 12:44:31 +02:00
npmExecutor npm . Executor
2022-08-02 08:26:26 +02:00
issues * github . IssuesService
search * github . SearchService
2022-03-17 15:32:48 +01:00
}
2020-10-20 09:49:26 +02:00
func ( w * whitesourceUtilsBundle ) FileOpen ( name string , flag int , perm os . FileMode ) ( ws . File , error ) {
2020-09-29 12:44:31 +02:00
return os . OpenFile ( name , flag , perm )
}
2021-02-10 16:18:00 +01:00
func ( w * whitesourceUtilsBundle ) GetArtifactCoordinates ( buildTool , buildDescriptorFile string , options * versioning . Options ) ( versioning . Coordinates , error ) {
2020-09-29 12:44:31 +02:00
artifact , err := versioning . GetArtifact ( buildTool , buildDescriptorFile , options , w )
2020-09-18 11:54:45 +02:00
if err != nil {
2021-02-10 16:18:00 +01:00
return versioning . Coordinates { } , err
2020-09-18 11:54:45 +02:00
}
return artifact . GetCoordinates ( )
}
2020-10-20 09:49:26 +02:00
func ( w * whitesourceUtilsBundle ) getNpmExecutor ( config * ws . ScanOptions ) npm . Executor {
2020-09-29 12:44:31 +02:00
if w . npmExecutor == nil {
w . npmExecutor = npm . NewExecutor ( npm . ExecutorOptions { DefaultNpmRegistry : config . DefaultNpmRegistry } )
}
return w . npmExecutor
}
2020-10-20 09:49:26 +02:00
func ( w * whitesourceUtilsBundle ) FindPackageJSONFiles ( config * ws . ScanOptions ) ( [ ] string , error ) {
2020-09-29 12:44:31 +02:00
return w . getNpmExecutor ( config ) . FindPackageJSONFilesWithExcludes ( config . BuildDescriptorExcludeList )
}
2020-10-20 09:49:26 +02:00
func ( w * whitesourceUtilsBundle ) InstallAllNPMDependencies ( config * ws . ScanOptions , packageJSONFiles [ ] string ) error {
2020-09-29 12:44:31 +02:00
return w . getNpmExecutor ( config ) . InstallAllDependencies ( packageJSONFiles )
}
2021-06-08 11:03:57 +02:00
func ( w * whitesourceUtilsBundle ) SetOptions ( o piperhttp . ClientOptions ) {
w . Client . SetOptions ( o )
}
2020-09-29 12:44:31 +02:00
func ( w * whitesourceUtilsBundle ) Now ( ) time . Time {
return time . Now ( )
}
2022-08-02 08:26:26 +02:00
func ( w * whitesourceUtilsBundle ) GetIssueService ( ) * github . IssuesService {
return w . issues
}
func ( w * whitesourceUtilsBundle ) GetSearchService ( ) * github . SearchService {
return w . search
}
func newWhitesourceUtils ( config * ScanOptions , client * github . Client ) * whitesourceUtilsBundle {
2020-09-18 11:54:45 +02:00
utils := whitesourceUtilsBundle {
Client : & piperhttp . Client { } ,
Command : & command . Command { } ,
Files : & piperutils . Files { } ,
}
2022-08-02 08:26:26 +02:00
if client != nil {
utils . issues = client . Issues
utils . search = client . Search
}
2020-09-18 11:54:45 +02:00
// Reroute cmd output to logging framework
utils . Stdout ( log . Writer ( ) )
utils . Stderr ( log . Writer ( ) )
2020-10-29 09:21:01 +01:00
// Configure HTTP Client
2021-06-15 11:13:24 +02:00
utils . SetOptions ( piperhttp . ClientOptions { TransportTimeout : time . Duration ( config . Timeout ) * time . Second } )
2020-09-18 11:54:45 +02:00
return & utils
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
2020-10-20 09:49:26 +02:00
func newWhitesourceScan ( config * ScanOptions ) * ws . Scan {
return & ws . Scan {
AggregateProjectName : config . ProjectName ,
2021-02-10 16:18:00 +01:00
ProductVersion : config . Version ,
2022-08-11 13:12:14 +02:00
BuildTool : config . BuildTool ,
2020-09-29 12:44:31 +02:00
}
}
2021-03-10 16:00:53 +01:00
func whitesourceExecuteScan ( config ScanOptions , _ * telemetry . CustomData , commonPipelineEnvironment * whitesourceExecuteScanCommonPipelineEnvironment , influx * whitesourceExecuteScanInflux ) {
2022-08-02 08:26:26 +02:00
ctx , client , err := piperGithub . NewClient ( config . GithubToken , config . GithubAPIURL , "" , config . CustomTLSCertificateLinks )
if err != nil {
log . Entry ( ) . WithError ( err ) . Warning ( "Failed to get GitHub client" )
}
utils := newWhitesourceUtils ( & config , client )
2020-09-29 12:44:31 +02:00
scan := newWhitesourceScan ( & config )
2020-11-02 08:51:58 +01:00
sys := ws . NewSystem ( config . ServiceURL , config . OrgToken , config . UserToken , time . Duration ( config . Timeout ) * time . Second )
2021-03-18 10:32:03 +01:00
influx . step_data . fields . whitesource = false
2022-08-02 08:26:26 +02:00
if err := runWhitesourceExecuteScan ( ctx , & config , scan , utils , sys , commonPipelineEnvironment , influx ) ; err != nil {
2020-09-29 12:44:31 +02:00
log . Entry ( ) . WithError ( err ) . Fatal ( "step execution failed" )
}
2021-03-18 10:32:03 +01:00
influx . step_data . fields . whitesource = true
2020-09-29 12:44:31 +02:00
}
2022-08-02 08:26:26 +02:00
func runWhitesourceExecuteScan ( ctx context . Context , config * ScanOptions , scan * ws . Scan , utils whitesourceUtils , sys whitesource , commonPipelineEnvironment * whitesourceExecuteScanCommonPipelineEnvironment , influx * whitesourceExecuteScanInflux ) error {
2020-11-10 09:09:51 +01:00
if err := resolveAggregateProjectName ( config , scan , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to resolve and aggregate project name" )
2020-11-10 09:09:51 +01:00
}
2020-09-29 12:44:31 +02:00
if err := resolveProjectIdentifiers ( config , scan , utils , sys ) ; err != nil {
2021-05-10 17:44:28 +02:00
if strings . Contains ( fmt . Sprint ( err ) , "User is not allowed to perform this action" ) {
log . SetErrorCategory ( log . ErrorConfiguration )
}
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to resolve project identifiers" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
if config . AggregateVersionWideReport {
2020-09-29 12:44:31 +02:00
// Generate a vulnerability report for all projects with version = config.ProjectVersion
// Note that this is not guaranteed that all projects are from the same scan.
// For example, if a module was removed from the source code, the project may still
// exist in the WhiteSource system.
if err := aggregateVersionWideLibraries ( config , utils , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to aggregate version wide libraries" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-09-29 12:44:31 +02:00
if err := aggregateVersionWideVulnerabilities ( config , utils , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to aggregate version wide vulnerabilities" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
} else {
2022-08-02 08:26:26 +02:00
if err := runWhitesourceScan ( ctx , config , scan , utils , sys , commonPipelineEnvironment , influx ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to execute WhiteSource scan" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
}
2020-09-29 12:44:31 +02:00
return nil
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2022-08-02 08:26:26 +02:00
func runWhitesourceScan ( ctx context . Context , config * ScanOptions , scan * ws . Scan , utils whitesourceUtils , sys whitesource , commonPipelineEnvironment * whitesourceExecuteScanCommonPipelineEnvironment , influx * whitesourceExecuteScanInflux ) error {
2021-02-03 14:52:48 +01:00
// Download Docker image for container scan
// ToDo: move it to improve testability
if config . BuildTool == "docker" {
saveImageOptions := containerSaveImageOptions {
2022-02-28 13:57:23 +01:00
ContainerImage : config . ScanImage ,
ContainerRegistryURL : config . ScanImageRegistryURL ,
ContainerRegistryUser : config . ContainerRegistryUser ,
ContainerRegistryPassword : config . ContainerRegistryPassword ,
DockerConfigJSON : config . DockerConfigJSON ,
FilePath : config . ProjectName ,
2022-05-13 18:56:41 +02:00
ImageFormat : "legacy" , // keep the image format legacy or whitesource is not able to read layers
2021-02-03 14:52:48 +01:00
}
2022-05-13 18:56:41 +02:00
dClientOptions := piperDocker . ClientOptions { ImageName : saveImageOptions . ContainerImage , RegistryURL : saveImageOptions . ContainerRegistryURL , LocalPath : "" , ImageFormat : "legacy" }
2021-02-03 14:52:48 +01:00
dClient := & piperDocker . Client { }
dClient . SetOptions ( dClientOptions )
2022-02-28 13:57:23 +01:00
if _ , err := runContainerSaveImage ( & saveImageOptions , & telemetry . CustomData { } , "./cache" , "" , dClient , utils ) ; err != nil {
2021-05-10 17:44:28 +02:00
if strings . Contains ( fmt . Sprint ( err ) , "no image found" ) {
log . SetErrorCategory ( log . ErrorConfiguration )
}
2021-10-25 09:07:46 +02:00
return errors . Wrapf ( err , "failed to download Docker image %v" , config . ScanImage )
2021-02-03 14:52:48 +01:00
}
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
// Start the scan
2020-09-29 12:44:31 +02:00
if err := executeScan ( config , scan , utils ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to execute Scan" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-02-03 14:52:48 +01:00
// ToDo: Check this:
// Why is this required at all, resolveProjectIdentifiers() is already called before the scan in runWhitesourceExecuteScan()
2020-09-29 12:44:31 +02:00
// Could perhaps use scan.updateProjects(sys) directly... have not investigated what could break
if err := resolveProjectIdentifiers ( config , scan , utils , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to resolve project identifiers" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
log . Entry ( ) . Info ( "-----------------------------------------------------" )
2021-02-10 16:18:00 +01:00
log . Entry ( ) . Infof ( "Product Version: '%s'" , config . Version )
2020-09-29 12:44:31 +02:00
log . Entry ( ) . Info ( "Scanned projects:" )
2020-10-20 09:49:26 +02:00
for _ , project := range scan . ScannedProjects ( ) {
2020-09-29 12:44:31 +02:00
log . Entry ( ) . Infof ( " Name: '%s', token: %s" , project . Name , project . Token )
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
log . Entry ( ) . Info ( "-----------------------------------------------------" )
2022-08-02 08:26:26 +02:00
paths , err := checkAndReportScanResults ( ctx , config , scan , utils , sys , influx )
2022-08-09 10:57:02 +02:00
piperutils . PersistReportsAndLinks ( "whitesourceExecuteScan" , "" , utils , paths , nil )
2021-02-10 16:18:00 +01:00
persistScannedProjects ( config , scan , commonPipelineEnvironment )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to check and report scan results" )
2020-09-18 11:54:45 +02:00
}
2020-09-29 12:44:31 +02:00
return nil
}
2022-08-02 08:26:26 +02:00
func checkAndReportScanResults ( ctx context . Context , config * ScanOptions , scan * ws . Scan , utils whitesourceUtils , sys whitesource , influx * whitesourceExecuteScanInflux ) ( [ ] piperutils . Path , error ) {
2021-02-10 16:18:00 +01:00
reportPaths := [ ] piperutils . Path { }
2020-09-29 12:44:31 +02:00
if ! config . Reporting && ! config . SecurityVulnerabilities {
2021-02-10 16:18:00 +01:00
return reportPaths , nil
2020-09-29 12:44:31 +02:00
}
2020-11-10 09:09:51 +01:00
// Wait for WhiteSource backend to propagate the changes before downloading any reports.
if err := scan . BlockUntilReportsAreReady ( sys ) ; err != nil {
2021-02-10 16:18:00 +01:00
return reportPaths , err
2020-09-29 12:44:31 +02:00
}
2021-02-10 16:18:00 +01:00
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if config . Reporting {
2021-02-10 16:18:00 +01:00
var err error
reportPaths , err = scan . DownloadReports ( ws . ReportOptions {
ReportDirectory : ws . ReportsDirectory ,
2020-10-20 09:49:26 +02:00
VulnerabilityReportFormat : config . VulnerabilityReportFormat ,
} , utils , sys )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if err != nil {
2021-02-10 16:18:00 +01:00
return reportPaths , err
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
}
2021-02-10 16:18:00 +01:00
checkErrors := [ ] string { }
2022-11-07 11:16:07 +01:00
rPath , err := checkPolicyViolations ( ctx , config , scan , sys , utils , reportPaths , influx )
2021-02-10 16:18:00 +01:00
if err != nil {
2022-11-07 11:16:07 +01:00
if ! config . FailOnSevereVulnerabilities && log . GetErrorCategory ( ) == log . ErrorCompliance {
log . Entry ( ) . Infof ( "policy violation(s) found - step will only create data but not fail due to setting failOnSevereVulnerabilities: false" )
} else {
checkErrors = append ( checkErrors , fmt . Sprint ( err ) )
}
2021-02-10 16:18:00 +01:00
}
reportPaths = append ( reportPaths , rPath )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if config . SecurityVulnerabilities {
2022-08-02 08:26:26 +02:00
rPaths , err := checkSecurityViolations ( ctx , config , scan , sys , utils , influx )
2021-02-10 16:18:00 +01:00
reportPaths = append ( reportPaths , rPaths ... )
if err != nil {
2022-11-07 11:16:07 +01:00
if ! config . FailOnSevereVulnerabilities && log . GetErrorCategory ( ) == log . ErrorCompliance {
log . Entry ( ) . Infof ( "policy violation(s) found - step will only create data but not fail due to setting failOnSevereVulnerabilities: false" )
} else {
checkErrors = append ( checkErrors , fmt . Sprint ( err ) )
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
}
2021-06-23 15:05:00 +02:00
// create toolrecord file
// tbd - how to handle verifyOnly
2022-08-09 10:57:02 +02:00
toolRecordFileName , err := createToolRecordWhitesource ( utils , "./" , config , scan )
2021-06-23 15:05:00 +02:00
if err != nil {
// do not fail until the framework is well established
log . Entry ( ) . Warning ( "TR_WHITESOURCE: Failed to create toolrecord file ..." , err )
} else {
reportPaths = append ( reportPaths , piperutils . Path { Target : toolRecordFileName } )
}
2021-02-10 16:18:00 +01:00
if len ( checkErrors ) > 0 {
return reportPaths , fmt . Errorf ( strings . Join ( checkErrors , ": " ) )
}
return reportPaths , nil
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-10-29 09:21:01 +01:00
func createWhiteSourceProduct ( config * ScanOptions , sys whitesource ) ( string , error ) {
log . Entry ( ) . Infof ( "Attempting to create new WhiteSource product for '%s'.." , config . ProductName )
productToken , err := sys . CreateProduct ( config . ProductName )
if err != nil {
return "" , fmt . Errorf ( "failed to create WhiteSource product: %w" , err )
}
var admins ws . Assignment
for _ , address := range config . EmailAddressesOfInitialProductAdmins {
admins . UserAssignments = append ( admins . UserAssignments , ws . UserAssignment { Email : address } )
}
err = sys . SetProductAssignments ( productToken , nil , & admins , nil )
if err != nil {
return "" , fmt . Errorf ( "failed to set admins on new WhiteSource product: %w" , err )
}
return productToken , nil
}
2020-10-20 09:49:26 +02:00
func resolveProjectIdentifiers ( config * ScanOptions , scan * ws . Scan , utils whitesourceUtils , sys whitesource ) error {
2021-02-10 16:18:00 +01:00
if len ( scan . AggregateProjectName ) > 0 && ( len ( config . Version ) + len ( config . CustomScanVersion ) > 0 ) {
2023-01-16 23:14:33 +06:00
if len ( config . CustomScanVersion ) > 0 {
log . Entry ( ) . Infof ( "Using custom version: %v" , config . CustomScanVersion )
2021-02-10 16:18:00 +01:00
config . Version = config . CustomScanVersion
2023-01-16 23:14:33 +06:00
} else if len ( config . Version ) > 0 {
log . Entry ( ) . Infof ( "Resolving product version from default provided '%s' with versioning '%s'" , config . Version , config . VersioningModel )
config . Version = versioning . ApplyVersioningModel ( config . VersioningModel , config . Version )
log . Entry ( ) . Infof ( "Resolved product version '%s'" , config . Version )
2021-02-10 16:18:00 +01:00
}
} else {
2020-09-29 12:44:31 +02:00
options := & versioning . Options {
2021-02-03 14:52:48 +01:00
DockerImage : config . ScanImage ,
2020-09-29 12:44:31 +02:00
ProjectSettingsFile : config . ProjectSettingsFile ,
GlobalSettingsFile : config . GlobalSettingsFile ,
M2Path : config . M2Path ,
}
coordinates , err := utils . GetArtifactCoordinates ( config . BuildTool , config . BuildDescriptorFile , options )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrap ( err , "failed to get build artifact description" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2022-08-09 13:56:01 +02:00
scan . Coordinates = coordinates
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
2021-02-10 16:18:00 +01:00
if len ( config . Version ) > 0 {
log . Entry ( ) . Infof ( "Resolving product version from default provided '%s' with versioning '%s'" , config . Version , config . VersioningModel )
coordinates . Version = config . Version
}
2021-02-03 14:52:48 +01:00
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
nameTmpl := ` {{ list .GroupID .ArtifactID | join "-" | trimAll "-" }} `
2021-02-10 16:18:00 +01:00
name , version := versioning . DetermineProjectCoordinatesWithCustomVersion ( nameTmpl , config . VersioningModel , config . CustomScanVersion , coordinates )
2020-10-20 09:49:26 +02:00
if scan . AggregateProjectName == "" {
2020-09-18 11:54:45 +02:00
log . Entry ( ) . Infof ( "Resolved project name '%s' from descriptor file" , name )
2020-10-20 09:49:26 +02:00
scan . AggregateProjectName = name
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-02-10 16:18:00 +01:00
config . Version = version
log . Entry ( ) . Infof ( "Resolved product version '%s'" , version )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-02-10 16:18:00 +01:00
scan . ProductVersion = validateProductVersion ( config . Version )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
2020-10-29 09:21:01 +01:00
if err := resolveProductToken ( config , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrap ( err , "error resolving product token" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-10-29 09:21:01 +01:00
if err := resolveAggregateProjectToken ( config , sys ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrap ( err , "error resolving aggregate project token" )
2020-10-29 09:21:01 +01:00
}
2022-08-11 13:12:14 +02:00
scan . ProductToken = config . ProductToken
2020-10-29 09:21:01 +01:00
return scan . UpdateProjects ( config . ProductToken , sys )
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
2020-10-29 09:21:01 +01:00
// resolveProductToken resolves the token of the WhiteSource Product specified by config.ProductName,
// unless the user provided a token in config.ProductToken already, or it was previously resolved.
// If no Product can be found for the given config.ProductName, and the parameter
// config.CreatePipelineFromProduct is set, an attempt will be made to create the product and
// configure the initial product admins.
func resolveProductToken ( config * ScanOptions , sys whitesource ) error {
if config . ProductToken != "" {
return nil
}
log . Entry ( ) . Infof ( "Attempting to resolve product token for product '%s'.." , config . ProductName )
product , err := sys . GetProductByName ( config . ProductName )
if err != nil && config . CreateProductFromPipeline {
product = ws . Product { }
product . Token , err = createWhiteSourceProduct ( config , sys )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to create whitesource product" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
}
2020-10-29 09:21:01 +01:00
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get product by name" )
2020-10-29 09:21:01 +01:00
}
log . Entry ( ) . Infof ( "Resolved product token: '%s'.." , product . Token )
config . ProductToken = product . Token
return nil
}
2020-09-29 12:44:31 +02:00
2020-11-10 09:09:51 +01:00
// resolveAggregateProjectName checks if config.ProjectToken is configured, and if so, expects a WhiteSource
// project with that token to exist. The AggregateProjectName in the ws.Scan is then configured with that
// project's name.
func resolveAggregateProjectName ( config * ScanOptions , scan * ws . Scan , sys whitesource ) error {
if config . ProjectToken == "" {
return nil
}
log . Entry ( ) . Infof ( "Attempting to resolve aggregate project name for token '%s'.." , config . ProjectToken )
// If the user configured the "projectToken" parameter, we expect this project to exist in the backend.
project , err := sys . GetProjectByToken ( config . ProjectToken )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get project by token" )
2020-11-10 09:09:51 +01:00
}
nameVersion := strings . Split ( project . Name , " - " )
scan . AggregateProjectName = nameVersion [ 0 ]
log . Entry ( ) . Infof ( "Resolve aggregate project name '%s'.." , scan . AggregateProjectName )
return nil
}
2020-10-29 09:21:01 +01:00
// resolveAggregateProjectToken fetches the token of the WhiteSource Project specified by config.ProjectName
// and stores it in config.ProjectToken.
// The user can configure a projectName or projectToken of the project to be used as for aggregation of scan results.
func resolveAggregateProjectToken ( config * ScanOptions , sys whitesource ) error {
if config . ProjectToken != "" || config . ProjectName == "" {
return nil
}
log . Entry ( ) . Infof ( "Attempting to resolve project token for project '%s'.." , config . ProjectName )
2021-02-10 16:18:00 +01:00
fullProjName := fmt . Sprintf ( "%s - %s" , config . ProjectName , config . Version )
2020-10-29 09:21:01 +01:00
projectToken , err := sys . GetProjectToken ( config . ProductToken , fullProjName )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get project token" )
2020-10-29 09:21:01 +01:00
}
// A project may not yet exist for this project name-version combo.
// It will be created by the scan, we retrieve the token again after scanning.
if projectToken != "" {
log . Entry ( ) . Infof ( "Resolved project token: '%s'.." , projectToken )
config . ProjectToken = projectToken
} else {
log . Entry ( ) . Infof ( "Project '%s' not yet present in WhiteSource" , fullProjName )
}
return nil
2020-10-20 09:49:26 +02:00
}
// validateProductVersion makes sure that the version does not contain a dash "-".
func validateProductVersion ( version string ) string {
// TrimLeft() removes all "-" from the beginning, unlike TrimPrefix()!
version = strings . TrimLeft ( version , "-" )
if strings . Contains ( version , "-" ) {
version = strings . SplitN ( version , "-" , 1 ) [ 0 ]
}
return version
}
func wsScanOptions ( config * ScanOptions ) * ws . ScanOptions {
return & ws . ScanOptions {
2021-02-03 14:52:48 +01:00
BuildTool : config . BuildTool ,
2021-03-19 09:58:24 +01:00
ScanType : "" , // no longer provided via config
2020-10-20 09:49:26 +02:00
OrgToken : config . OrgToken ,
UserToken : config . UserToken ,
ProductName : config . ProductName ,
ProductToken : config . ProductToken ,
2021-02-10 16:18:00 +01:00
ProductVersion : config . Version ,
2020-10-20 09:49:26 +02:00
ProjectName : config . ProjectName ,
2021-02-03 14:52:48 +01:00
BuildDescriptorFile : config . BuildDescriptorFile ,
2020-10-20 09:49:26 +02:00
BuildDescriptorExcludeList : config . BuildDescriptorExcludeList ,
PomPath : config . BuildDescriptorFile ,
M2Path : config . M2Path ,
GlobalSettingsFile : config . GlobalSettingsFile ,
ProjectSettingsFile : config . ProjectSettingsFile ,
2020-10-30 15:05:14 +01:00
InstallArtifacts : config . InstallArtifacts ,
2020-10-20 09:49:26 +02:00
DefaultNpmRegistry : config . DefaultNpmRegistry ,
AgentDownloadURL : config . AgentDownloadURL ,
AgentFileName : config . AgentFileName ,
ConfigFilePath : config . ConfigFilePath ,
Includes : config . Includes ,
Excludes : config . Excludes ,
2021-02-03 14:52:48 +01:00
JreDownloadURL : config . JreDownloadURL ,
AgentURL : config . AgentURL ,
ServiceURL : config . ServiceURL ,
2021-05-03 11:53:16 +03:00
ScanPath : config . ScanPath ,
2021-02-03 14:52:48 +01:00
Verbose : GeneralConfig . Verbose ,
2020-10-20 09:49:26 +02:00
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-03-19 09:58:24 +01:00
// Unified Agent is the only supported option by WhiteSource going forward:
// The Unified Agent will be used to perform the scan.
2020-10-20 09:49:26 +02:00
func executeScan ( config * ScanOptions , scan * ws . Scan , utils whitesourceUtils ) error {
options := wsScanOptions ( config )
2021-03-19 09:58:24 +01:00
// Execute scan with Unified Agent jar file
if err := scan . ExecuteUAScan ( options , utils ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to execute Unified Agent scan" )
2020-09-29 12:44:31 +02:00
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return nil
}
2022-11-07 11:16:07 +01:00
func checkPolicyViolations ( ctx context . Context , config * ScanOptions , scan * ws . Scan , sys whitesource , utils whitesourceUtils , reportPaths [ ] piperutils . Path , influx * whitesourceExecuteScanInflux ) ( piperutils . Path , error ) {
2021-02-10 16:18:00 +01:00
policyViolationCount := 0
2022-11-07 11:16:07 +01:00
allAlerts := [ ] ws . Alert { }
2021-02-10 16:18:00 +01:00
for _ , project := range scan . ScannedProjects ( ) {
alerts , err := sys . GetProjectAlertsByType ( project . Token , "REJECTED_BY_POLICY_RESOURCE" )
if err != nil {
return piperutils . Path { } , fmt . Errorf ( "failed to retrieve project policy alerts from WhiteSource: %w" , err )
}
policyViolationCount += len ( alerts )
2022-11-07 11:16:07 +01:00
allAlerts = append ( allAlerts , alerts ... )
2021-02-10 16:18:00 +01:00
}
violations := struct {
PolicyViolations int ` json:"policyViolations" `
Reports [ ] string ` json:"reports" `
} {
PolicyViolations : policyViolationCount ,
Reports : [ ] string { } ,
}
for _ , report := range reportPaths {
_ , reportFile := filepath . Split ( report . Target )
violations . Reports = append ( violations . Reports , reportFile )
}
violationContent , err := json . Marshal ( violations )
if err != nil {
return piperutils . Path { } , fmt . Errorf ( "failed to marshal policy violation data: %w" , err )
}
jsonViolationReportPath := filepath . Join ( ws . ReportsDirectory , "whitesource-ip.json" )
2022-07-18 14:36:29 +02:00
err = utils . FileWrite ( jsonViolationReportPath , violationContent , 0 o666 )
2021-02-10 16:18:00 +01:00
if err != nil {
return piperutils . Path { } , fmt . Errorf ( "failed to write policy violation report: %w" , err )
}
policyReport := piperutils . Path { Name : "WhiteSource Policy Violation Report" , Target : jsonViolationReportPath }
2021-04-15 07:45:06 +02:00
// create a json report to be used later, e.g. issue creation in GitHub
ipReport := reporting . ScanReport {
2022-03-17 15:32:48 +01:00
ReportTitle : "WhiteSource IP Report" ,
2021-04-15 07:45:06 +02:00
Subheaders : [ ] reporting . Subheader {
{ Description : "WhiteSource product name" , Details : config . ProductName } ,
{ Description : "Filtered project names" , Details : strings . Join ( scan . ScannedProjectNames ( ) , ", " ) } ,
} ,
Overview : [ ] reporting . OverviewRow {
{ Description : "Total number of licensing vulnerabilities" , Details : fmt . Sprint ( policyViolationCount ) } ,
} ,
2021-05-11 08:01:02 +02:00
SuccessfulScan : policyViolationCount == 0 ,
ReportTime : utils . Now ( ) ,
2021-04-15 07:45:06 +02:00
}
// JSON reports are used by step pipelineCreateSummary in order to e.g. prepare an issue creation in GitHub
// ignore JSON errors since structure is in our hands
jsonReport , _ := ipReport . ToJSON ( )
if exists , _ := utils . DirExists ( reporting . StepReportDirectory ) ; ! exists {
2022-07-18 14:36:29 +02:00
err := utils . MkdirAll ( reporting . StepReportDirectory , 0 o777 )
2021-04-15 07:45:06 +02:00
if err != nil {
return policyReport , errors . Wrap ( err , "failed to create reporting directory" )
}
}
2022-07-18 14:36:29 +02:00
if err := utils . FileWrite ( filepath . Join ( reporting . StepReportDirectory , fmt . Sprintf ( "whitesourceExecuteScan_ip_%v.json" , ws . ReportSha ( config . ProductName , scan ) ) ) , jsonReport , 0 o666 ) ; err != nil {
2021-04-15 07:45:06 +02:00
return policyReport , errors . Wrapf ( err , "failed to write json report" )
}
// we do not add the json report to the overall list of reports for now,
// since it is just an intermediary report used as input for later
// and there does not seem to be real benefit in archiving it.
2021-02-10 16:18:00 +01:00
if policyViolationCount > 0 {
2021-03-10 16:00:53 +01:00
influx . whitesource_data . fields . policy_violations = policyViolationCount
2022-11-07 11:16:07 +01:00
log . SetErrorCategory ( log . ErrorCompliance )
if config . CreateResultIssue && policyViolationCount > 0 && len ( config . GithubToken ) > 0 && len ( config . GithubAPIURL ) > 0 && len ( config . Owner ) > 0 && len ( config . Repository ) > 0 {
log . Entry ( ) . Debugf ( "Creating result issues for %v alert(s)" , policyViolationCount )
issueDetails := make ( [ ] reporting . IssueDetail , len ( allAlerts ) )
piperutils . CopyAtoB ( allAlerts , issueDetails )
gh := reporting . GitHub {
Owner : & config . Owner ,
Repository : & config . Repository ,
Assignees : & config . Assignees ,
IssueService : utils . GetIssueService ( ) ,
SearchService : utils . GetSearchService ( ) ,
}
if err := gh . UploadMultipleReports ( ctx , & issueDetails ) ; err != nil {
return policyReport , fmt . Errorf ( "failed to upload reports to GitHub for %v policy violations: %w" , policyViolationCount , err )
}
2022-07-12 11:43:24 +02:00
}
2022-11-07 11:16:07 +01:00
return policyReport , fmt . Errorf ( "%v policy violation(s) found" , policyViolationCount )
2021-02-10 16:18:00 +01:00
}
return policyReport , nil
}
2022-08-02 08:26:26 +02:00
func checkSecurityViolations ( ctx context . Context , config * ScanOptions , scan * ws . Scan , sys whitesource , utils whitesourceUtils , influx * whitesourceExecuteScanInflux ) ( [ ] piperutils . Path , error ) {
2020-09-29 12:44:31 +02:00
// Check for security vulnerabilities and fail the build if cvssSeverityLimit threshold is crossed
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
// convert config.CvssSeverityLimit to float64
cvssSeverityLimit , err := strconv . ParseFloat ( config . CvssSeverityLimit , 64 )
if err != nil {
2020-09-18 11:54:45 +02:00
log . SetErrorCategory ( log . ErrorConfiguration )
2023-02-07 16:10:21 +01:00
return [ ] piperutils . Path { } , fmt . Errorf ( "failed to parse parameter cvssSeverityLimit (%s) " +
2020-09-18 11:54:45 +02:00
"as floating point number: %w" , config . CvssSeverityLimit , err )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-02-10 16:18:00 +01:00
2022-08-09 13:56:01 +02:00
// inhale assessments from file system
assessments := readAssessmentsFromFile ( config . AssessmentFile , utils )
2023-02-07 16:10:21 +01:00
vulnerabilitiesCount := 0
var allOccurredErrors [ ] string
allAlerts := [ ] ws . Alert { }
allAssessedAlerts := [ ] ws . Alert { }
allLibraries := [ ] ws . Library { }
2020-09-29 12:44:31 +02:00
if config . ProjectToken != "" {
project := ws . Project { Name : config . ProjectName , Token : config . ProjectToken }
2021-02-10 16:18:00 +01:00
// ToDo: see if HTML report generation is really required here
// we anyway need to do some refactoring here since config.ProjectToken != "" essentially indicates an aggregated project
2023-02-07 16:10:21 +01:00
vulnerabilitiesCount , allAlerts , allAssessedAlerts , allLibraries , allOccurredErrors = collectVulnsAndLibsForProject (
config ,
cvssSeverityLimit ,
project ,
sys ,
assessments ,
influx ,
)
log . Entry ( ) . Debugf ( "Collected %v libraries for project %v" , len ( allLibraries ) , project . Name )
2020-09-29 12:44:31 +02:00
} else {
2020-10-20 09:49:26 +02:00
for _ , project := range scan . ScannedProjects ( ) {
2021-02-03 14:52:48 +01:00
// collect errors and aggregate vulnerabilities from all projects
2023-02-07 16:10:21 +01:00
vulCount , alerts , assessedAlerts , libraries , occurredErrors := collectVulnsAndLibsForProject (
config ,
cvssSeverityLimit ,
project ,
sys ,
assessments ,
influx ,
)
if len ( occurredErrors ) != 0 {
allOccurredErrors = append ( allOccurredErrors , occurredErrors ... )
2021-02-03 14:52:48 +01:00
}
2023-02-07 16:10:21 +01:00
2022-08-12 11:59:47 +02:00
allAlerts = append ( allAlerts , alerts ... )
2022-10-13 12:34:02 +02:00
allAssessedAlerts = append ( allAssessedAlerts , assessedAlerts ... )
2022-08-12 11:59:47 +02:00
vulnerabilitiesCount += vulCount
allLibraries = append ( allLibraries , libraries ... )
2021-02-03 14:52:48 +01:00
}
2022-02-23 09:30:19 +01:00
log . Entry ( ) . Debugf ( "Aggregated %v alerts for scanned projects" , len ( allAlerts ) )
2023-02-07 16:10:21 +01:00
}
2021-02-10 16:18:00 +01:00
2023-02-07 16:10:21 +01:00
reportPaths , errors := reportGitHubIssuesAndCreateReports (
ctx ,
config ,
utils ,
scan ,
allAlerts ,
allLibraries ,
allAssessedAlerts ,
cvssSeverityLimit ,
vulnerabilitiesCount ,
)
2022-02-23 09:30:19 +01:00
2023-02-07 16:10:21 +01:00
allOccurredErrors = append ( allOccurredErrors , errors ... )
2022-02-23 09:30:19 +01:00
2023-02-07 16:10:21 +01:00
if len ( allOccurredErrors ) > 0 {
if vulnerabilitiesCount > 0 {
log . SetErrorCategory ( log . ErrorCompliance )
2021-02-10 16:18:00 +01:00
}
2023-02-07 16:10:21 +01:00
return reportPaths , fmt . Errorf ( strings . Join ( allOccurredErrors , ": " ) )
}
2021-02-10 16:18:00 +01:00
2023-02-07 16:10:21 +01:00
return reportPaths , nil
}
func collectVulnsAndLibsForProject (
config * ScanOptions ,
cvssSeverityLimit float64 ,
project ws . Project ,
sys whitesource ,
assessments * [ ] format . Assessment ,
influx * whitesourceExecuteScanInflux ,
) (
int ,
[ ] ws . Alert ,
[ ] ws . Alert ,
[ ] ws . Library ,
[ ] string ,
) {
var errorsOccurred [ ] string
vulCount , alerts , assessedAlerts , err := checkProjectSecurityViolations ( config , cvssSeverityLimit , project , sys , assessments , influx )
if err != nil {
errorsOccurred = append ( errorsOccurred , fmt . Sprint ( err ) )
}
// collect all libraries detected in all related projects and errors
libraries , err := sys . GetProjectHierarchy ( project . Token , true )
if err != nil {
errorsOccurred = append ( errorsOccurred , fmt . Sprint ( err ) )
}
log . Entry ( ) . Debugf ( "Collected %v libraries for project %v" , len ( libraries ) , project . Name )
return vulCount , alerts , assessedAlerts , libraries , errorsOccurred
}
func reportGitHubIssuesAndCreateReports (
ctx context . Context ,
config * ScanOptions ,
utils whitesourceUtils ,
scan * ws . Scan ,
allAlerts [ ] ws . Alert ,
allLibraries [ ] ws . Library ,
allAssessedAlerts [ ] ws . Alert ,
cvssSeverityLimit float64 ,
vulnerabilitiesCount int ,
) ( [ ] piperutils . Path , [ ] string ) {
errorsOccured := make ( [ ] string , 0 )
reportPaths := make ( [ ] piperutils . Path , 0 )
if config . CreateResultIssue && vulnerabilitiesCount > 0 && len ( config . GithubToken ) > 0 && len ( config . GithubAPIURL ) > 0 && len ( config . Owner ) > 0 && len ( config . Repository ) > 0 {
log . Entry ( ) . Debugf ( "Creating result issues for %v alert(s)" , vulnerabilitiesCount )
issueDetails := make ( [ ] reporting . IssueDetail , len ( allAlerts ) )
piperutils . CopyAtoB ( allAlerts , issueDetails )
gh := reporting . GitHub {
Owner : & config . Owner ,
Repository : & config . Repository ,
Assignees : & config . Assignees ,
IssueService : utils . GetIssueService ( ) ,
SearchService : utils . GetSearchService ( ) ,
2022-08-09 13:56:01 +02:00
}
2023-02-07 16:10:21 +01:00
if err := gh . UploadMultipleReports ( ctx , & issueDetails ) ; err != nil {
2022-08-09 13:56:01 +02:00
errorsOccured = append ( errorsOccured , fmt . Sprint ( err ) )
}
2023-02-07 16:10:21 +01:00
}
2022-08-09 13:56:01 +02:00
2023-02-07 16:10:21 +01:00
scanReport := ws . CreateCustomVulnerabilityReport ( config . ProductName , scan , & allAlerts , cvssSeverityLimit )
paths , err := ws . WriteCustomVulnerabilityReports ( config . ProductName , scan , scanReport , utils )
if err != nil {
errorsOccured = append ( errorsOccured , fmt . Sprint ( err ) )
2020-09-29 12:44:31 +02:00
}
2023-02-07 16:10:21 +01:00
reportPaths = append ( reportPaths , paths ... )
sarif := ws . CreateSarifResultFile ( scan , & allAlerts )
paths , err = ws . WriteSarifFile ( sarif , utils )
if err != nil {
errorsOccured = append ( errorsOccured , fmt . Sprint ( err ) )
}
reportPaths = append ( reportPaths , paths ... )
sbom , err := ws . CreateCycloneSBOM ( scan , & allLibraries , & allAlerts , & allAssessedAlerts )
if err != nil {
errorsOccured = append ( errorsOccured , fmt . Sprint ( err ) )
}
paths , err = ws . WriteCycloneSBOM ( sbom , utils )
if err != nil {
errorsOccured = append ( errorsOccured , fmt . Sprint ( err ) )
}
reportPaths = append ( reportPaths , paths ... )
return reportPaths , errorsOccured
2020-09-29 12:44:31 +02:00
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
2022-08-09 13:56:01 +02:00
// read assessments from file and expose them to match alerts and filter them before processing
func readAssessmentsFromFile ( assessmentFilePath string , utils whitesourceUtils ) * [ ] format . Assessment {
exists , err := utils . FileExists ( assessmentFilePath )
if err != nil {
log . SetErrorCategory ( log . ErrorConfiguration )
2022-10-13 12:34:02 +02:00
log . Entry ( ) . WithError ( err ) . Errorf ( "unable to check existence of assessment file at '%s'" , assessmentFilePath )
2022-08-09 13:56:01 +02:00
}
assessmentFile , err := utils . Open ( assessmentFilePath )
if exists && err != nil {
log . SetErrorCategory ( log . ErrorConfiguration )
2022-10-13 12:34:02 +02:00
log . Entry ( ) . WithError ( err ) . Errorf ( "unable to open assessment file at '%s'" , assessmentFilePath )
2022-08-09 13:56:01 +02:00
}
assessments := & [ ] format . Assessment { }
if exists {
defer assessmentFile . Close ( )
assessments , err = format . ReadAssessments ( assessmentFile )
if err != nil {
log . SetErrorCategory ( log . ErrorConfiguration )
2022-10-13 12:34:02 +02:00
log . Entry ( ) . WithError ( err ) . Errorf ( "unable to parse assessment file at '%s'" , assessmentFilePath )
2022-08-09 13:56:01 +02:00
}
}
return assessments
}
2022-10-13 12:34:02 +02:00
// checkSecurityViolations checks security violations and returns an error if the configured severity limit is crossed. Besides the potential error the list of unassessed and assessed alerts are being returned to allow generating reports and issues from the data.
func checkProjectSecurityViolations ( config * ScanOptions , cvssSeverityLimit float64 , project ws . Project , sys whitesource , assessments * [ ] format . Assessment , influx * whitesourceExecuteScanInflux ) ( int , [ ] ws . Alert , [ ] ws . Alert , error ) {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
// get project alerts (vulnerabilities)
2022-10-13 12:34:02 +02:00
assessedAlerts := [ ] ws . Alert { }
2021-02-10 16:18:00 +01:00
alerts , err := sys . GetProjectAlertsByType ( project . Token , "SECURITY_VULNERABILITY" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if err != nil {
2022-10-13 12:34:02 +02:00
return 0 , alerts , assessedAlerts , fmt . Errorf ( "failed to retrieve project alerts from WhiteSource: %w" , err )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2022-08-09 13:56:01 +02:00
// filter alerts related to existing assessments
filteredAlerts := [ ] ws . Alert { }
2022-10-13 12:34:02 +02:00
if assessments != nil && len ( * assessments ) > 0 {
2022-08-09 13:56:01 +02:00
for _ , alert := range alerts {
2022-10-13 12:34:02 +02:00
if result , err := alert . ContainedIn ( assessments ) ; err == nil && ! result {
2022-08-09 13:56:01 +02:00
filteredAlerts = append ( filteredAlerts , alert )
2022-10-13 12:34:02 +02:00
} else if alert . Assessment != nil {
log . Entry ( ) . Debugf ( "Matched assessment with status %v and analysis %v to vulnerability %v affecting packages %v" , alert . Assessment . Status , alert . Assessment . Analysis , alert . Assessment . Vulnerability , alert . Assessment . Purls )
assessedAlerts = append ( assessedAlerts , alert )
2022-08-09 13:56:01 +02:00
}
}
2022-10-13 12:34:02 +02:00
// intentionally overwriting original list of alerts with those remaining unassessed after processing of assessments
2022-08-09 13:56:01 +02:00
alerts = filteredAlerts
}
2022-02-23 09:30:19 +01:00
severeVulnerabilities , nonSevereVulnerabilities := ws . CountSecurityVulnerabilities ( & alerts , cvssSeverityLimit )
2021-03-10 16:00:53 +01:00
influx . whitesource_data . fields . minor_vulnerabilities = nonSevereVulnerabilities
influx . whitesource_data . fields . major_vulnerabilities = severeVulnerabilities
influx . whitesource_data . fields . vulnerabilities = nonSevereVulnerabilities + severeVulnerabilities
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if nonSevereVulnerabilities > 0 {
log . Entry ( ) . Warnf ( "WARNING: %v Open Source Software Security vulnerabilities with " +
2020-09-29 12:44:31 +02:00
"CVSS score below threshold %.1f detected in project %s." , nonSevereVulnerabilities ,
cvssSeverityLimit , project . Name )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
} else if len ( alerts ) == 0 {
log . Entry ( ) . Infof ( "No Open Source Software Security vulnerabilities detected in project %s" ,
2020-09-29 12:44:31 +02:00
project . Name )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
// https://github.com/SAP/jenkins-library/blob/master/vars/whitesourceExecuteScan.groovy#L558
if severeVulnerabilities > 0 {
2022-07-18 14:36:29 +02:00
if config . FailOnSevereVulnerabilities {
log . SetErrorCategory ( log . ErrorCompliance )
2022-10-13 12:34:02 +02:00
return severeVulnerabilities , alerts , assessedAlerts , fmt . Errorf ( "%v Open Source Software Security vulnerabilities with CVSS score greater or equal to %.1f detected in project %s" , severeVulnerabilities , cvssSeverityLimit , project . Name )
2022-07-18 14:36:29 +02:00
}
log . Entry ( ) . Infof ( "%v Open Source Software Security vulnerabilities with CVSS score greater or equal to %.1f detected in project %s" , severeVulnerabilities , cvssSeverityLimit , project . Name )
log . Entry ( ) . Info ( "Step will only create data but not fail due to setting failOnSevereVulnerabilities: false" )
2022-10-13 12:34:02 +02:00
return severeVulnerabilities , alerts , assessedAlerts , nil
2020-09-29 12:44:31 +02:00
}
2022-10-13 12:34:02 +02:00
return 0 , alerts , assessedAlerts , nil
2021-02-10 16:18:00 +01:00
}
2020-09-18 11:54:45 +02:00
func aggregateVersionWideLibraries ( config * ScanOptions , utils whitesourceUtils , sys whitesource ) error {
2021-02-10 16:18:00 +01:00
log . Entry ( ) . Infof ( "Aggregating list of libraries used for all projects with version: %s" , config . Version )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
projects , err := sys . GetProjectsMetaInfo ( config . ProductToken )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get projects meta info" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-09-18 11:54:45 +02:00
versionWideLibraries := map [ string ] [ ] ws . Library { } // maps project name to slice of libraries
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
for _ , project := range projects {
projectVersion := strings . Split ( project . Name , " - " ) [ 1 ]
projectName := strings . Split ( project . Name , " - " ) [ 0 ]
2021-02-10 16:18:00 +01:00
if projectVersion == config . Version {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
libs , err := sys . GetProjectLibraryLocations ( project . Token )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get project library locations" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
log . Entry ( ) . Infof ( "Found project: %s with %v libraries." , project . Name , len ( libs ) )
versionWideLibraries [ projectName ] = libs
}
}
2020-09-18 11:54:45 +02:00
if err := newLibraryCSVReport ( versionWideLibraries , config , utils ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed toget new libary CSV report" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
return nil
}
2020-09-18 11:54:45 +02:00
func aggregateVersionWideVulnerabilities ( config * ScanOptions , utils whitesourceUtils , sys whitesource ) error {
2021-02-10 16:18:00 +01:00
log . Entry ( ) . Infof ( "Aggregating list of vulnerabilities for all projects with version: %s" , config . Version )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
projects , err := sys . GetProjectsMetaInfo ( config . ProductToken )
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get projects meta info" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-09-18 11:54:45 +02:00
var versionWideAlerts [ ] ws . Alert // all alerts for a given project version
projectNames := ` ` // holds all project tokens considered a part of the report for debugging
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
for _ , project := range projects {
projectVersion := strings . Split ( project . Name , " - " ) [ 1 ]
2021-02-10 16:18:00 +01:00
if projectVersion == config . Version {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
projectNames += project . Name + "\n"
2021-06-17 13:58:10 +02:00
alerts , err := sys . GetProjectAlertsByType ( project . Token , "SECURITY_VULNERABILITY" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
if err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to get project alerts by type" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
log . Entry ( ) . Infof ( "Found project: %s with %v vulnerabilities." , project . Name , len ( alerts ) )
versionWideAlerts = append ( versionWideAlerts , alerts ... )
}
}
2021-02-10 16:18:00 +01:00
reportPath := filepath . Join ( ws . ReportsDirectory , "project-names-aggregated.txt" )
2022-07-18 14:36:29 +02:00
if err := utils . FileWrite ( reportPath , [ ] byte ( projectNames ) , 0 o666 ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to write report: %s" , reportPath )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2020-09-18 11:54:45 +02:00
if err := newVulnerabilityExcelReport ( versionWideAlerts , config , utils ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to create new vulnerability excel report" )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
return nil
}
2020-09-29 12:44:31 +02:00
const wsReportTimeStampLayout = "20060102-150405"
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
// outputs an slice of alerts to an excel file
2020-09-18 11:54:45 +02:00
func newVulnerabilityExcelReport ( alerts [ ] ws . Alert , config * ScanOptions , utils whitesourceUtils ) error {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
file := excelize . NewFile ( )
streamWriter , err := file . NewStreamWriter ( "Sheet1" )
if err != nil {
return err
}
styleID , err := file . NewStyle ( ` { "font": { "color":"#777777"}} ` )
if err != nil {
return err
}
2020-09-29 12:44:31 +02:00
if err := fillVulnerabilityExcelReport ( alerts , streamWriter , styleID ) ; err != nil {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return err
}
2020-09-29 12:44:31 +02:00
if err := streamWriter . Flush ( ) ; err != nil {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return err
}
2020-09-29 12:44:31 +02:00
2022-07-18 14:36:29 +02:00
if err := utils . MkdirAll ( ws . ReportsDirectory , 0 o777 ) ; err != nil {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return err
}
2020-09-29 12:44:31 +02:00
2021-02-10 16:18:00 +01:00
fileName := filepath . Join ( ws . ReportsDirectory ,
2020-09-29 12:44:31 +02:00
fmt . Sprintf ( "vulnerabilities-%s.xlsx" , utils . Now ( ) . Format ( wsReportTimeStampLayout ) ) )
2022-07-18 14:36:29 +02:00
stream , err := utils . FileOpen ( fileName , os . O_WRONLY | os . O_TRUNC | os . O_CREATE , 0 o666 )
2020-09-29 12:44:31 +02:00
if err != nil {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return err
}
2020-09-29 12:44:31 +02:00
if err := file . Write ( stream ) ; err != nil {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
return err
}
2021-06-09 15:56:56 +02:00
filePath := piperutils . Path { Name : "aggregated-vulnerabilities" , Target : fileName }
2022-08-09 10:57:02 +02:00
piperutils . PersistReportsAndLinks ( "whitesourceExecuteScan" , "" , utils , [ ] piperutils . Path { filePath } , nil )
2020-09-29 12:44:31 +02:00
return nil
}
func fillVulnerabilityExcelReport ( alerts [ ] ws . Alert , streamWriter * excelize . StreamWriter , styleID int ) error {
rows := [ ] struct {
axis string
title string
} {
{ "A1" , "Severity" } ,
{ "B1" , "Library" } ,
2021-06-09 15:56:56 +02:00
{ "C1" , "Vulnerability Id" } ,
{ "D1" , "CVSS 3" } ,
{ "E1" , "Project" } ,
{ "F1" , "Resolution" } ,
2020-09-29 12:44:31 +02:00
}
for _ , row := range rows {
err := streamWriter . SetRow ( row . axis , [ ] interface { } { excelize . Cell { StyleID : styleID , Value : row . title } } )
if err != nil {
return err
}
}
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
for i , alert := range alerts {
2021-06-09 15:56:56 +02:00
row := make ( [ ] interface { } , 6 )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
vuln := alert . Vulnerability
2021-06-09 15:56:56 +02:00
row [ 0 ] = vuln . CVSS3Severity
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
row [ 1 ] = alert . Library . Filename
2021-06-09 15:56:56 +02:00
row [ 2 ] = vuln . Name
row [ 3 ] = vuln . CVSS3Score
row [ 4 ] = alert . Project
row [ 5 ] = vuln . FixResolutionText
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
cell , _ := excelize . CoordinatesToCellName ( 1 , i + 2 )
if err := streamWriter . SetRow ( cell , row ) ; err != nil {
2020-09-29 12:44:31 +02:00
log . Entry ( ) . Errorf ( "failed to write alert row: %v" , err )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
}
return nil
}
2021-02-10 16:18:00 +01:00
// outputs an slice of libraries to an excel file based on projects with version == config.Version
2020-09-18 11:54:45 +02:00
func newLibraryCSVReport ( libraries map [ string ] [ ] ws . Library , config * ScanOptions , utils whitesourceUtils ) error {
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
output := "Library Name, Project Name\n"
for projectName , libraries := range libraries {
log . Entry ( ) . Infof ( "Writing %v libraries for project %s to excel report.." , len ( libraries ) , projectName )
for _ , library := range libraries {
output += library . Name + ", " + projectName + "\n"
}
}
// Ensure reporting directory exists
2022-07-18 14:36:29 +02:00
if err := utils . MkdirAll ( ws . ReportsDirectory , 0 o777 ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to create directories: %s" , ws . ReportsDirectory )
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
// Write result to file
2021-02-10 16:18:00 +01:00
fileName := fmt . Sprintf ( "%s/libraries-%s.csv" , ws . ReportsDirectory ,
2020-09-29 12:44:31 +02:00
utils . Now ( ) . Format ( wsReportTimeStampLayout ) )
2022-07-18 14:36:29 +02:00
if err := utils . FileWrite ( fileName , [ ] byte ( output ) , 0 o666 ) ; err != nil {
2021-06-30 11:11:41 +02:00
return errors . Wrapf ( err , "failed to write file: %s" , fileName )
2020-09-29 12:44:31 +02:00
}
2021-06-09 15:56:56 +02:00
filePath := piperutils . Path { Name : "aggregated-libraries" , Target : fileName }
2022-08-09 10:57:02 +02:00
piperutils . PersistReportsAndLinks ( "whitesourceExecuteScan" , "" , utils , [ ] piperutils . Path { filePath } , nil )
2020-09-29 12:44:31 +02:00
return nil
}
2021-02-10 16:18:00 +01:00
// persistScannedProjects writes all actually scanned WhiteSource project names as list
// into the Common Pipeline Environment, from where it can be used by sub-sequent steps.
2020-11-02 08:51:58 +01:00
func persistScannedProjects ( config * ScanOptions , scan * ws . Scan , commonPipelineEnvironment * whitesourceExecuteScanCommonPipelineEnvironment ) {
2022-07-21 09:04:21 +02:00
var projectNames [ ] string
2020-09-29 12:44:31 +02:00
if config . ProjectName != "" {
2021-02-10 16:18:00 +01:00
projectNames = [ ] string { config . ProjectName + " - " + config . Version }
2020-09-29 12:44:31 +02:00
} else {
2021-04-15 07:45:06 +02:00
projectNames = scan . ScannedProjectNames ( )
2020-09-29 12:44:31 +02:00
}
2020-11-02 08:51:58 +01:00
commonPipelineEnvironment . custom . whitesourceProjectNames = projectNames
Whitesource scan (MVP) (#1658)
* Whitesource MVP for Gradle, Golang, and NPM/Yarn
* Refactoring
* Refactor and cleanup, better error checking
* publish stepResults, use pkg/versioning, bubble up errors, add gomod versioning support
* Run gofmt and cleanup comments
* Resolve PR comments
* Update resources/metadata/whitesource.yaml
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
* Only determine project coordinates if they are missing
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
* Gradle versioning artifact
* fix gradle artifact version regexp and refactor
* Fix token extraction from output buffer
* Fix some issues with pip and jsonfile versioning logic
* Remove useless spacing
* Remove unnecessary test file and fix naming style for JSONDescriptor
* Automatically download wss-unified-agent if file does not exist
* adds downloadVulnerabilityReport, checkSecurityViolations, minor refactoring
* adds config.ReportDirectoryName, improves readability
* Version-wide reporting for vulnerabilities and list of libraries.
* Refactor and improve build accuracy
* fix sed command
* Add includes file pattern config option
* Adds --exclude command line flag
* run go mod tidy and regenerate step framework
* Fix unit tests
* revert changes
* poll project status before downloading reports
* merge with master
* go mod tidy, go fmt, and fix whitesource unit test
* sync go.mod
* sync go.mod again
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-06-30 22:54:13 -07:00
}
2021-06-23 15:05:00 +02:00
// create toolrecord file for whitesource
2022-08-09 10:57:02 +02:00
func createToolRecordWhitesource ( utils whitesourceUtils , workspace string , config * whitesourceExecuteScanOptions , scan * ws . Scan ) ( string , error ) {
record := toolrecord . New ( utils , workspace , "whitesource" , config . ServiceURL )
2021-09-10 13:20:54 +02:00
wsUiRoot := "https://saas.whitesourcesoftware.com"
productURL := wsUiRoot + "/Wss/WSS.html#!product;token=" + config . ProductToken
2021-06-23 15:05:00 +02:00
err := record . AddKeyData ( "product" ,
config . ProductToken ,
config . ProductName ,
productURL )
if err != nil {
return "" , err
}
2021-09-09 10:50:33 +02:00
max_idx := 0
for idx , project := range scan . ScannedProjects ( ) {
max_idx = idx
name := project . Name
token := project . Token
projectURL := ""
if token != "" {
2021-09-10 13:20:54 +02:00
projectURL = wsUiRoot + "/Wss/WSS.html#!project;token=" + token
2021-09-09 10:50:33 +02:00
} else {
// token is empty, provide a dummy to have an indication
token = "unknown"
}
err = record . AddKeyData ( "project" ,
token ,
name ,
projectURL )
if err != nil {
return "" , err
}
}
// set overall display data to product if there
// is more than one project
if max_idx > 1 {
record . SetOverallDisplayData ( config . ProductName , productURL )
}
2021-06-23 15:05:00 +02:00
err = record . Persist ( )
if err != nil {
return "" , err
}
return record . GetFileName ( ) , nil
}