Search in sources :

Example 1 with Output

use of com.hp.oo.sdk.content.annotations.Output in project cs-actions by CloudSlang.

the class AddMember method execute.

@Action(name = ADD_MEMBER, description = ADD_MEMBER_DESCRIPTION, outputs = { @Output(RETURN_RESULT), @Output(STATUS_CODE), @Output(RETURN_CODE), @Output(EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) })
public Map<String, String> execute(@Param(value = HOST, description = HOST_DESCRIPTION, required = true) String hostName, @Param(value = PROTOCOL, description = PROTOCOL_DESCRIPTION) String protocol, @Param(value = AUTH_TOKEN, description = AUTH_TOKEN_DESCRIPTION, required = true) String authToken, @Param(value = SAFE_URL_ID, description = SAFE_URL_ID_DESCRIPTION, required = true) String safeUrlId, @Param(value = MEMBER_NAME, description = MEMBER_NAME_DESCRIPTION, required = true) String memberName, @Param(value = SEARCH_IN, description = SEARCH_IN_DESCRIPTION) String searchIn, @Param(value = MEMBERSHIP_EXPIRATION_DATE, description = MEMBERSHIP_EXPIRATION_DATE_DESCRIPTION) String membershipExpirationDate, @Param(value = PERMISSIONS, description = PERMISSIONS_DESCRIPTION) String permissions, @Param(value = IS_READ_ONLY, description = IS_READ_ONLY_DESCRIPTION) String isReadOnly, @Param(value = MEMBER_TYPE, description = MEMBER_TYPE_DESCRIPTION) String memberType, @Param(value = PROXY_HOST, description = PROXY_HOST_DESCRIPTION) String proxyHost, @Param(value = PROXY_PORT, description = PROXY_PORT_DESCRIPTION) String proxyPort, @Param(value = PROXY_USERNAME, description = PROXY_USERNAME_DESCRIPTION) String proxyUsername, @Param(value = PROXY_PASSWORD, encrypted = true, description = PROXY_PASSWORD_DESCRIPTION) String proxyPassword, @Param(value = TLS_VERSION, description = TLS_VERSION_DESCRIPTION) String tlsVersion, @Param(value = ALLOWED_CIPHERS, description = ALLOWED_CIPHERS_DESCRIPTION) String allowedCiphers, @Param(value = TRUST_ALL_ROOTS, description = TRUST_ALL_ROOTS_DESCRIPTION) String trustAllRoots, @Param(value = X509_HOSTNAME_VERIFIER, description = X509_HOSTNAME_VERIFIER_DESCRIPTION) String x509HostnameVerifier, @Param(value = TRUST_KEYSTORE, description = TRUST_KEYSTORE_DESCRIPTION) String trustKeystore, @Param(value = TRUST_PASSWORD, encrypted = true, description = TRUST_PASSWORD_DESCRIPTION) String trustPassword, @Param(value = KEYSTORE, description = KEYSTORE_DESCRIPTION) String keystore, @Param(value = KEYSTORE_PASSWORD, encrypted = true, description = KEYSTORE_PASSWORD_DESCRIPTION) String keystorePassword, @Param(value = CONNECT_TIMEOUT, description = CONNECT_TIMEOUT_DESCRIPTION) String connectTimeout, @Param(value = EXECUTION_TIMEOUT, description = EXECUTION_TIMEOUT_DESCRIPTION) String executionTimeout, @Param(value = KEEP_ALIVE, description = KEEP_ALIVE_DESCRIPTION) String keepAlive, @Param(value = CONNECTIONS_MAX_PER_ROUTE, description = CONNECTIONS_MAX_PER_ROUTE_DESCRIPTION) String connectionsMaxPerRoute, @Param(value = CONNECTIONS_MAX_TOTAL, description = CONNECTIONS_MAX_TOTAL_DESCRIPTION) String connectionsMaxTotal, @Param(value = SESSION_COOKIES, description = SESSION_COOKIES_DESC) SerializableSessionObject sessionCookies, @Param(value = SESSION_CONNECTION_POOL, description = SESSION_CONNECTION_POOL_DESC) GlobalSessionObject sessionConnectionPool) {
    try {
        validateProtocol(protocol);
        JSONObject body = new JSONObject();
        body.put(MEMBER_NAME, memberName);
        body.put(SEARCH_IN, searchIn);
        if (!StringUtils.isEmpty(membershipExpirationDate))
            body.put(MEMBERSHIP_EXPIRATION_DATE, membershipExpirationDate);
        JSONObject permissionsJson = new JSONObject();
        if (!StringUtils.isEmpty(permissions))
            Arrays.stream(permissions.trim().split(SEMICOLON)).map(permission -> permission.split(EQUALS)).forEach(permission -> permissionsJson.put(permission[0], permission[1]));
        body.put(PERMISSIONS, permissionsJson);
        body.put(IS_READ_ONLY, isReadOnly);
        body.put(MEMBER_TYPE, memberType);
        Map<String, String> result = new HttpClientPostAction().execute(protocol + PROTOCOL_DELIMITER + hostName + ADD_MEMBER_ENDPOINT + safeUrlId + MEMBERS, ANONYMOUS, EMPTY, EMPTY, EMPTY, proxyHost, proxyPort, proxyUsername, proxyPassword, tlsVersion, allowedCiphers, trustAllRoots, x509HostnameVerifier, trustKeystore, trustPassword, keystore, keystorePassword, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal, EMPTY, EMPTY, CONTENT_TYPE + APPLICATION_JSON + COMMA + AUTHORIZATION + authToken, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, body.toString(), APPLICATION_JSON, EMPTY, connectTimeout, EMPTY, executionTimeout, sessionCookies, sessionConnectionPool);
        processHttpResult(result);
        return result;
    } catch (Exception exception) {
        return OutputUtilities.getFailureResultsMap(exception);
    }
}
Also used : ResponseType(com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType) Arrays(java.util.Arrays) SerializableSessionObject(com.hp.oo.sdk.content.plugin.SerializableSessionObject) GlobalSessionObject(com.hp.oo.sdk.content.plugin.GlobalSessionObject) HttpClientPostAction(io.cloudslang.content.httpclient.actions.HttpClientPostAction) MatchType(com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType) OutputUtilities(io.cloudslang.content.utils.OutputUtilities) OtherConstants(io.cloudslang.content.cyberark.utils.Constants.OtherConstants) Map(java.util.Map) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) Param(com.hp.oo.sdk.content.annotations.Param) CommonConstants(io.cloudslang.content.cyberark.utils.Constants.CommonConstants) ReturnCodes(io.cloudslang.content.constants.ReturnCodes) Action(com.hp.oo.sdk.content.annotations.Action) OutputNames(io.cloudslang.content.constants.OutputNames) Response(com.hp.oo.sdk.content.annotations.Response) SESSION_CONNECTION_POOL_DESC(io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_CONNECTION_POOL_DESC) SESSION_CONNECTION_POOL(io.cloudslang.content.httpclient.utils.Inputs.HTTPInputs.SESSION_CONNECTION_POOL) StringUtils(io.cloudslang.content.cyberark.utils.StringUtils) CyberarkUtils.validateProtocol(io.cloudslang.content.cyberark.utils.CyberarkUtils.validateProtocol) SESSION_COOKIES_DESC(io.cloudslang.content.httpclient.utils.Descriptions.HTTPClient.SESSION_COOKIES_DESC) SESSION_COOKIES(io.cloudslang.content.httpclient.utils.Inputs.HTTPInputs.SESSION_COOKIES) Output(com.hp.oo.sdk.content.annotations.Output) AddMemberConstants(io.cloudslang.content.cyberark.utils.Constants.AddMemberConstants) ResponseNames(io.cloudslang.content.constants.ResponseNames) JSONObject(net.minidev.json.JSONObject) CyberarkUtils.processHttpResult(io.cloudslang.content.cyberark.utils.CyberarkUtils.processHttpResult) JSONObject(net.minidev.json.JSONObject) HttpClientPostAction(io.cloudslang.content.httpclient.actions.HttpClientPostAction) HttpClientPostAction(io.cloudslang.content.httpclient.actions.HttpClientPostAction) Action(com.hp.oo.sdk.content.annotations.Action)

