ollixx / node-red-contrib-components

reusable flows with a well defined api
MIT License
8 stars 9 forks source link

Start Component firing off when not specifically called on. #59

Closed Kwitchlang closed 1 year ago

Kwitchlang commented 1 year ago

Not too sure whats happening here but its appears to be firing off all the Comp Start nodes in this Flow - its like it does a reverse Comp call - checking on weather a Comp Start contains the selected  'Use Comp' in any section of its flow upstream.

In the diagram it should only be firing off the arrows in green - however its also firing off the red ones - My guess is its because the red flows eventually contains a shared component the initial Start component 'Get Proxy Hosts' node?

Kind of like a reverse call - it finds the any Start Component node that wil eventually contain the 'Get Proxy Hosts' Start Component node.

Any light on this would be amazing, as I think this is and amazing tool to use as it helps with modualizing code.

ollixx commented 1 year ago

Hey Kwitchlang, thanks for posting the issue. Can you send the flow JSON with your example here? If so, make sure not to include any secrets etc. I will take look at it asap. Cheers :ollix

Kwitchlang commented 1 year ago

Sanatised the data. The nodes still work - even when its calling http requests

Im using v3.0.2 of NodeRED

Hope this helps! :)

[ { "id": "f6f2187d.f17ca8", "type": "tab", "label": "Nginx Proxy Manager", "disabled": false, "info": "" }, { "id": "4f44704bdf767d5a", "type": "group", "z": "f6f2187d.f17ca8", "name": "Commands", "style": { "label": true, "fill": "#ffff7f", "fill-opacity": "0.37" }, "nodes": [ "55795d7e7a0ab363", "61deb9feeaedb9b3", "cdf9cc869a10e208", "d1cc7dbee54d8137", "a1273b99f96aa086" ], "x": 334, "y": 559, "w": 932, "h": 162 }, { "id": "896785e50ef025a4", "type": "group", "z": "f6f2187d.f17ca8", "name": "Get NPM Information", "style": { "label": true }, "nodes": [ "44199a65e373b57f", "1e1b385f8c79e428", "388651196e40fb8a", "82de9b3b5880eb6e", "e2eaea6fb211552b", "b9f2281ceef9600d", "03bf9e6008a58569", "5a3d776f64ee868e", "3fbe638b944f943f", "e3dc2560ee47612e", "8147dd1dd44ae0be", "0ace509dd291fc40", "242c78767c2f8c47", "51bad06641c5750e", "4b0b46df4d5b9e61", "44073c816dd426ba", "39f2af6d04a80b15", "88483a9f73d10f92", "acd4cde7105096b8", "53cfd7816bbee7fc", "bd7096f282cf8756", "afe6d8567e9f65c2" ], "x": 334, "y": 79, "w": 2212, "h": 202 }, { "id": "b9e0b70de4f169b5", "type": "group", "z": "f6f2187d.f17ca8", "name": "Update NPM Entries", "style": { "label": true }, "nodes": [ "4aea0804c813dda7", "7553a49a12ce3fd9", "7dfbeb392913b83b", "20074a78e242d517", "76371d4260e7f4f6" ], "x": 334, "y": 319, "w": 2232, "h": 82 }, { "id": "44b89164832ffedf", "type": "group", "z": "f6f2187d.f17ca8", "name": "Create NPM Entry", "style": { "label": true }, "nodes": [ "46bbc29c631efdd0", "854600f0359e4a8b", "20ac283119f08ebd", "0af64a680604c2e0", "19ab2dfa4775e160" ], "x": 334, "y": 439, "w": 1072, "h": 82 }, { "id": "55795d7e7a0ab363", "type": "function", "z": "f6f2187d.f17ca8", "g": "4f44704bdf767d5a", "name": "Submit New NPM Entry", "func": "\n//var auth = context.flow.get(\"NPMToken\")\nvar container = global.get(\"Container\").data\nnode.warn(container.Forward_Scheme);\n\n\n//Make single entry into array\nvar domainArray = []\ndomainArray.push(container.subdomain)\n\n\n\n\n//msg = {}\nmsg.payload = {\n\n \"domain_names\": domainArray,\n \"forward_scheme\": container.Forward_Scheme,\n \"forward_host\": container.IP_Address,\n \"forward_port\": \"9999\",\n \"allow_websocket_upgrade\": 1,\n \"block_exploits\": 1\n}\n\n\n\n\n\n\n////////////Send information\nmsg.headers = {};\nmsg.url = global.get('NPM_API') + \"/nginx/proxy-hosts\"\nmsg.headers['Authorization'] = \"Bearer \" + context.flow.get(\"NPMToken\");\n//msg.headers['Authorization'] = \"Bearer \" + auth;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 950, "y": 600, "wires": [ [] ] }, { "id": "cdf9cc869a10e208", "type": "switch", "z": "f6f2187d.f17ca8", "g": "4f44704bdf767d5a", "name": "", "property": "action", "propertyType": "msg", "rules": [ { "t": "eq", "v": "", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 1, "x": 1190, "y": 600, "wires": [ [] ] }, { "id": "61deb9feeaedb9b3", "type": "inject", "z": "f6f2187d.f17ca8", "g": "4f44704bdf767d5a", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 440, "y": 680, "wires": [ [ "a1273b99f96aa086" ] ] }, { "id": "44199a65e373b57f", "type": "http request", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "", "method": "use", "ret": "obj", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "insecureHTTPParser": false, "authType": "", "senderr": false, "headers": [], "x": 1810, "y": 160, "wires": [ [ "82de9b3b5880eb6e" ] ] }, { "id": "1e1b385f8c79e428", "type": "function", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "NPM Send Authentication", "func": "var NPM = msg.NginxProxyManager\n\nmsg.headers = {};\nmsg.url = NPM.URL + NPM.API_Schema.Authenticate.Endpoint\nmsg.method = NPM.API_Schema.Authenticate.Method\nmsg.payload = NPM.API_Schema.Authenticate.Credentials\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1610, "y": 160, "wires": [ [ "44199a65e373b57f" ] ] }, { "id": "388651196e40fb8a", "type": "function", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "NPM Get Proxy Hosts", "func": "var token = msg.NginxProxyManager.Bearer\n\nvar NPM = msg.NginxProxyManager\n\n\n\n\n// msg = {}\nmsg.method = NPM.API_Schema.GetAllProxyHosts.Method\nmsg.payload = {}\nmsg.headers = {};\nmsg.url = NPM.URL + NPM.API_Schema.GetAllProxyHosts.Endpoint\nmsg.headers['Authorization'] = \"Bearer \" + token;\n\nreturn msg;\n\n\n\n", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1600, "y": 200, "wires": [ [ "e2eaea6fb211552b" ] ] }, { "id": "82de9b3b5880eb6e", "type": "function", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "Store Token Bearing", "func": "msg.NginxProxyManager.Bearer = msg.payload.token\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 2020, "y": 160, "wires": [ [ "51bad06641c5750e", "53cfd7816bbee7fc" ] ] }, { "id": "e2eaea6fb211552b", "type": "http request", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "", "method": "use", "ret": "obj", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "insecureHTTPParser": false, "authType": "", "senderr": false, "headers": [], "x": 1830, "y": 200, "wires": [ [ "4b0b46df4d5b9e61", "bd7096f282cf8756" ] ] }, { "id": "b9f2281ceef9600d", "type": "function", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "NPM Find Domain", "func": "var domainList = msg.payload\nvar Subdomain = '*'\nvar RootDomain = '.domain.example'\n\nvar domainSearch = Subdomain + RootDomain\n\n//Find Specific Domain name \n\n\n\n\nFindIDbyHostname(domainSearch);\n\n\nfunction FindIDbyHostname(searchedDomainEntry) \n{\n for (var item in domainList) \n {\n if (domainList[item].domain_names == searchedDomainEntry) \n {\n node.warn(\"Found Domain: \" + searchedDomainEntry);\n node.log(\"DomainFound\");\n msg.payload = \n { \n 'Item In Array': item, \n 'Domain Names': domainList[item].domain_names,\n 'ID Number': domainList[item].id\n }\n break\n }\n }\n if (domainList[item].domain_names != searchedDomainEntry)\n {\n node.warn('No Entry Found');\n msg.payload = null \n }\n}\n\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1590, "y": 240, "wires": [ [ "44073c816dd426ba", "afe6d8567e9f65c2" ] ] }, { "id": "4aea0804c813dda7", "type": "function", "z": "f6f2187d.f17ca8", "g": "b9e0b70de4f169b5", "name": "Update NPM Entry", "func": "msg.DirectusAPI.NPM.Payload\n\nvar hostID = flow.get(\"HostID\")\nvar domainList = flow.get(\"NPM\")\n\n//Find Specific Domain name \n\n\nmsg.payload = {\n \"domain_names\": [\"nodered.domain.example\"],\n \"forward_scheme\": \"http\",\n \"forward_host\": \"192.168.1.2\",\n \"forward_port\": \"1880\",\n \"allow_websocket_upgrade\": 1,\n \"block_exploits\": 1\n}\n\n\nmsg.headers = {};\nmsg.method = \"PUT\"\nmsg.url = \"https://10.10.1.1/api/nginx/proxy-hosts/\" + hostID\nmsg.headers['Authorization'] = \"Bearer \" + flow.get(\"NPMToken\");\n\nreturn msg;\n\n////////////////////////////////////\n//payload[17].domain_names[0]\n//payload.id", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1590, "y": 360, "wires": [ [ "7553a49a12ce3fd9" ] ] }, { "id": "7553a49a12ce3fd9", "type": "http request", "z": "f6f2187d.f17ca8", "g": "b9e0b70de4f169b5", "name": "", "method": "use", "ret": "txt", "paytoqs": "ignore", "url": "", "tls": "", "persist": false, "proxy": "", "insecureHTTPParser": false, "authType": "", "senderr": false, "headers": [], "x": 1830, "y": 360, "wires": [ [ "76371d4260e7f4f6" ] ] }, { "id": "03bf9e6008a58569", "type": "function", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "NPM API Schema", "func": "var NPM = \n{\n// URL: GetIPFromDirectus(),\n URL: 'http://10.10.1.1:81/api',\n HTTPS: false, //set true to use ina function when URL Requesting\n Bearer: 'null',\n\n API_Schema:\n {\n\n\n Authenticate:\n {\n Endpoint: '/tokens',\n Method: 'POST',\n Credentials:\n {\n// identity: GetIdentityFromDirectus(),\n// secret: GetSecretFromDirectus()\n identity: 'domain@example.com',\n secret: 'Sup3rS3cr3tP@ssw0rd'\n\n },\n Token: null \n },\n\n\n NewProxyEntry:\n {\n Endpoint: '/nginx/proxy-hosts',\n Method: 'POST',\n Payload: \n {\n \"domain_names\": [null], // '[\"nodered.domain.com,\"],\n \"forward_scheme\": null, // http / https\n \"forward_host\": null, // '10.10.X.X',\n \"forward_port\": null, // Exposed Port number,\n \"allow_websocket_upgrade\": null, // 1- yes,0 - No,\n \"block_exploits\": null, // 1- yes,0 - No,\n }\n },\n GetAllProxyHosts:\n {\n Endpoint: '/nginx/proxy-hosts',\n Method: 'GET',\n },\n \n \n GetAllUsers:\n {\n Endpoint: '/users',\n Method: 'GET',\n }\n }\n}\n\n\n\n\nfunction GetIPFromDirectus()\n{\n \n}\nfunction GetIPFromDirectus() \n{\n \n}\n\n\n\nmsg = { 'NginxProxyManager': NPM}\n\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1590, "y": 120, "wires": [ [ "242c78767c2f8c47", "acd4cde7105096b8" ] ] }, { "id": "5a3d776f64ee868e", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "Get Bearing Token", "api": [], "usecontext": true, "x": 450, "y": 160, "wires": [ [ "39f2af6d04a80b15" ] ] }, { "id": "3fbe638b944f943f", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "API NPM Schema", "api": [], "usecontext": true, "x": 450, "y": 120, "wires": [ [ "03bf9e6008a58569" ] ] }, { "id": "46bbc29c631efdd0", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "44b89164832ffedf", "name": "Create New NPM Entry", "api": [], "usecontext": true, "x": 460, "y": 480, "wires": [ [ "854600f0359e4a8b" ] ] }, { "id": "e3dc2560ee47612e", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "Get Proxy Hosts", "api": [], "usecontext": true, "x": 440, "y": 200, "wires": [ [ "88483a9f73d10f92" ] ] }, { "id": "8147dd1dd44ae0be", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "Find ID by Domain Name", "api": [], "usecontext": true, "x": 470, "y": 240, "wires": [ [ "0ace509dd291fc40" ] ] }, { "id": "7dfbeb392913b83b", "type": "component_in", "z": "f6f2187d.f17ca8", "g": "b9e0b70de4f169b5", "name": "Update NPM Entry", "api": [ { "name": "prop", "type": "any", "required": false, "contextOption": true } ], "usecontext": true, "x": 450, "y": 360, "wires": [ [ "20074a78e242d517" ] ] }, { "id": "20074a78e242d517", "type": "component", "z": "f6f2187d.f17ca8", "g": "b9e0b70de4f169b5", "name": "", "targetComponent": null, "targetComponentId": "8147dd1dd44ae0be", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 740, "y": 360, "wires": [ [ "4aea0804c813dda7" ] ] }, { "id": "0ace509dd291fc40", "type": "component", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "", "targetComponent": null, "targetComponentId": "e3dc2560ee47612e", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 770, "y": 240, "wires": [ [ "b9f2281ceef9600d" ] ] }, { "id": "242c78767c2f8c47", "type": "debug", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "[1]", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 2450, "y": 120, "wires": [] }, { "id": "51bad06641c5750e", "type": "debug", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "[2]", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 2450, "y": 160, "wires": [] }, { "id": "4b0b46df4d5b9e61", "type": "debug", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "[3]", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 2450, "y": 200, "wires": [] }, { "id": "44073c816dd426ba", "type": "debug", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "[4]", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 2450, "y": 240, "wires": [] }, { "id": "76371d4260e7f4f6", "type": "debug", "z": "f6f2187d.f17ca8", "g": "b9e0b70de4f169b5", "name": "[5]", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 2470, "y": 360, "wires": [] }, { "id": "854600f0359e4a8b", "type": "function", "z": "f6f2187d.f17ca8", "g": "44b89164832ffedf", "name": "function 1", "func": "msg.payload = \"this is a testoutput\"\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 700, "y": 480, "wires": [ [ "0af64a680604c2e0", "19ab2dfa4775e160" ] ] }, { "id": "20ac283119f08ebd", "type": "component_out", "z": "f6f2187d.f17ca8", "g": "44b89164832ffedf", "name": null, "mode": "default", "component_definitions_are_NOT_allowed_inside_subflows": false, "x": 1130, "y": 480, "wires": [] }, { "id": "0af64a680604c2e0", "type": "debug", "z": "f6f2187d.f17ca8", "g": "44b89164832ffedf", "name": "debug 22", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1300, "y": 480, "wires": [] }, { "id": "19ab2dfa4775e160", "type": "component", "z": "f6f2187d.f17ca8", "g": "44b89164832ffedf", "name": "", "targetComponent": null, "targetComponentId": "5a3d776f64ee868e", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 900, "y": 480, "wires": [ [ "20ac283119f08ebd" ] ] }, { "id": "d1cc7dbee54d8137", "type": "debug", "z": "f6f2187d.f17ca8", "g": "4f44704bdf767d5a", "name": "debug 23", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1000, "y": 680, "wires": [] }, { "id": "39f2af6d04a80b15", "type": "component", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "", "targetComponent": null, "targetComponentId": "3fbe638b944f943f", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 760, "y": 160, "wires": [ [ "1e1b385f8c79e428" ] ] }, { "id": "88483a9f73d10f92", "type": "component", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": "", "targetComponent": null, "targetComponentId": "5a3d776f64ee868e", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 760, "y": 200, "wires": [ [ "388651196e40fb8a" ] ] }, { "id": "a1273b99f96aa086", "type": "component", "z": "f6f2187d.f17ca8", "g": "4f44704bdf767d5a", "name": "", "targetComponent": null, "targetComponentId": "e3dc2560ee47612e", "paramSources": {}, "statuz": "", "statuzType": "str", "outputs": 1, "outLabels": [ "default" ], "x": 650, "y": 680, "wires": [ [ "d1cc7dbee54d8137" ] ] }, { "id": "acd4cde7105096b8", "type": "component_out", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": null, "mode": "default", "component_definitions_are_NOT_allowed_inside_subflows": false, "x": 2230, "y": 120, "wires": [] }, { "id": "53cfd7816bbee7fc", "type": "component_out", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": null, "mode": "default", "component_definitions_are_NOT_allowed_inside_subflows": false, "x": 2250, "y": 160, "wires": [] }, { "id": "bd7096f282cf8756", "type": "component_out", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": null, "mode": "default", "component_definitions_are_NOT_allowed_inside_subflows": false, "x": 2230, "y": 200, "wires": [] }, { "id": "afe6d8567e9f65c2", "type": "component_out", "z": "f6f2187d.f17ca8", "g": "896785e50ef025a4", "name": null, "mode": "default", "component_definitions_are_NOT_allowed_inside_subflows": false, "x": 2230, "y": 240, "wires": [] } ]

Kwitchlang commented 1 year ago

Any potential update on insite to this issue? Kind Regards

-K

ollixx commented 1 year ago

It looks like a bug. I am investigating...

ollixx commented 1 year ago

I found the problem after scanning through all of your code. In function node "NPM API Schema" you replace the msg completely, as you build it from scratch. That basically rips apart any context information, that the component nodes need and that is stored in msg._comp. Generally it is not a good idea to create a completely new msg object inside a flow, unless you are absolutely sure about what you are doing. Most nodes don't rely on state in msg, but some do - like the components.

What happens in this nested flows is, that when you replace the msg, the return nodes automatically fall back to a broadcast scenario, that triggers all matching run-nodes. That is what you see. All run nodes send the message. This broadcast is meant to be used for components, that get an external event from somewhere else.

So, if you cleanup your code, not removing any msg objects, all should be good.

Kwitchlang commented 1 year ago

Thanks heaps!

I added this to the scheme:

image Hopefully this will preserve the msg._comp data - have tested and it appears to work! ( although it may not be the best way to do it)

Thank you so much for looking into this! Absolute legend!

Take care. -K

ollixx commented 1 year ago

you'r welcome.

If you like, rate me here: https://flows.nodered.org/node/node-red-contrib-components