<commit_before>/*
* Copyright 2015 herd contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.finra.herd.dao.helper;

import com.amazonaws.ClientConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.finra.herd.core.helper.ConfigurationHelper;
import org.finra.herd.model.dto.AwsParamsDto;
import org.finra.herd.model.dto.ConfigurationValue;

/**
 * A base helper class that provides AWS functions.
 */
@Component
public class AwsHelper
{
    private static final int BITS_PER_BYTE = 8;

    @Autowired
    protected ConfigurationHelper configurationHelper;

    // herdHelper to access helper methods
    @Autowired
    protected HerdStringHelper herdStringHelper;

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AwsHelper.class);

    /**
     * Constructs awsParamsDto with AWS parameters.
     *
     * @return the AWS params DTO object.
     */
    public AwsParamsDto getAwsParamsDto()
    {
        AwsParamsDto awsParamsDto = new AwsParamsDto();

        // Get HTTP proxy configuration settings.
        String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST);
        Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class);

        awsParamsDto.setHttpProxyHost(httpProxyHost);
        awsParamsDto.setHttpProxyPort(httpProxyPort);

        LOGGER.info("The proxy host=", +httpProxyPort + " port=" + httpProxyPort);
        return awsParamsDto;
    }

    /**
     * Returns client configuration options that might contain proxy settings set per specified AWS parameters DTO.
     *
     * @param awsParamsDto the AWS params DTO object
     *
     * @return the client configuration options
     */
    public ClientConfiguration getClientConfiguration(AwsParamsDto awsParamsDto)
    {
        ClientConfiguration clientConfiguration;

        // Only set the proxy hostname and port if they're both configured.
        if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null)
        {
            clientConfiguration = new ClientConfiguration().withProxyHost(awsParamsDto.getHttpProxyHost()).withProxyPort(awsParamsDto.getHttpProxyPort());
        }
        else
        {
            clientConfiguration = new ClientConfiguration();
        }

        return clientConfiguration;
    }<commit_msg>DM-9579 FactoryCQ - Remove CRED_PROXY and CRED_PORT environment variables<commit_after>/*
* Copyright 2015 herd contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.finra.herd.dao.helper;

import com.amazonaws.ClientConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.finra.herd.core.helper.ConfigurationHelper;
import org.finra.herd.model.dto.AwsParamsDto;
import org.finra.herd.model.dto.ConfigurationValue;

/**
 * A base helper class that provides AWS functions.
 */
@Component
public class AwsHelper
{
    private static final int BITS_PER_BYTE = 8;

    @Autowired
    protected ConfigurationHelper configurationHelper;

    // herdHelper to access helper methods
    @Autowired
    protected HerdStringHelper herdStringHelper;

    /**
     * Constructs awsParamsDto with AWS parameters.
     *
     * @return the AWS params DTO object.
     */
    public AwsParamsDto getAwsParamsDto()
    {
        AwsParamsDto awsParamsDto = new AwsParamsDto();

        // Get HTTP proxy configuration settings.
        String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST);
        Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class);

        awsParamsDto.setHttpProxyHost(httpProxyHost);
        awsParamsDto.setHttpProxyPort(httpProxyPort);

        return awsParamsDto;
    }

    /**
     * Returns client configuration options that might contain proxy settings set per specified AWS parameters DTO.
     *
     * @param awsParamsDto the AWS params DTO object
     *
     * @return the client configuration options
     */
    public ClientConfiguration getClientConfiguration(AwsParamsDto awsParamsDto)
    {
        ClientConfiguration clientConfiguration;

        // Only set the proxy hostname and port if they're both configured.
        if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null)
        {
            clientConfiguration = new ClientConfiguration().withProxyHost(awsParamsDto.getHttpProxyHost()).withProxyPort(awsParamsDto.getHttpProxyPort());
        }
        else
        {
            clientConfiguration = new ClientConfiguration();
        }

        return clientConfiguration;
    }
{'fraction_non_alphanumeric': 0.07467695922134586, 'fraction_numerical': 0.004363148179224702, 'mean_word_length': 3.595219737856592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662078', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1575, 'n_words': 463}