Example 2 with Output

use of com.hp.oo.sdk.content.annotations.Output in project cs-actions by CloudSlang.

the class Base64Encoder method execute.

/**
 * This encodes in base64 a value read from a file.
 *
 * @param filePath - the path were the desired file is to be encoded.
 * @return - a map containing the output of the operation. Keys present in the map are:
 * returnResult - The encoded value.
 * returnCode - the return code of the operation. 0 if the operation goes to success, -1 if the operation goes to failure.
 * exception - the exception message if the operation fails.
 */
@Action(name = Descriptions.EncodeFileToStringOutput.BASE64_ENCODER_FROM_FILE, description = Descriptions.EncodeFileToStringOutput.BASE64_ENCODER_FROM_FILE_DESC, outputs = { @Output(value = OutputNames.EXCEPTION, description = Descriptions.EncodeFileToStringOutput.EXCEPTION_DESC), @Output(value = OutputNames.RETURN_CODE, description = Descriptions.EncodeFileToStringOutput.RETURN_CODE_DESC), @Output(value = OutputNames.RETURN_RESULT, description = Descriptions.EncodeFileToStringOutput.RETURN_RESULT_DESC), @Output(value = Constants.RETURN_VALUE, description = Descriptions.EncodeFileToStringOutput.RETURN_VALUE_DESC) }, responses = { @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, description = Descriptions.EncodeFileToStringOutput.FAILURE_DESC), @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED, description = Descriptions.EncodeFileToStringOutput.SUCCESS_DESC) })
public Map<String, String> execute(@Param(value = Inputs.Base64CoderInputs.FILE_PATH, description = Descriptions.EncodeFileToStringOutput.FILE_PATH_DESC, required = true) String filePath) {
    final List<String> exceptionMessages = InputsValidation.verifyBase64EncoderInputs(filePath);
    if (!exceptionMessages.isEmpty()) {
        final Map<String, String> result = OutputUtilities.getFailureResultsMap(StringUtilities.join(exceptionMessages, Constants.NEW_LINE));
        result.put(Constants.RETURN_VALUE, Constants.ENCODE_EXCEPTION_MESSAGE);
        return result;
    }
    try {
        Base64EncoderInputs base64EncoderInputs = new Base64EncoderInputs.Base64EncoderInputsBuilder().with(builder -> builder.filePath = filePath).buildInputs();
        final String resultResult = Base64EncoderToStringImpl.displayEncodedBytes(base64EncoderInputs);
        final Map<String, String> result = OutputUtilities.getSuccessResultsMap(Constants.ENCODE_RETURN_VALUE + resultResult);
        result.put(Constants.RETURN_VALUE, resultResult);
        return result;
    } catch (Exception exception) {
        final Map<String, String> result = OutputUtilities.getFailureResultsMap(exception);
        result.put(Constants.RETURN_VALUE, Constants.ENCODE_NO_FILE_EXCEPTION);
        return result;
    }
}
Also used : InputsValidation(io.cloudslang.content.utilities.util.InputsValidation) ResponseType(com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType) Action(com.hp.oo.sdk.content.annotations.Action) OutputNames(io.cloudslang.content.constants.OutputNames) Response(com.hp.oo.sdk.content.annotations.Response) StringUtilities(io.cloudslang.content.utils.StringUtilities) Base64EncoderInputs(io.cloudslang.content.utilities.entities.Base64EncoderInputs) MatchType(com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType) Base64EncoderToStringImpl(io.cloudslang.content.utilities.services.base64coder.Base64EncoderToStringImpl) Constants(io.cloudslang.content.utilities.util.Constants) OutputUtilities(io.cloudslang.content.utils.OutputUtilities) List(java.util.List) Output(com.hp.oo.sdk.content.annotations.Output) ResponseNames(io.cloudslang.content.constants.ResponseNames) Map(java.util.Map) Descriptions(io.cloudslang.content.utilities.util.Descriptions) Inputs(io.cloudslang.content.utilities.util.Inputs) Param(com.hp.oo.sdk.content.annotations.Param) ReturnCodes(io.cloudslang.content.constants.ReturnCodes) Base64EncoderInputs(io.cloudslang.content.utilities.entities.Base64EncoderInputs) Map(java.util.Map) Action(com.hp.oo.sdk.content.annotations.Action)

