<commit_before>/*global module, require */
var Promise = require('bluebird'),
aws = require('aws-sdk'),
loadConfig = require('../util/loadconfig');
module.exports = function destroy(options) {
	'use strict';
	var lambda, lambdaConfig, apiConfig, deleteFunction,
		iam = Promise.promisifyAll(new aws.IAM()),
		destroyRole = function (roleName) {
		var deleteSinglePolicy = function (policyName) {
			return iam.deleteRolePolicyAsync({
				PolicyName: policyName,
				RoleName: roleName
			});
		};
		return iam.listRolePoliciesAsync({ RoleName: roleName }).then(function (result) {
			return Promise.map(result.PolicyNames, deleteSinglePolicy);
		}).then(function () {
			return iam.deleteRoleAsync({ RoleName: roleName });
		});
	};

	return loadConfig(options, { lambda: { name: true, region: true, role: true } }).then(function (config) {
		lambdaConfig = config.lambda;
		apiConfig = config.api;
	}).then(function () {
		lambda = Promise.promisifyAll(new aws.Lambda({ region: lambdaConfig.region }), { suffix: 'Promise' });
		deleteFunction = Promise.promisify(lambda.deleteFunction.bind(lambda));
		return deleteFunction({ FunctionName: lambdaConfig.name });
	}).then(function () {
		var apiGateway = Promise.promisifyAll(new aws.APIGateway({ region: lambdaConfig.region }));
		if (!apiConfig) {
			return Promise.resolve(true);
		}
		return apiGateway.deleteRestApiAsync({
			restApiId: apiConfig.id
		});
	}).then(function () {
		if (lambdaConfig.role) {
			return destroyRole(lambdaConfig.role);
		}
	});
};<commit_msg>code cleanup<commit_after>/*global module, require */
var Promise = require('bluebird'),
aws = require('aws-sdk'),
loadConfig = require('../util/loadconfig');
module.exports = function destroy(options) {
	'use strict';
	var lambdaConfig, apiConfig,
		iam = Promise.promisifyAll(new aws.IAM()),
		destroyRole = function (roleName) {
			var deleteSinglePolicy = function (policyName) {
				return iam.deleteRolePolicyAsync({
					PolicyName: policyName,
					RoleName: roleName
				});
			};
			return iam.listRolePoliciesAsync({ RoleName: roleName }).then(function (result) {
				return Promise.map(result.PolicyNames, deleteSinglePolicy);
			}).then(function () {
				return iam.deleteRoleAsync({ RoleName: roleName });
			});
		};

	return loadConfig(options, { lambda: { name: true, region: true, role: true } })
		.then(function (config) {
			lambdaConfig = config.lambda;
			apiConfig = config.api;
		}).then(function () {
			var lambda = Promise.promisifyAll(new aws.Lambda({ region: lambdaConfig.region }), { suffix: 'Promise' });
			return lambda.deleteFunctionPromise({ FunctionName: lambdaConfig.name });
		}).then(function () {
			var apiGateway = Promise.promisifyAll(new aws.APIGateway({ region: lambdaConfig.region }));
			if (apiConfig) {
				return apiGateway.deleteRestApiAsync({
					restApiId: apiConfig.id
				});
			}
		}).then(function () {
			if (lambdaConfig.role) {
				return destroyRole(lambdaConfig.role);
			}
		});
};
{'fraction_non_alphanumeric': 0.14838492597577388, 'fraction_numerical': 0.0, 'mean_word_length': 4.515769944341373, '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': '4476895', 'n_tokens_mistral': 1001, 'n_tokens_neox': 904, 'n_words': 194}