Config

2 minute readReferenceExtensibilityDeveloper productivity

This class provides methods to handle current configuration (global values) available in current run context based on the name of the configuration provided. To get a handle to a Config object you need to use the getConfigValues() method from Context.

isParameterExists(String parameterName)

Returns true if parameter exists in the current configuration.

Parameters

(String) Name of parameter

Returns

(Boolean) True if parameter exists.

Usage

if (configValues.isParameterExists('endpoint')) { ... }

getParameter(String parameterName)

Returns the Parameter object for the given name.

Parameter

(String) Name of parameter to get.

Returns

Returns Parameter instance for the given parameter name. If parameter with given name doesn’t exist, will return null.

Usage

To retrieve parameter object:

def query = configValues.getParameter('query') println("Query: " + query.getValue())

Or:

def query = configValues.getParameter('query') println("Query: ${query}")

getCredential(String credentialName)

Returns the Credential object for the given name.

Parameters

(String) Name of credential’s parameter to get.

Returns

Returns Credential instance for the given parameter name. If parameter with given name doesn’t exist, will return null.

Usage

To retrieve credential object:

def cred = configValues.getCredential('credential') println("UserName: " + cred.getUserName()) println("Password: " + cred.getSecretValue())

Or:

def cred = configValues.getCredential('credential') println("Credential: ${cred}") // toString() is overridden, so the password part (secretValue) will be masked

getRequiredParameter(String parameterName)

Returns a Parameter object if parameter exists.

If parameter does not exist, this method will throw an UnexpectedMissingValue exception.

Parameters

(String) Name of parameter

Returns

Returns Parameter instance for the given parameter name.

Usage

To retrieve parameter object:

def query = configValues.getRequiredParameter('query') println("Query: " + query.getValue())
def query = configValues.getRequiredParameter('query') println("Query: ${query}")

getRequiredCredential(String credentialName)

Returns a Credential object if parameter exists.

If parameter does not exist, this method will throw an UnexpectedMissingValue exception.

Parameters

(String) Name of credential

Returns

Returns Credential instance for the given parameter name.

Usage

To retrieve credential object:

def cred = configValues.getRequiredCredential('credential') println("UserName: " + cred.getUserName()) println("Password: " + cred.getSecretValue())

Or:

def cred = configValues.getRequiredCredential('credential') println("Credential: ${cred}") // toString() is overridden, so the password part (secretValue) will be masked

getAsMap()

Returns a Map representation of the parameters. Keys will be parameter names and values will be the parameter values. Value for the credential will be a Credential object reference.

Parameters

None

Returns

Returns a Map that is a simplified representation for current values.

Usage

def configMap = configValues.getAsMap() println("Endpoint: ${configMap['endpoint']}") println("Username: " + configMap['credential'].getUserName())