2020-05-26 17:30:45 +02:00
|
|
|
package whitesource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2020-10-29 10:21:01 +02:00
|
|
|
"time"
|
2020-05-26 17:30:45 +02:00
|
|
|
|
|
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2021-02-10 17:18:00 +02:00
|
|
|
// ReportsDirectory defines the subfolder for the WhiteSource reports which are generated
|
|
|
|
const ReportsDirectory = "whitesource"
|
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
// Product defines a WhiteSource product with name and token
|
|
|
|
type Product struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
CreationDate string `json:"creationDate,omitempty"`
|
|
|
|
LastUpdateDate string `json:"lastUpdatedDate,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:21:01 +02:00
|
|
|
// Assignment describes a list of UserAssignments and GroupAssignments which can be attributed to a WhiteSource Product.
|
|
|
|
type Assignment struct {
|
|
|
|
UserAssignments []UserAssignment `json:"userAssignments,omitempty"`
|
|
|
|
GroupAssignments []GroupAssignment `json:"groupAssignments,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserAssignment holds an email address for a WhiteSource user
|
|
|
|
// which can be assigned to a WhiteSource Product in a specific role.
|
|
|
|
type UserAssignment struct {
|
|
|
|
Email string `json:"email,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupAssignment refers to the name of a particular group in WhiteSource.
|
|
|
|
type GroupAssignment struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
}
|
|
|
|
|
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-07-01 07:54:13 +02:00
|
|
|
// Alert
|
|
|
|
type Alert struct {
|
|
|
|
Vulnerability Vulnerability `json:"vulnerability"`
|
|
|
|
Library Library `json:"library,omitempty"`
|
|
|
|
Project string `json:"project,omitempty"`
|
|
|
|
CreationDate string `json:"creation_date,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Library
|
|
|
|
type Library struct {
|
2021-02-10 17:18:00 +02:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Filename string `json:"filename,omitempty"`
|
|
|
|
ArtifactID string `json:"artifactId,omitempty"`
|
|
|
|
GroupID string `json:"groupId,omitempty"`
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Project string `json:"project,omitempty"`
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2021-02-10 17:18:00 +02:00
|
|
|
// Vulnerability defines a vulnerability as returned by WhiteSource
|
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-07-01 07:54:13 +02:00
|
|
|
type Vulnerability struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Severity string `json:"severity,omitempty"`
|
2021-02-10 17:18:00 +02:00
|
|
|
Score float64 `json:"score,omitempty"`
|
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-07-01 07:54:13 +02:00
|
|
|
CVSS3Severity string `json:"cvss3_severity,omitempty"`
|
|
|
|
CVSS3Score float64 `json:"cvss3_score,omitempty"`
|
|
|
|
PublishDate string `json:"publishDate,omitempty"`
|
2021-02-10 17:18:00 +02:00
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
TopFix Fix `json:"topFix,omitempty"`
|
|
|
|
AllFixes []Fix `json:"allFixes,omitempty"`
|
|
|
|
Level string `json:"level,omitempty"`
|
|
|
|
FixResolutionText string `json:"fixResolutionText,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix defines a Fix as returned by WhiteSource
|
|
|
|
type Fix struct {
|
|
|
|
Vulnerability string `json:"vulnerability,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Origin string `json:"origin,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
FixResolution string `json:"fixResolution,omitempty"`
|
|
|
|
Date string `json:"date,omitempty"`
|
|
|
|
Message string `json:"message,omitempty"`
|
|
|
|
ExtraData string `json:"extraData,omitempty"`
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
// Project defines a WhiteSource project with name and token
|
|
|
|
type Project struct {
|
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-07-01 07:54:13 +02:00
|
|
|
ID int64 `json:"id"`
|
2020-05-26 17:30:45 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
PluginName string `json:"pluginName"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
UploadedBy string `json:"uploadedBy"`
|
|
|
|
CreationDate string `json:"creationDate,omitempty"`
|
|
|
|
LastUpdateDate string `json:"lastUpdatedDate,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request defines a request object to be sent to the WhiteSource system
|
|
|
|
type Request struct {
|
2020-10-29 10:21:01 +02:00
|
|
|
RequestType string `json:"requestType,omitempty"`
|
|
|
|
UserKey string `json:"userKey,omitempty"`
|
|
|
|
ProductToken string `json:"productToken,omitempty"`
|
|
|
|
ProductName string `json:"productName,omitempty"`
|
|
|
|
ProjectToken string `json:"projectToken,omitempty"`
|
|
|
|
OrgToken string `json:"orgToken,omitempty"`
|
|
|
|
Format string `json:"format,omitempty"`
|
2021-02-10 17:18:00 +02:00
|
|
|
AlertType string `json:"alertType,omitempty"`
|
2020-10-29 10:21:01 +02:00
|
|
|
ProductAdmins *Assignment `json:"productAdmins,omitempty"`
|
|
|
|
ProductMembership *Assignment `json:"productMembership,omitempty"`
|
|
|
|
AlertsEmailReceivers *Assignment `json:"alertsEmailReceivers,omitempty"`
|
|
|
|
ProductApprovers *Assignment `json:"productApprovers,omitempty"`
|
|
|
|
ProductIntegrators *Assignment `json:"productIntegrators,omitempty"`
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// System defines a WhiteSource System including respective tokens (e.g. org token, user token)
|
2020-05-26 17:30:45 +02:00
|
|
|
type System struct {
|
2020-09-18 11:54:45 +02:00
|
|
|
httpClient piperhttp.Sender
|
|
|
|
orgToken string
|
|
|
|
serverURL string
|
|
|
|
userToken string
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:21:01 +02:00
|
|
|
// DateTimeLayout is the layout of the time format used by the WhiteSource API.
|
|
|
|
const DateTimeLayout = "2006-01-02 15:04:05 -0700"
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// NewSystem constructs a new System instance
|
2020-10-29 10:21:01 +02:00
|
|
|
func NewSystem(serverURL, orgToken, userToken string, timeout time.Duration) *System {
|
|
|
|
httpClient := &piperhttp.Client{}
|
|
|
|
httpClient.SetOptions(piperhttp.ClientOptions{TransportTimeout: timeout})
|
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-07-01 07:54:13 +02:00
|
|
|
return &System{
|
2020-09-18 11:54:45 +02:00
|
|
|
serverURL: serverURL,
|
|
|
|
orgToken: orgToken,
|
|
|
|
userToken: userToken,
|
2020-10-29 10:21:01 +02:00
|
|
|
httpClient: httpClient,
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
// GetProductsMetaInfo retrieves meta information for all WhiteSource products a user has access to
|
|
|
|
func (s *System) GetProductsMetaInfo() ([]Product, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
ProductVitals []Product `json:"productVitals"`
|
|
|
|
}{
|
|
|
|
ProductVitals: []Product{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getOrganizationProductVitals",
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
2020-05-26 17:30:45 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return wsResponse.ProductVitals, err
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return wsResponse.ProductVitals, nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// GetProductByName retrieves meta information for a specific WhiteSource product
|
|
|
|
func (s *System) GetProductByName(productName string) (Product, error) {
|
2020-05-26 17:30:45 +02:00
|
|
|
products, err := s.GetProductsMetaInfo()
|
|
|
|
if err != nil {
|
|
|
|
return Product{}, errors.Wrap(err, "failed to retrieve WhiteSource products")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range products {
|
|
|
|
if p.Name == productName {
|
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Product{}, fmt.Errorf("product '%v' not found in WhiteSource", productName)
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:21:01 +02:00
|
|
|
// CreateProduct creates a new WhiteSource product and returns its product token.
|
|
|
|
func (s *System) CreateProduct(productName string) (string, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
ProductToken string `json:"productToken"`
|
|
|
|
}{
|
|
|
|
ProductToken: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "createProduct",
|
|
|
|
ProductName: productName,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return "", err
|
2020-10-29 10:21:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return wsResponse.ProductToken, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetProductAssignments assigns various types of membership to a WhiteSource Product.
|
|
|
|
func (s *System) SetProductAssignments(productToken string, membership, admins, alertReceivers *Assignment) error {
|
|
|
|
req := Request{
|
|
|
|
RequestType: "setProductAssignments",
|
|
|
|
ProductToken: productToken,
|
|
|
|
ProductMembership: membership,
|
|
|
|
ProductAdmins: admins,
|
|
|
|
AlertsEmailReceivers: alertReceivers,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.sendRequestAndDecodeJSON(req, nil)
|
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return err
|
2020-10-29 10:21:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// GetProjectsMetaInfo retrieves the registered projects for a specific WhiteSource product
|
2020-05-26 17:30:45 +02:00
|
|
|
func (s *System) GetProjectsMetaInfo(productToken string) ([]Project, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
ProjectVitals []Project `json:"projectVitals"`
|
|
|
|
}{
|
|
|
|
ProjectVitals: []Project{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProductProjectVitals",
|
|
|
|
ProductToken: productToken,
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
2020-05-26 17:30:45 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return nil, err
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return wsResponse.ProjectVitals, 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-07-01 07:54:13 +02:00
|
|
|
// GetProjectToken returns the project token for a project with a given name
|
2020-05-26 17:30:45 +02:00
|
|
|
func (s *System) GetProjectToken(productToken, projectName string) (string, 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-07-01 07:54:13 +02:00
|
|
|
project, err := s.GetProjectByName(productToken, projectName)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-09-18 11:54:45 +02:00
|
|
|
return project.Token, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// GetProjectByToken returns project meta info given a project token
|
|
|
|
func (s *System) GetProjectByToken(projectToken string) (Project, 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-07-01 07:54:13 +02:00
|
|
|
wsResponse := struct {
|
|
|
|
ProjectVitals []Project `json:"projectVitals"`
|
|
|
|
}{
|
|
|
|
ProjectVitals: []Project{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectVitals",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
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-07-01 07:54:13 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return Project{}, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
if len(wsResponse.ProjectVitals) == 0 {
|
|
|
|
return Project{}, errors.Wrapf(err, "no project with token '%s' found in WhiteSource", projectToken)
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
return wsResponse.ProjectVitals[0], 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// GetProjectByName fetches all projects and returns the one matching the given projectName, or none, if not found
|
|
|
|
func (s *System) GetProjectByName(productToken, projectName string) (Project, error) {
|
2020-05-26 17:30:45 +02:00
|
|
|
projects, err := s.GetProjectsMetaInfo(productToken)
|
|
|
|
if err != nil {
|
2020-09-18 11:54:45 +02:00
|
|
|
return Project{}, errors.Wrap(err, "failed to retrieve WhiteSource project 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
for _, project := range projects {
|
|
|
|
if projectName == project.Name {
|
|
|
|
return project, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// returns empty project and no error. The reason seems to be that it makes polling until the project exists easier.
|
|
|
|
return Project{}, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
// GetProjectsByIDs retrieves all projects for the given productToken and filters them by the given project ids
|
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-07-01 07:54:13 +02:00
|
|
|
func (s *System) GetProjectsByIDs(productToken string, projectIDs []int64) ([]Project, error) {
|
|
|
|
projects, err := s.GetProjectsMetaInfo(productToken)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to retrieve WhiteSource project meta info")
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
var projectsMatched []Project
|
2020-05-26 17:30:45 +02:00
|
|
|
for _, project := range projects {
|
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-07-01 07:54:13 +02:00
|
|
|
for _, projectID := range projectIDs {
|
|
|
|
if projectID == project.ID {
|
|
|
|
projectsMatched = append(projectsMatched, project)
|
2020-09-18 11:54:45 +02:00
|
|
|
break
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
2020-05-26 17:30:45 +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-07-01 07:54:13 +02:00
|
|
|
|
|
|
|
return projectsMatched, nil
|
2020-05-26 17:30:45 +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-07-01 07:54:13 +02:00
|
|
|
// GetProjectTokens returns the project tokens matching a given a slice of project names
|
2020-05-26 17:30:45 +02:00
|
|
|
func (s *System) GetProjectTokens(productToken string, projectNames []string) ([]string, error) {
|
|
|
|
projectTokens := []string{}
|
|
|
|
projects, err := s.GetProjectsMetaInfo(productToken)
|
|
|
|
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-07-01 07:54:13 +02:00
|
|
|
return nil, errors.Wrap(err, "failed to retrieve WhiteSource project meta info")
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, project := range projects {
|
|
|
|
for _, projectName := range projectNames {
|
|
|
|
if projectName == project.Name {
|
|
|
|
projectTokens = append(projectTokens, project.Token)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 11:33:10 +02:00
|
|
|
|
|
|
|
if len(projectNames) > 0 && len(projectTokens) == 0 {
|
|
|
|
return projectTokens, fmt.Errorf("no project token(s) found for provided projects")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(projectNames) > 0 && len(projectNames) != len(projectTokens) {
|
|
|
|
return projectTokens, fmt.Errorf("not all project token(s) found for provided projects")
|
|
|
|
}
|
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
return projectTokens, 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-07-01 07:54:13 +02:00
|
|
|
// GetProductName returns the product name for a given product token
|
2020-05-26 17:30:45 +02:00
|
|
|
func (s *System) GetProductName(productToken string) (string, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
ProductTags []Product `json:"productTags"`
|
|
|
|
}{
|
|
|
|
ProductTags: []Product{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProductTags",
|
|
|
|
ProductToken: productToken,
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
2020-05-26 17:30:45 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return "", err
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
if len(wsResponse.ProductTags) == 0 {
|
|
|
|
return "", nil // fmt.Errorf("no product with token '%s' found in WhiteSource", productToken)
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
return wsResponse.ProductTags[0].Name, nil
|
2020-05-26 17:30:45 +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-07-01 07:54:13 +02:00
|
|
|
// GetProjectRiskReport
|
|
|
|
func (s *System) GetProjectRiskReport(projectToken string) ([]byte, error) {
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectRiskReport",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
respBody, err := s.sendRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "WhiteSource getProjectRiskReport request failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return respBody, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetProjectVulnerabilityReport
|
|
|
|
func (s *System) GetProjectVulnerabilityReport(projectToken string, format string) ([]byte, error) {
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectVulnerabilityReport",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
Format: format,
|
|
|
|
}
|
|
|
|
|
|
|
|
respBody, err := s.sendRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "WhiteSource getProjectVulnerabilityReport request failed")
|
|
|
|
}
|
|
|
|
|
|
|
|
return respBody, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetProjectAlerts
|
|
|
|
func (s *System) GetProjectAlerts(projectToken string) ([]Alert, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
Alerts []Alert `json:"alerts"`
|
|
|
|
}{
|
|
|
|
Alerts: []Alert{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectAlerts",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
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-07-01 07:54:13 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return wsResponse.Alerts, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetProjectAlertsByType returns all alerts of a certain type for a given project
|
|
|
|
func (s *System) GetProjectAlertsByType(projectToken, alertType string) ([]Alert, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
Alerts []Alert `json:"alerts"`
|
|
|
|
}{
|
|
|
|
Alerts: []Alert{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectAlertsByType",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
AlertType: alertType,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return wsResponse.Alerts, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetProjectLibraryLocations
|
|
|
|
func (s *System) GetProjectLibraryLocations(projectToken string) ([]Library, error) {
|
|
|
|
wsResponse := struct {
|
|
|
|
Libraries []Library `json:"libraryLocations"`
|
|
|
|
}{
|
|
|
|
Libraries: []Library{},
|
|
|
|
}
|
|
|
|
|
|
|
|
req := Request{
|
|
|
|
RequestType: "getProjectLibraryLocations",
|
|
|
|
ProjectToken: projectToken,
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
err := s.sendRequestAndDecodeJSON(req, &wsResponse)
|
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-07-01 07:54:13 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return nil, 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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
return wsResponse.Libraries, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *System) sendRequestAndDecodeJSON(req Request, result interface{}) error {
|
|
|
|
respBody, err := s.sendRequest(req)
|
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-07-01 07:54:13 +02:00
|
|
|
if err != nil {
|
2021-02-10 17:18:00 +02:00
|
|
|
return errors.Wrap(err, "sending whiteSource request failed")
|
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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
log.Entry().Debugf("response: %v", string(respBody))
|
|
|
|
|
|
|
|
errorResponse := struct {
|
2020-10-29 10:21:01 +02:00
|
|
|
ErrorCode int `json:"errorCode"`
|
2020-09-18 11:54:45 +02:00
|
|
|
ErrorMessage string `json:"errorMessage"`
|
|
|
|
}{}
|
|
|
|
|
|
|
|
err = json.Unmarshal(respBody, &errorResponse)
|
2020-10-29 10:21:01 +02:00
|
|
|
if err == nil && errorResponse.ErrorCode != 0 {
|
|
|
|
return fmt.Errorf("invalid request, error code %v, message '%s'",
|
2020-09-18 11:54:45 +02:00
|
|
|
errorResponse.ErrorCode, errorResponse.ErrorMessage)
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:21:01 +02:00
|
|
|
if result != nil {
|
|
|
|
err = json.Unmarshal(respBody, result)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to parse WhiteSource response")
|
|
|
|
}
|
2020-09-18 11:54:45 +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-07-01 07:54:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
func (s *System) sendRequest(req Request) ([]byte, 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-07-01 07:54:13 +02:00
|
|
|
var responseBody []byte
|
2020-05-26 17:30:45 +02:00
|
|
|
if req.UserKey == "" {
|
2020-09-18 11:54:45 +02:00
|
|
|
req.UserKey = s.userToken
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
if req.OrgToken == "" {
|
2020-09-18 11:54:45 +02:00
|
|
|
req.OrgToken = s.orgToken
|
2020-05-26 17:30:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
body, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
|
|
|
return responseBody, errors.Wrap(err, "failed to create WhiteSource request")
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:54:45 +02:00
|
|
|
log.Entry().Debugf("request: %v", string(body))
|
2020-05-26 17:30:45 +02:00
|
|
|
|
|
|
|
headers := http.Header{}
|
|
|
|
headers.Add("Content-Type", "application/json")
|
2020-09-18 11:54:45 +02:00
|
|
|
response, err := s.httpClient.SendRequest(http.MethodPost, s.serverURL, bytes.NewBuffer(body), headers, nil)
|
2020-05-26 17:30:45 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return responseBody, errors.Wrap(err, "failed to send request to WhiteSource")
|
|
|
|
}
|
|
|
|
|
|
|
|
responseBody, err = ioutil.ReadAll(response.Body)
|
|
|
|
if err != nil {
|
|
|
|
return responseBody, errors.Wrap(err, "failed to read WhiteSource response")
|
|
|
|
}
|
2020-09-18 11:54:45 +02:00
|
|
|
|
2020-05-26 17:30:45 +02:00
|
|
|
return responseBody, nil
|
|
|
|
}
|