<commit_before>var request = require('./lib/databox-request/databox-request.js')();
var basicAuth = require('basic-auth');
var macaroons = require('macaroons.js');
var pathToRegexp = require('path-to-regexp');


const DATABOX_ARBITER_ENDPOINT = process.env.DATABOX_ARBITER_ENDPOINT || "https://databox-arbiter:8080" 


/**
 * @return {Promise} A promise that resolves with a shared secret gotten from the arbiter
 */
module.exports.getSecretFromArbiter = function(arbiterKey) {
	return new Promise((resolve, reject) => {
		if (!arbiterKey) {
			resolve('');
			return;
		}

		// TODO: Could just make it port 80 arbiter-side since permissions don't matter in the container anyway...
		request.get('http://'+arbiterKey+'@'+DATABOX_ARBITER_ENDPOINT+'/store/secret', {})
		.then((error, response, body) => {
			if (error) {
				reject(error);
				return;
			}
			resolve(new Buffer(body, 'base64'));
		});

	});
};


/**
 * @param {String} Arbiter shared secret key
 * @param {String} Store hostname
 * @return {Function} Macaroon verification middleware
 */
module.exports.verifier = function (secret, storeName) {

	/**
	 * Checks validity of the macaroon "path" caveat
	 * @param {String} path
	 * @param {String} caveat
	 * @return {Boolean} valid
	 */
	var isPathValid = function () {
		var prefixRegex = /path = .*/;
		var prefixLen   = 'path = '.length;

		return function (caveat, path) {
			if (!prefixRegex.test(caveat))
				return false;

			// TODO: Catch potential JSON.parse exception
			return pathToRegexp(JSON.parse(caveat.substring(prefixLen).trim())).test(path);
		}
	}();

	/**
	 * Returns a verifier for a given path
	 * @param {String} path
	 * @return {Function} Path verifier
	 */
	var createPathVerifier = function (path) {
		return function (caveat) {
			return isPathValid(caveat, path);<commit_msg>Fix comment annotations<commit_after>var request = require('./lib/databox-request/databox-request.js')();
var basicAuth = require('basic-auth');
var macaroons = require('macaroons.js');
var pathToRegexp = require('path-to-regexp');


const DATABOX_ARBITER_ENDPOINT = process.env.DATABOX_ARBITER_ENDPOINT || "https://databox-arbiter:8080" 


/**
 * @return {Promise} A promise that resolves with a shared secret gotten from the arbiter
 */
module.exports.getSecretFromArbiter = function(arbiterKey) {
	return new Promise((resolve, reject) => {
		if (!arbiterKey) {
			resolve('');
			return;
		}

		// TODO: Could just make it port 80 arbiter-side since permissions don't matter in the container anyway...
		request.get('http://'+arbiterKey+'@'+DATABOX_ARBITER_ENDPOINT+'/store/secret', {})
		.then((error, response, body) => {
			if (error) {
				reject(error);
				return;
			}
			resolve(new Buffer(body, 'base64'));
		});

	});
};


/**
 * @param {String} secret Arbiter shared secret key
 * @param {String} storeName Store hostname
 * @return {Function} Macaroon verification middleware
 */
module.exports.verifier = function (secret, storeName) {

	/**
	 * Checks validity of the macaroon "path" caveat
	 * @param {String} path
	 * @param {String} caveat
	 * @return {Boolean} valid
	 */
	var isPathValid = function () {
		var prefixRegex = /path = .*/;
		var prefixLen   = 'path = '.length;

		return function (caveat, path) {
			if (!prefixRegex.test(caveat))
				return false;

			// TODO: Catch potential JSON.parse exception
			return pathToRegexp(JSON.parse(caveat.substring(prefixLen).trim())).test(path);
		}
	}();

	/**
	 * Returns a verifier for a given path
	 * @param {String} path
	 * @return {Function} Path verifier
	 */
	var createPathVerifier = function (path) {
		return function (caveat) {
			return isPathValid(caveat, path);
{'fraction_non_alphanumeric': 0.1464742717124966, 'fraction_numerical': 0.004356112169888375, 'mean_word_length': 3.985074626865672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '2194012', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1171, 'n_words': 305}