You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	Add creation capabilities for whitesource products
This commit is contained in:
		| @@ -256,6 +256,8 @@ steps: | |||||||
|   npmExecute: |   npmExecute: | ||||||
|     dockerImage: 'node:8-stretch' |     dockerImage: 'node:8-stretch' | ||||||
|   whitesourceExecuteScan: |   whitesourceExecuteScan: | ||||||
|  |     createProductFromPipeline: true | ||||||
|  |     emailAddressesOfInitialProductAdmins: [] | ||||||
|     buildDescriptorExcludeList: [] |     buildDescriptorExcludeList: [] | ||||||
|     parallelLimit: 15 |     parallelLimit: 15 | ||||||
|     licensingVulnerabilities: true |     licensingVulnerabilities: true | ||||||
|   | |||||||
| @@ -42,13 +42,40 @@ class WhitesourceOrgAdminRepository implements Serializable { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!foundMetaProduct) |  | ||||||
|             script.error "[WhiteSource] Could not fetch/find requested product '${config.productName}'" |  | ||||||
|  |  | ||||||
|         return foundMetaProduct |         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 |     @NonCPS | ||||||
|     protected def httpWhitesource(requestBody) { |     protected def httpWhitesource(requestBody) { | ||||||
|   | |||||||
| @@ -224,8 +224,15 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU | |||||||
| void analyseWhitesourceResults(Map config, WhitesourceRepository repository, WhitesourceOrgAdminRepository orgAdminRepository) { | void analyseWhitesourceResults(Map config, WhitesourceRepository repository, WhitesourceOrgAdminRepository orgAdminRepository) { | ||||||
|     if (!config.productToken) { |     if (!config.productToken) { | ||||||
|         def metaInfo = orgAdminRepository.fetchProductMetaInfo() |         def metaInfo = orgAdminRepository.fetchProductMetaInfo() | ||||||
|         echo "Meta Information: ${metaInfo}" |         def key = "token" | ||||||
|         config.productToken = metaInfo.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" |     def pdfName = "whitesource-riskReport.pdf" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user