1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00

Moved admin auth handling into script

This commit is contained in:
Sven Merk 2019-03-11 10:46:22 +01:00
parent 61a9710fab
commit 61d6280c3a
3 changed files with 40 additions and 28 deletions

View File

@ -9,7 +9,9 @@ class WhitesourceOrgAdminRepository implements Serializable {
final internalWhitesource
final Map config
def orgAdminUserKey
WhitesourceOrgAdminRepository() {
super()
}
WhitesourceOrgAdminRepository(Script script, Map config) {
this.script = script
@ -79,11 +81,7 @@ class WhitesourceOrgAdminRepository implements Serializable {
@NonCPS
protected def httpWhitesource(requestBody) {
script.withCredentials ([script.string(
credentialsId: config.orgAdminUserTokenCredentialsId,
variable: 'orgAdminUserKey'
)]) {
requestBody["userKey"] = orgAdminUserKey
requestBody["userKey"] = config.orgAdminUserKey
def serializedBody = new JsonUtils().jsonToString(requestBody)
def params = [
url : config.serviceUrl,
@ -108,5 +106,4 @@ class WhitesourceOrgAdminRepository implements Serializable {
return response
}
}
}

View File

@ -1,5 +1,7 @@
package com.sap.piper.integration
import com.lesfurets.jenkins.unit.PipelineTestHelper
import org.codehaus.groovy.runtime.InvokerHelper
import org.junit.After
import org.junit.Before
import org.junit.Rule
@ -71,8 +73,8 @@ class WhitesourceOrgAdminRepositoryTest extends BasePiperTest {
@Test
void testHttpWhitesourceInternalCallUserKey() {
repository.orgAdminUserKey = "4711"
def config = [ serviceUrl: "http://some.host.whitesource.com/api/", verbose: false, orgAdminUserKey: "4711"]
repository.config.putAll(config)
def requestBody = ["someJson" : [ "someObject" : "abcdef" ]]
def requestParams

View File

@ -217,14 +217,27 @@ void call(Map parameters = [:]) {
def whitesourceRepository = parameters.whitesourceRepositoryStub ?: new WhitesourceRepository(this, config)
def whitesourceOrgAdminRepository = parameters.whitesourceOrgAdminRepositoryStub ?: new WhitesourceOrgAdminRepository(this, config)
if(config.orgAdminUserTokenCredentialsId) {
statusCode = triggerWhitesourceScanWithOrgAdminUserKey(script, config, utils, descriptorUtils, parameters, whitesourceRepository, whitesourceOrgAdminRepository)
} else {
statusCode = triggerWhitesourceScanWithUserKey(script, config, utils, descriptorUtils, parameters, whitesourceRepository, whitesourceOrgAdminRepository)
}
checkStatus(statusCode, config)
script.commonPipelineEnvironment.setInfluxStepData('whitesource', true)
}
}
private def triggerWhitesourceScanWithOrgAdminUserKey(script, config, utils, descriptorUtils, parameters, repository, orgAdminRepository) {
withCredentials ([script.string(
credentialsId: config.orgAdminUserTokenCredentialsId,
variable: 'orgAdminUserKey'
)]) {
config.orgAdminUserKey = orgAdminUserKey
triggerWhitesourceScanWithUserKey(script, config, utils, descriptorUtils, parameters, repository, orgAdminRepository)
}
}
private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorUtils, parameters, repository, orgAdminRepository) {
withCredentials ([string(
credentialsId: config.userTokenCredentialsId,