<commit_before>'use strict';

var registry = require('./registry/index');
registry.init();
exports.registry = registry;

var soajsLogger = require('./logger/index');
exports.getLogger = soajsLogger.getLogger;
exports.getLog = soajsLogger.getLog;

exports.meta = require('./meta/index');
exports.error = require('./error/index');
exports.key = require('./key/index');
exports.provision = require('./provision/index');
exports.security = require('./security/index');
exports.getMail = require('./mail/index');
exports.validator = require('./validator/index');
exports.getHostIp = function (cb) {
    var ips = [];
    var ifnameLookupSequence = [];
    if (process.env.SOAJS_DEPLOY_HA) {
        var Docker = require('dockerode');
        var deployer = new Docker({socketPath: '/var/run/docker.sock'});
        var container = deployer.getContainer(process.env.HOSTNAME);
        container.inspect(function (error, containerInfo) {
            if (error) {
                return cb({"result": false, "ip": null, "extra": {"ips": ips, "n": ifnameLookupSequence}});
            }

            var taskName = containerInfo.Config.Labels['com.docker.swarm.task.name'];
            var swarmNetwork = containerInfo.NetworkSettings.Networks.soajsnet;

            return cb({
                "result": true,
                "ip": swarmNetwork.IPAddress,
                "extra": {"ips": ips, "n": ifnameLookupSequence, "swarmTask": taskName}
            });
        });
    }
    else {
        var os = require('os');
        var ifaces = os.networkInterfaces();
        ifnameLookupSequence = ["eth0", "en0", "eth1", "en1"];
        Object.keys(ifaces).forEach(function (ifname) {
            ifaces[ifname].forEach(function (iface) {
                if ('IPv4' !== iface.family || iface.internal !== false) {
                    // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
                    return;<commit_msg>Added support for kubernetes when fetching host ip<commit_after>'use strict';

var registry = require('./registry/index');
registry.init();
exports.registry = registry;

var soajsLogger = require('./logger/index');
exports.getLogger = soajsLogger.getLogger;
exports.getLog = soajsLogger.getLog;

exports.meta = require('./meta/index');
exports.error = require('./error/index');
exports.key = require('./key/index');
exports.provision = require('./provision/index');
exports.security = require('./security/index');
exports.getMail = require('./mail/index');
exports.validator = require('./validator/index');
exports.getHostIp = function (cb) {
    var ips = [];
    var ifnameLookupSequence = [];
    if (process.env.SOAJS_DEPLOY_HA) {
        if (process.env.SOAJS_DEPLOY_KUBE) {
            if (!process.env.SOAJS_KUBE_POD_IP || !process.env.SOAJS_KUBE_POD_NAME) {
                return cb({"result": false, "ip": null, "extra": {"ips": ips, "n": ifnameLookupSequence}});
            }

            return cb({
                "result": true,
                "ip": process.env.SOAJS_KUBE_POD_IP,
                "extra": {"ips": ips, "n": ifnameLookupSequence, "swarmTask": process.env.SOAJS_KUBE_POD_NAME}
            });
        }
        else {
            var Docker = require('dockerode');
            var deployer = new Docker({socketPath: '/var/run/docker.sock'});
            var container = deployer.getContainer(process.env.HOSTNAME);
            container.inspect(function (error, containerInfo) {
                if (error) {
                    return cb({"result": false, "ip": null, "extra": {"ips": ips, "n": ifnameLookupSequence}});
                }

                var taskName = containerInfo.Config.Labels['com.docker.swarm.task.name'];
                var swarmNetwork = containerInfo.NetworkSettings.Networks.soajsnet;

                return cb({
                    "result": true,
                    "ip": swarmNetwork.IPAddress,
                    "extra": {"ips": ips, "n": ifnameLookupSequence, "swarmTask": taskName}
                });
            });
        }
    }
    else {
        var os = require('os');
        var ifaces = os.networkInterfaces();
        ifnameLookupSequence = ["eth0", "en0", "eth1", "en1"];
        Object.keys(ifaces).forEach(function (ifname) {
            ifaces[ifname].forEach(function (iface) {
                if ('IPv4' !== iface.family || iface.internal !== false) {
                    // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
                    return;
{'fraction_non_alphanumeric': 0.1546023235031278, 'fraction_numerical': 0.005361930294906166, 'mean_word_length': 2.396813353566009, 'pattern_counts': {'":': 33, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2616038', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1285, 'n_words': 261}