Skip to content

Commit

Permalink
toolrecord/whitesource: improve URL generation (#4581)
Browse files Browse the repository at this point in the history
toolrecord file:
- drop the hardcoded default url
- use the more user-friendly project ID instead of the project token
  • Loading branch information
larsbrueckner authored Sep 20, 2023
1 parent 3744787 commit a946034
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/whitesourceExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -1043,9 +1044,14 @@ func persistScannedProjects(config *ScanOptions, scan *ws.Scan, commonPipelineEn
// create toolrecord file for whitesource
func createToolRecordWhitesource(utils whitesourceUtils, workspace string, config *whitesourceExecuteScanOptions, scan *ws.Scan) (string, error) {
record := toolrecord.New(utils, workspace, "whitesource", config.ServiceURL)
wsUiRoot := "https://saas.whitesourcesoftware.com"
// rest api url https://.../api/v1.x
apiUrl, err := url.Parse(config.ServiceURL)
if err != nil {
return "", err
}
wsUiRoot := "https://" + apiUrl.Hostname()
productURL := wsUiRoot + "/Wss/WSS.html#!product;token=" + config.ProductToken
err := record.AddKeyData("product",
err = record.AddKeyData("product",
config.ProductToken,
config.ProductName,
productURL)
Expand All @@ -1056,11 +1062,13 @@ func createToolRecordWhitesource(utils whitesourceUtils, workspace string, confi
for idx, project := range scan.ScannedProjects() {
max_idx = idx
name := project.Name
projectId := strconv.FormatInt(project.ID, 10)
token := project.Token
projectURL := ""
if token != "" {
projectURL = wsUiRoot + "/Wss/WSS.html#!project;token=" + token
} else {
if projectId != "" {
projectURL = wsUiRoot + "/Wss/WSS.html#!project;id=" + projectId
}
if token == "" {
// token is empty, provide a dummy to have an indication
token = "unknown"
}
Expand Down

0 comments on commit a946034

Please sign in to comment.