<commit_before>const AWS = require('aws-sdk');
const fs = require('fs');
const path = require('path');
const { config } = require('../../../../../lib/Config');

function getAwsCredentials(profile, credFile) {
    const filename = path.join(process.env.HOME, credFile);

    try {
        fs.statSync(filename);
    } catch (e) {
        const msg = `AWS credential file does not exist: ${filename}`;
        throw new Error(msg);
    }

    return new AWS.SharedIniFileCredentials({ profile, filename });
}

function getRealAwsConfig(awsLocation) {
    const cp =
        config.locationConstraints[awsLocation].details.credentialsProfile
        || 'default';
    const credentials = getAwsCredentials(cp, '/.aws/credentials');
    const realAwsConfig = { credentials, signatureVersion: 'v4' };

    return realAwsConfig;
}

module.exports = {
    getRealAwsConfig,
    getAwsCredentials,
};<commit_msg>fix: use credentials for getRealAwsConfig if fit<commit_after>const AWS = require('aws-sdk');
const fs = require('fs');
const path = require('path');
const { config } = require('../../../../../lib/Config');

function getAwsCredentials(profile, credFile) {
    const filename = path.join(process.env.HOME, credFile);

    try {
        fs.statSync(filename);
    } catch (e) {
        const msg = `AWS credential file does not exist: ${filename}`;
        throw new Error(msg);
    }

    return new AWS.SharedIniFileCredentials({ profile, filename });
}

function getRealAwsConfig(awsLocation) {
    const { credentialsProfile, credentials: locCredentials } =
        config.locationConstraints[awsLocation].details;
    if (credentialsProfile) {
        const credentials = getAwsCredentials(credentialsProfile,
            '/.aws/credentials');
        return { credentials, signatureVersion: 'v4' };
    }
    return {
        accessKeyId: locCredentials.accessKey,
        secretAccessKey: locCredentials.secretKey,
        signatureVersion: 'v4',
    };
}

module.exports = {
    getRealAwsConfig,
    getAwsCredentials,
};
{'fraction_non_alphanumeric': 0.13336614173228348, 'fraction_numerical': 0.0014763779527559055, 'mean_word_length': 3.289029535864979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5321859', 'n_tokens_mistral': 579, 'n_tokens_neox': 586, 'n_words': 133}