<commit_before>var fs = require('fs');
var Rancher = require('../lib/Rancher.js');

module.exports = function () {

	var UpdateRancherCommand = function (domain, keyfile, certfile, chainfile) {
		this.domain = domain;
		this.keyfile = keyfile;
		this.certfile = certfile;
		this.chainfile = chainfile;
	};

	UpdateRancherCommand.prototype.handle = function () {
		var payload = this.prepareJsonBody();

		console.log('Using payload for create/update requests:', payload);

		Rancher.findCertByName(this.domain, function (data) {
			if (data.length) {
				// an existing certificate exists. Update it.
				var id = data[0].id;

				console.log('Found existing certificate with ID ' + id);

				Rancher.updateCertificateById(id, payload, function (data) {
					console.log('Updated certificate in Rancher!');
				});
			} else {
				// no certificate exists. Create one!
				Rancher.createCertificate(payload, function (data) {
					console.log('Created certificate in Rancher!');
				});
			}
		}.bind(this));

		// console.log(body);
	}

	UpdateRancherCommand.prototype.prepareJsonBody = function () {
		return {
			name: this.domain,
			key: fs.readFileSync(this.keyfile, 'utf8'),
			cert: fs.readFileSync(this.certfile, 'utf8'),
			chain: this.chainfile ? fs.readFileSync(this.chainfile, 'utf8') : null,
		};
	}

	return UpdateRancherCommand;

}();<commit_msg>Using non-full-chain<commit_after>var fs = require('fs');
var Rancher = require('../lib/Rancher.js');

module.exports = function () {

	var UpdateRancherCommand = function (domain, keyfile, certfile, chainfile) {
		this.domain = domain;
		this.keyfile = keyfile;
		this.certfile = certfile;
		this.chainfile = chainfile;
	};

	UpdateRancherCommand.prototype.handle = function () {
		var payload = this.prepareJsonBody();

		console.log('Using payload for create/update requests:', payload);

		Rancher.findCertByName(this.domain, function (data) {
			if (data.length) {
				// an existing certificate exists. Update it.
				var id = data[0].id;

				console.log('Found existing certificate with ID ' + id);

				Rancher.updateCertificateById(id, payload, function (data) {
					console.log('Updated certificate in Rancher!');
				});
			} else {
				// no certificate exists. Create one!
				Rancher.createCertificate(payload, function (data) {
					console.log('Created certificate in Rancher!');
				});
			}
		}.bind(this));

		// console.log(body);
	}

	UpdateRancherCommand.prototype.prepareJsonBody = function () {
		return {
			name: this.domain,
			key: fs.readFileSync(this.keyfile, 'utf8'),
			cert: fs.readFileSync(this.certfile, 'utf8'),
			chain: this.chainfile ? fs.readFileSync(this.chainfile.replace('full', ''), 'utf8') : null,
		};
	}

	return UpdateRancherCommand;

}();
{'fraction_non_alphanumeric': 0.14467466375863322, 'fraction_numerical': 0.0029080334423845873, 'mean_word_length': 3.8111888111888113, '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': '1651705', 'n_tokens_mistral': 1008, 'n_tokens_neox': 877, 'n_words': 191}