<commit_before>/*
 * Copyright 2016 Red Hat Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';

var rhea = require('rhea');
var path = require('path');
var fs = require('fs');
var Router = require('./qdr.js').Router;

var cert_dir = (process.env.CERT_DIR !== undefined) ? process.env.CERT_DIR : '/etc/enmasse-certs';
var ca_path = path.resolve(cert_dir, 'ca.crt');//TODO: allow setting via env var
var client_crt_path = path.resolve(cert_dir, 'tls.crt');//TODO: allow setting via env var
var client_key_path = path.resolve(cert_dir, 'tls.key');//TODO: allow setting via env var


function RouterStats(connection) {
    var options = { host: process.env.MESSAGING_SERVICE_HOST, port: process.env.MESSAGING_SERVICE_PORT_SECURE_INTERNAL};
    try {
        options.ca = [fs.readFileSync(ca_path)];
        options.key = fs.readFileSync(client_key_path);
        options.cert = fs.readFileSync(client_crt_path);
        options.transport = 'tls';
    //    options.enable_sasl_external = true;
        options.rejectUnauthorized = false;
    } catch (error) {
        console.warn('Error setting connection options ' + error);
    }

    //TODO: fix admin_service to be more sensibly generic
    var conn = connection || require('./admin_service.js').connect(rhea, options, 'MESSAGING');
    this.router = new Router(conn);
    var self = this;
    this.router.get_all_routers().then(function (routers) {
        self.routers = routers;
        console.log('routers: ' + self.routers.map(function (r) { return r.target; }));
    });
}

function clean_address(address) {
    if (!address) {
        return address;
    } else if (address.charAt(0) === 'M') {
        return address.substring(2);
    } else {
        return address.substring(1);
    }<commit_msg>Enable sasl_external for client<commit_after>/*
 * Copyright 2016 Red Hat Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';

var rhea = require('rhea');
var path = require('path');
var fs = require('fs');
var Router = require('./qdr.js').Router;

var cert_dir = (process.env.CERT_DIR !== undefined) ? process.env.CERT_DIR : '/etc/enmasse-certs';
var ca_path = path.resolve(cert_dir, 'ca.crt');//TODO: allow setting via env var
var client_crt_path = path.resolve(cert_dir, 'tls.crt');//TODO: allow setting via env var
var client_key_path = path.resolve(cert_dir, 'tls.key');//TODO: allow setting via env var


function RouterStats(connection) {
    var options = { host: process.env.MESSAGING_SERVICE_HOST, port: process.env.MESSAGING_SERVICE_PORT_SECURE_INTERNAL};
    try {
        options.ca = [fs.readFileSync(ca_path)];
        options.key = fs.readFileSync(client_key_path);
        options.cert = fs.readFileSync(client_crt_path);
        options.enable_sasl_external = true;
        options.transport = 'tls';
    //    options.enable_sasl_external = true;
        options.rejectUnauthorized = false;
    } catch (error) {
        console.warn('Error setting connection options ' + error);
    }

    //TODO: fix admin_service to be more sensibly generic
    var conn = connection || require('./admin_service.js').connect(rhea, options, 'MESSAGING');
    this.router = new Router(conn);
    var self = this;
    this.router.get_all_routers().then(function (routers) {
        self.routers = routers;
        console.log('routers: ' + self.routers.map(function (r) { return r.target; }));
    });
}

function clean_address(address) {
    if (!address) {
        return address;
    } else if (address.charAt(0) === 'M') {
        return address.substring(2);
    } else {
        return address.substring(1);
    }
{'fraction_non_alphanumeric': 0.1226557447725803, 'fraction_numerical': 0.004742401379607674, 'mean_word_length': 3.4787644787644787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1433257', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1400, 'n_words': 411}