1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/vars/writeTemporaryCredentials.groovy
Christopher Fenner 70b860f47f
feat: remove SAP web analytics reporting (#4773)
* improve vault logging

* remove swa calls

* Revert "improve vault logging"

This reverts commit 8335bbf365.
2024-01-15 13:17:53 +01:00

65 lines
2.8 KiB
Groovy

import com.sap.piper.ConfigurationHelper
import com.sap.piper.ConfigurationLoader
import com.sap.piper.GenerateDocumentation
import com.sap.piper.JsonUtils
import com.sap.piper.TemporaryCredentialsUtils
import com.sap.piper.Utils
import groovy.transform.Field
import static com.sap.piper.Prerequisites.checkScript
@Field String STEP_NAME = getClass().getName()
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = [
/**
* The list of credentials that are written to a temporary file for the execution of the body.
* Each element of credentials must be a map containing a property alias and a property credentialId.
* You have to ensure that corresponding credential entries exist in your Jenkins configuration.
*/
'credentials',
/**
* The list of paths to directories where credentials files need to be placed.
*/
'credentialsDirectories'
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
/**
* Writes credentials to a temporary file and deletes it after the body has been executed.
*/
@GenerateDocumentation
void call(Map parameters = [:], Closure body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
def script = checkScript(this, parameters) ?: this
String stageName = parameters.stageName ?: env.STAGE_NAME
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults([:], stageName)
.mixin(ConfigurationLoader.defaultStageConfiguration(script, stageName))
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
.mixin(parameters, PARAMETER_KEYS)
.use()
if (config.credentials && !(config.credentials instanceof List)) {
error "[${STEP_NAME}] The execution failed, since credentials is not a list. Please provide credentials as a list of maps. For example:\n" +
"credentials: \n" + " - alias: 'ERP'\n" + " credentialId: 'erp-credentials'"
}
if (!config.credentialsDirectories) {
error "[${STEP_NAME}] The execution failed, since no credentialsDirectories are defined. Please provide a list of paths for the credentials files.\n"
}
if (!(config.credentialsDirectories instanceof List)) {
error "[${STEP_NAME}] The execution failed, since credentialsDirectories is not a list. Please provide credentialsDirectories as a list of paths.\n"
}
TemporaryCredentialsUtils credUtils = new TemporaryCredentialsUtils(script)
credUtils.handleTemporaryCredentials(config.credentials, config.credentialsDirectories) {
body()
}
}
}