Aggregations

Action (com.hp.oo.sdk.content.annotations.Action)2 Output (com.hp.oo.sdk.content.annotations.Output)2 Param (com.hp.oo.sdk.content.annotations.Param)2 Response (com.hp.oo.sdk.content.annotations.Response)2 MatchType (com.hp.oo.sdk.content.plugin.ActionMetadata.MatchType)2 ResponseType (com.hp.oo.sdk.content.plugin.ActionMetadata.ResponseType)2 OutputNames (io.cloudslang.content.constants.OutputNames)2 ResponseNames (io.cloudslang.content.constants.ResponseNames)2 ReturnCodes (io.cloudslang.content.constants.ReturnCodes)2 OutputUtilities (io.cloudslang.content.utils.OutputUtilities)2 Map (java.util.Map)2 GlobalSessionObject (com.hp.oo.sdk.content.plugin.GlobalSessionObject)1 SerializableSessionObject (com.hp.oo.sdk.content.plugin.SerializableSessionObject)1 AddMemberConstants (io.cloudslang.content.cyberark.utils.Constants.AddMemberConstants)1 CommonConstants (io.cloudslang.content.cyberark.utils.Constants.CommonConstants)1 OtherConstants (io.cloudslang.content.cyberark.utils.Constants.OtherConstants)1 CyberarkUtils.processHttpResult (io.cloudslang.content.cyberark.utils.CyberarkUtils.processHttpResult)1 CyberarkUtils.validateProtocol (io.cloudslang.content.cyberark.utils.CyberarkUtils.validateProtocol)1 StringUtils (io.cloudslang.content.cyberark.utils.StringUtils)1 HttpClientPostAction (io.cloudslang.content.httpclient.actions.HttpClientPostAction)1