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:
parent
61a9710fab
commit
61d6280c3a
@ -9,7 +9,9 @@ class WhitesourceOrgAdminRepository implements Serializable {
|
|||||||
final internalWhitesource
|
final internalWhitesource
|
||||||
final Map config
|
final Map config
|
||||||
|
|
||||||
def orgAdminUserKey
|
WhitesourceOrgAdminRepository() {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
WhitesourceOrgAdminRepository(Script script, Map config) {
|
WhitesourceOrgAdminRepository(Script script, Map config) {
|
||||||
this.script = script
|
this.script = script
|
||||||
@ -79,11 +81,7 @@ class WhitesourceOrgAdminRepository implements Serializable {
|
|||||||
|
|
||||||
@NonCPS
|
@NonCPS
|
||||||
protected def httpWhitesource(requestBody) {
|
protected def httpWhitesource(requestBody) {
|
||||||
script.withCredentials ([script.string(
|
requestBody["userKey"] = config.orgAdminUserKey
|
||||||
credentialsId: config.orgAdminUserTokenCredentialsId,
|
|
||||||
variable: 'orgAdminUserKey'
|
|
||||||
)]) {
|
|
||||||
requestBody["userKey"] = orgAdminUserKey
|
|
||||||
def serializedBody = new JsonUtils().jsonToString(requestBody)
|
def serializedBody = new JsonUtils().jsonToString(requestBody)
|
||||||
def params = [
|
def params = [
|
||||||
url : config.serviceUrl,
|
url : config.serviceUrl,
|
||||||
@ -109,4 +107,3 @@ class WhitesourceOrgAdminRepository implements Serializable {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.sap.piper.integration
|
package com.sap.piper.integration
|
||||||
|
|
||||||
|
import com.lesfurets.jenkins.unit.PipelineTestHelper
|
||||||
|
import org.codehaus.groovy.runtime.InvokerHelper
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
@ -71,8 +73,8 @@ class WhitesourceOrgAdminRepositoryTest extends BasePiperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testHttpWhitesourceInternalCallUserKey() {
|
void testHttpWhitesourceInternalCallUserKey() {
|
||||||
repository.orgAdminUserKey = "4711"
|
|
||||||
def config = [ serviceUrl: "http://some.host.whitesource.com/api/", verbose: false, 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 requestBody = ["someJson" : [ "someObject" : "abcdef" ]]
|
||||||
|
|
||||||
def requestParams
|
def requestParams
|
||||||
|
@ -217,14 +217,27 @@ void call(Map parameters = [:]) {
|
|||||||
def whitesourceRepository = parameters.whitesourceRepositoryStub ?: new WhitesourceRepository(this, config)
|
def whitesourceRepository = parameters.whitesourceRepositoryStub ?: new WhitesourceRepository(this, config)
|
||||||
def whitesourceOrgAdminRepository = parameters.whitesourceOrgAdminRepositoryStub ?: new WhitesourceOrgAdminRepository(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)
|
statusCode = triggerWhitesourceScanWithUserKey(script, config, utils, descriptorUtils, parameters, whitesourceRepository, whitesourceOrgAdminRepository)
|
||||||
|
}
|
||||||
checkStatus(statusCode, config)
|
checkStatus(statusCode, config)
|
||||||
|
|
||||||
script.commonPipelineEnvironment.setInfluxStepData('whitesource', true)
|
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) {
|
private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorUtils, parameters, repository, orgAdminRepository) {
|
||||||
withCredentials ([string(
|
withCredentials ([string(
|
||||||
credentialsId: config.userTokenCredentialsId,
|
credentialsId: config.userTokenCredentialsId,
|
||||||
|
Loading…
Reference in New Issue
Block a user