How to use the @node-red/util.log function in @node-red/util

To help you get started, we’ve selected a few @node-red/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-red / node-red / packages / node_modules / @node-red / runtime / lib / storage / localfilesystem / projects / ssh / index.js View on Github external
* 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.
 **/

var fs = require('fs-extra');
var when = require('when');
var fspath = require("path");
var keygen = require("./keygen");

var settings;
var log = require("@node-red/util").log;
var sshkeyDir;
var userSSHKeyDir;

function init(_settings) {
    settings = _settings;
    sshkeyDir = fspath.resolve(fspath.join(settings.userDir, "projects", ".sshkeys"));
    userSSHKeyDir = fspath.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH, ".ssh");
    // console.log('sshkeys.init()');
    return fs.ensureDir(sshkeyDir);
}

function listSSHKeys(username) {
    return listSSHKeysInDir(sshkeyDir,username + '_').then(function(customKeys) {
        return listSSHKeysInDir(userSSHKeyDir).then(function(existingKeys) {
            existingKeys.forEach(function(k){
                k.system = true;
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / auth / index.js View on Github external
/**
 * @mixin @node-red/editor-api_auth
 */

var passport = require("passport");
var oauth2orize = require("oauth2orize");

var strategies = require("./strategies");
var Tokens = require("./tokens");
var Users = require("./users");
var permissions = require("./permissions");

var theme = require("../editor/theme");

var settings = null;
var log = require("@node-red/util").log; // TODO: separate module


passport.use(strategies.bearerStrategy.BearerStrategy);
passport.use(strategies.clientPasswordStrategy.ClientPasswordStrategy);
passport.use(strategies.anonymousStrategy);

var server = oauth2orize.createServer();

server.exchange(oauth2orize.exchange.password(strategies.passwordTokenExchange));

function init(_settings,storage) {
    settings = _settings;
    if (settings.adminAuth) {
        var mergedAdminAuth = Object.assign({}, settings.adminAuth, settings.adminAuth.module);
        Users.init(mergedAdminAuth);
        Tokens.init(mergedAdminAuth,storage);
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / util.js View on Github external
*
 * 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.
 **/


var log = require("@node-red/util").log; // TODO: separate module
var i18n = require("@node-red/util").i18n; // TODO: separate module


module.exports = {
    errorHandler: function(err,req,res,next) {
        //TODO: why this when rejectHandler also?!

        if (err.message === "request entity too large") {
            log.error(err);
        } else {
            log.error(err.stack);
        }
        log.audit({event: "api.error",error:err.code||"unexpected_error",message:err.toString()},req);
        res.status(400).json({error:"unexpected_error", message:err.toString()});
    },
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / auth / strategies.js View on Github external
* limitations under the License.
 **/

var BearerStrategy = require('passport-http-bearer').Strategy;
var ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy;

var passport = require("passport");
var crypto = require("crypto");
var util = require("util");

var Tokens = require("./tokens");
var Users = require("./users");
var Clients = require("./clients");
var permissions = require("./permissions");

var log = require("@node-red/util").log; // TODO: separate module

var bearerStrategy = function (accessToken, done) {
    // is this a valid token?
    Tokens.get(accessToken).then(function(token) {
        if (token) {
            Users.get(token.user).then(function(user) {
                if (user) {
                    done(null,user,{scope:token.scope});
                } else {
                    log.audit({event: "auth.invalid-token"});
                    done(null,false);
                }
            });
        } else {
            log.audit({event: "auth.invalid-token"});
            done(null,false);
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / context / index.js View on Github external
*
 * 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.
 **/

var clone = require("clone");
var log = require("@node-red/util").log;
var util = require("@node-red/util").util;
var memory = require("./memory");
var flows;

var settings;

// A map of scope id to context instance
var contexts = {};

// A map of store name to instance
var stores = {};
var storeList = [];
var defaultStore;

// Whether there context storage has been configured or left as default
var hasConfiguredStore = false;
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / storage / localfilesystem / projects / Project.js View on Github external
* limitations under the License.
 **/


var fs = require('fs-extra');
var when = require('when');
var fspath = require("path");
var os = require('os');

var gitTools = require("./git");
var util = require("../util");
var defaultFileSet = require("./defaultFileSet");
var sshKeys = require("./ssh");
var settings;
var runtime;
var log = require("@node-red/util").log;

var projectsDir;

var authCache = require("./git/authCache");

// TODO: DRY - red/api/editor/sshkeys !
function getSSHKeyUsername(userObj) {
    var username = '__default';
    if ( userObj && userObj.name ) {
        username = userObj.name;
    }
    return username;
}
function getGitUser(user) {
    var username;
    if (!user) {
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / storage / localfilesystem / index.js View on Github external
* 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.
 **/

var fs = require('fs-extra');
var when = require('when');
var fspath = require("path");

var log = require("@node-red/util").log; // TODO: separate module

var util = require("./util");
var library = require("./library");
var sessions = require("./sessions");
var runtimeSettings = require("./settings");
var projects = require("./projects");

var initialFlowLoadComplete = false;
var settings;

var localfilesystem = {
    init: function(_settings, runtime) {
        settings = _settings;

        var promises = [];
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / editor / index.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var express = require("express");
var path = require('path');

var comms = require("./comms");
var library = require("./library");
var info = require("./settings");

var auth = require("../auth");
var nodes = require("../admin/nodes"); // TODO: move /icons into here
var needsPermission;
var runtimeAPI;
var log = require("@node-red/util").log; // TODO: separate module
var i18n = require("@node-red/util").i18n; // TODO: separate module

var apiUtil = require("../util");

var ensureRuntimeStarted = function(req,res,next) {
    runtimeAPI.isStarted().then( started => {
        if (!started) {
            log.error("Node-RED runtime not started");
            res.status(503).send("Not started");
        } else {
            next()
        }
    })
}

module.exports = {
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / storage / localfilesystem / projects / index.js View on Github external
var fs = require('fs-extra');
var when = require('when');
var fspath = require("path");
var nodeFn = require('when/node/function');
var crypto = require('crypto');

var storageSettings = require("../settings");
var util = require("../util");
var gitTools = require("./git");
var sshTools = require("./ssh");

var Projects = require("./Project");

var settings;
var runtime;
var log = require("@node-red/util").log;

var projectsEnabled = false;
var projectLogMessages = [];

var projectsDir;
var activeProject

var globalGitUser = false;

function init(_settings, _runtime) {
    settings = _settings;
    runtime = _runtime;

    try {
        if (settings.editorTheme.projects.enabled === true) {
            projectsEnabled = true;
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / flows / util.js View on Github external
*
 * 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.
 **/
var clone = require("clone");
var redUtil = require("@node-red/util").util;
var Log = require("@node-red/util").log;
var subflowInstanceRE = /^subflow:(.+)$/;
var typeRegistry = require("@node-red/registry");

var envVarExcludes = {};

function diffNodes(oldNode,newNode) {
    if (oldNode == null) {
        return true;
    }
    var oldKeys = Object.keys(oldNode).filter(function(p) { return p != "x" && p != "y" && p != "wires" });
    var newKeys = Object.keys(newNode).filter(function(p) { return p != "x" && p != "y" && p != "wires" });
    if (oldKeys.length != newKeys.length) {
        return true;
    }
    for (var i=0;i