1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Add creation capabilities for whitesource products

This commit is contained in:
Sven Merk 2019-03-06 13:12:23 +01:00
parent 93b3afe67d
commit 6a907cff23
3 changed files with 41 additions and 5 deletions

View File

@ -256,6 +256,8 @@ steps:
npmExecute:
dockerImage: 'node:8-stretch'
whitesourceExecuteScan:
createProductFromPipeline: true
emailAddressesOfInitialProductAdmins: []
buildDescriptorExcludeList: []
parallelLimit: 15
licensingVulnerabilities: true

View File

@ -42,13 +42,40 @@ class WhitesourceOrgAdminRepository implements Serializable {
}
}
if (!foundMetaProduct)
script.error "[WhiteSource] Could not fetch/find requested product '${config.productName}'"
return foundMetaProduct
}
def createProduct() {
def requestBody = [
requestType: "createProduct",
orgToken: config.orgToken,
productName: config.productName
]
def response = issueHttpRequest(requestBody)
def parsedResponse = new JsonUtils().parseJsonSerializable(response.content)
def metaInfo = parsedResponse
def groups = []
def users = []
config.emailAddressesOfInitialProductAdmins.each {
email -> users.add(["email": config.emailOfInitialProductAdmin])
}
requestBody = [
"requestType" : "setProductAssignments",
"productToken" : metaInfo.productToken,
"productMembership" : ["userAssignments":[], "groupAssignments":groups],
"productAdmins" : ["userAssignments":users],
"alertsEmailReceivers" : ["userAssignments":[]]
]
issueHttpRequest(requestBody)
return metaInfo
}
def issueHttpRequest(requestBody) {
internalWhitesource ? internalWhitesource.httpWhitesource(requestBody) : httpWhitesource(requestBody)
}
@NonCPS
protected def httpWhitesource(requestBody) {

View File

@ -224,8 +224,15 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU
void analyseWhitesourceResults(Map config, WhitesourceRepository repository, WhitesourceOrgAdminRepository orgAdminRepository) {
if (!config.productToken) {
def metaInfo = orgAdminRepository.fetchProductMetaInfo()
echo "Meta Information: ${metaInfo}"
config.productToken = metaInfo.token
def key = "token"
if(!metaInfo && config.createProductFromPipeline) {
metaInfo = orgAdminRepository.createProduct()
key = "productToken"
} else if(!metaInfo) {
error "[WhiteSource] Could not fetch/find requested product '${config.productName}' and automatic creation has been disabled"
}
echo "Meta Info: ${metaInfo}"
config.productToken = metaInfo[key]
}
def pdfName = "whitesource-riskReport.pdf"