<commit_before>/*jslint node: true */
var request = require('request');
var apigee = require('../config.js');
var proxies;
module.exports = function(grunt) {
	'use strict';
	grunt.registerTask('exportProxies', 'Export all proxies from org ' + apigee.from.org + " [" + apigee.from.version + "]", function() {
		var url = apigee.from.url;
		var org = apigee.from.org;
		var userid = apigee.from.userid;
		var passwd = <PASSWORD>;
		var fs = require('fs');
		var filepath = grunt.config.get("exportProxies.dest.data");
		var done_count =0;
		var done = this.async();
        // var done = this.async();
		grunt.verbose.write("getting proxies..." + url);
		url = url + "/v1/organizations/" + org + "/apis";

		request(url, function (error, response, body) {
			if (!error && response.statusCode == 200) {
			    proxies =  JSON.parse(body);
			   
			    for (var i = 0; i < proxies.length; i++) {
			    	var proxy_url = url + "/" + proxies[i];
			    	grunt.file.mkdir(filepath);

			    	//Call proxy details
					request(proxy_url, function (error, response, body) {
						if (!error && response.statusCode == 200) {
							grunt.verbose.write(body);
						    var proxy_detail =  JSON.parse(body);
                            // var proxy_file = filepath + "/" + proxy_detail.name;
						    // gets max revision - May not be the deployed version
						    var max_rev = proxy_detail.revision[proxy_detail.revision.length -1];

						    var proxy_download_url = url + "/" + proxy_detail.name + "/revisions/" + max_rev + "?format=bundle";
						    grunt.verbose.writeln ("\nFetching proxy bundle  : " + proxy_download_url);

						    request(proxy_download_url).auth(userid, passwd, true)
							  .pipe(fs.createWriteStream(filepath + "/" + proxy_detail.name + '.zip'))
							  .on('close', function () {
							    //grunt.verbose.writeln('Proxy File written!');
							});
						}
						else
						{
							grunt.log.error(error);
						}
						done_count++;
						if (done_count == proxies.length)
						{
							grunt.log.ok('Exported ' + done_count + ' proxies.');
							done();
						}
					}).auth(userid, passwd, true);
			    	// End proxy details
			    }; 			    
			} 
			else
			{
				grunt.log.error(error);
			}
		}).auth(userid, passwd, true);
	});

	grunt.registerMultiTask('importProxies', 'Import all proxies to org ' + apigee.to.org + " [" + apigee.to.version + "]", function() {
		var url = apigee.to.url;
		var org = apigee.to.org;
		var userid = apigee.to.userid;
		var passwd = <PASSWORD>;
		var files;
		var done_count = 0;
		url = url + "/v1/organizations/" + org + "/apis?action=import&name=";
		var fs = require('fs');
		var opts = {flatten: false};
		var f = grunt.option('src');
		if (f)
		{
			grunt.verbose.writeln('src pattern = ' + f);
			files = grunt.file.expand(opts,f);
		}
		else
		{
			files = this.filesSrc;
		}

		files.forEach(function(filepath) {
			//console.log(filepath);
			var filename = filepath.replace(/^.*[\\\/]/, '');
			var name = filename.slice(0, -4);
			//console.log(name);
			var req = request.post(url+name, function (err, resp, body) {
			  if (err) {
			    grunt.verbose.log(err);
			  } else {
			    grunt.verbose.writeln('Resp [' + resp.statusCode + '] for proxy creation ' + this.url + ' -> ' + body);<commit_msg>feat - change logger per grunt-docs<commit_after>/*jslint node: true */
var request = require('request');
var apigee = require('../config.js');
var proxies;
module.exports = function(grunt) {
	'use strict';
	grunt.registerTask('exportProxies', 'Export all proxies from org ' + apigee.from.org + " [" + apigee.from.version + "]", function() {
		var url = apigee.from.url;
		var org = apigee.from.org;
		var userid = apigee.from.userid;
		var passwd = <PASSWORD>;
		var fs = require('fs');
		var filepath = grunt.config.get("exportProxies.dest.data");
		var done_count =0;
		var done = this.async();
        // var done = this.async();
		grunt.verbose.write("getting proxies..." + url);
		url = url + "/v1/organizations/" + org + "/apis";

		request(url, function (error, response, body) {
			if (!error && response.statusCode == 200) {
			    proxies =  JSON.parse(body);
			   
			    for (var i = 0; i < proxies.length; i++) {
			    	var proxy_url = url + "/" + proxies[i];
			    	grunt.file.mkdir(filepath);

			    	//Call proxy details
					request(proxy_url, function (error, response, body) {
						if (!error && response.statusCode == 200) {
							grunt.verbose.write(body);
						    var proxy_detail =  JSON.parse(body);
                            // var proxy_file = filepath + "/" + proxy_detail.name;
						    // gets max revision - May not be the deployed version
						    var max_rev = proxy_detail.revision[proxy_detail.revision.length -1];

						    var proxy_download_url = url + "/" + proxy_detail.name + "/revisions/" + max_rev + "?format=bundle";
						    grunt.verbose.writeln ("\nFetching proxy bundle  : " + proxy_download_url);

						    request(proxy_download_url).auth(userid, passwd, true)
							  .pipe(fs.createWriteStream(filepath + "/" + proxy_detail.name + '.zip'))
							  .on('close', function () {
							    //grunt.verbose.writeln('Proxy File written!');
							});
						}
						else
						{
							grunt.log.error(error);
						}
						done_count++;
						if (done_count == proxies.length)
						{
							grunt.log.ok('Exported ' + done_count + ' proxies.');
							done();
						}
					}).auth(userid, passwd, true);
			    	// End proxy details
			    }; 			    
			} 
			else
			{
				grunt.log.error(error);
			}
		}).auth(userid, passwd, true);
	});

	grunt.registerMultiTask('importProxies', 'Import all proxies to org ' + apigee.to.org + " [" + apigee.to.version + "]", function() {
		var url = apigee.to.url;
		var org = apigee.to.org;
		var userid = apigee.to.userid;
		var passwd = apigee.to.passwd;
		var files;
		var done_count = 0;
		url = url + "/v1/organizations/" + org + "/apis?action=import&name=";
		var fs = require('fs');
		var opts = {flatten: false};
		var f = grunt.option('src');
		if (f)
		{
			grunt.verbose.writeln('src pattern = ' + f);
			files = grunt.file.expand(opts,f);
		}
		else
		{
			files = this.filesSrc;
		}

		files.forEach(function(filepath) {
			//console.log(filepath);
			var filename = filepath.replace(/^.*[\\\/]/, '');
			var name = filename.slice(0, -4);
			//console.log(name);
			var req = request.post(url+name, function (err, resp, body) {
			  if (err) {
			    grunt.log.error(err);
			  } else {
			    grunt.verbose.writeln('Resp [' + resp.statusCode + '] for proxy creation ' + this.url + ' -> ' + body);
{'fraction_non_alphanumeric': 0.16636363636363635, 'fraction_numerical': 0.004242424242424243, 'mean_word_length': 2.5, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4504886', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2255, 'n_words': 479}