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

Add ability to load custom defaults from secured resource (#1680)

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
This commit is contained in:
Daniel Kurzynski 2020-06-18 12:39:55 +02:00 committed by GitHub
parent f7015b562d
commit 6dfd83d246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,10 @@ import groovy.transform.Field
@Field Set GENERAL_CONFIG_KEYS = [
/** */
'collectTelemetryData'
'collectTelemetryData',
/** Credentials (username and password) used to download custom defaults if access is secured.*/
'customDefaultsCredentialsId'
]
@Field Set STEP_CONFIG_KEYS = []
@ -69,7 +72,8 @@ void call(Map parameters = [:]) {
customDefaultsFiles = Utils.appendParameterToStringList(
customDefaultsFiles, script.commonPipelineEnvironment.configuration as Map, 'customDefaults')
}
customDefaultsFiles = copyOrDownloadCustomDefaultsIntoPipelineEnv(script, customDefaultsFiles)
String customDefaultsCredentialsId = script.commonPipelineEnvironment.configuration.general?.customDefaultsCredentialsId
customDefaultsFiles = copyOrDownloadCustomDefaultsIntoPipelineEnv(script, customDefaultsFiles, customDefaultsCredentialsId)
prepareDefaultValues([
script: script,
@ -112,7 +116,7 @@ private static loadConfigurationFromFile(script, String configFile) {
}
}
private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List customDefaults) {
private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List customDefaults, String credentialsId) {
List fileList = []
int urlCount = 0
for (int i = 0; i < customDefaults.size(); i++) {
@ -125,10 +129,14 @@ private static List copyOrDownloadCustomDefaultsIntoPipelineEnv(script, List cus
if (customDefaults[i].startsWith('http://') || customDefaults[i].startsWith('https://')) {
fileName = "custom_default_from_url_${urlCount}.yml"
def response = script.httpRequest(
Map httpRequestParameters = [
url: customDefaults[i],
validResponseCodes: '100:399,404' // Allow a more specific error message for 404 case
)
]
if (credentialsId) {
httpRequestParameters.authentication = credentialsId
}
def response = script.httpRequest(httpRequestParameters)
if (response.status == 404) {
error "URL for remote custom defaults (${customDefaults[i]}) appears to be incorrect. " +
"Server returned HTTP status code 404. " +