ibmresearchuk / node-red-bluemix-nodes

A collection of node-red nodes for the IBM Bluemix platform
Apache License 2.0
33 stars 36 forks source link

way to access credentials from environment for mongo-db node #35

Open fraggys opened 8 years ago

fraggys commented 8 years ago

Mongo-db node is not persisting db credentials in database, each time i restart the credentials of mongodb gets lost. (I am using mongo by compose on bluemix to save flows)

knolleary commented 8 years ago

Could you provide some more details on your setup? I assume you are using a custom storage plugin to save your flows in mongo, rather then the cloudant plugin we provide? And that plugin is being provided its credentials via your settings file? If it is failing to store credentials you set in the editor, that sounds like a bug with the storage plugin you are using.

fraggys commented 8 years ago

I've only mongo db in my setup. I am saving flows and application data both in the same mongodb. For that aspect I've used, mongostorage.js instead of couchstorage.js. Setup is like below- 1) I started with node.js boilerplate app backed by mongodb. 2) Integrated NODE-RED within that app. 3) Used mongostorage.js to work with NODE-RED and I am able to save my flows/library functions in mongodb. 4) Now on my flow editor, I am using Mongo-db node to save my application data in the same mongodb which i just integrated and I am giving credentials inside the monog-db node.

Issue I am facing is when I restart my app, my db-credentials are lost and my API's stop working. Mongo-db node is not persisting credentials along with flows data in db.

knolleary commented 8 years ago

Ok, so this sounds like a bug in mongostorage.js - it isn't routinely used anywhere since we replaced it with the Cloudant based plugin. Are there any error messages in the log when you deploy? Are you able to look at the database contents to see if the credentials are getting saved as you'd expect to determine if its a saving or loading issue.

fraggys commented 8 years ago

In the database credentials are not stored. So its a saving issue and not a loading issue.

knolleary commented 8 years ago

Can you try to save some credentials in another node type - for example, the HTTP Request node lets you provide a username/password.

fraggys commented 8 years ago

Ok http-request node is not letting me deploy with credentials. Getting following error.

2016-02-09T21:36:47.64+0530 [App/0] OUT 9 Feb 16:06:47 - [warn] Error saving flows: The dotted field '419575e3.be6a8c' in 'credentials.419575e3.be6a8c' is not valid for storage. 2016-02-09T21:36:47.64+0530 [App/0] OUT 9 Feb 16:06:47 - [warn] MongoError: The dotted field '419575e3.be6a8c' in 'credentials.419575e3.be6a8c' is not valid for storage. 2016-02-09T21:36:47.64+0530 [App/0] OUT at Function.MongoError.create (/home/vcap/app/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11) 2016-02-09T21:36:47.64+0530 [App/0] OUT at toError (/home/vcap/app/node_modules/mongodb/lib/utils.js:114:22) 2016-02-09T21:36:47.64+0530 [App/0] OUT at /home/vcap/app/node_modules/mongodb/lib/collection.js:985:67 2016-02-09T21:36:47.64+0530 [App/0] OUT at handler (/home/vcap/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:378:5) 2016-02-09T21:36:47.64+0530 [App/0] OUT at /home/vcap/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:780:13 2016-02-09T21:36:47.64+0530 [App/0] OUT at Callbacks.emit (/home/vcap/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:95:3) 2016-02-09T21:36:47.64+0530 [App/0] OUT at null.messageHandler (/home/vcap/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:249:23) 2016-02-09T21:36:47.64+0530 [App/0] OUT at Socket.<anonymous> (/home/vcap/app/node_modules/mongodb/node_modules /mongodb-core/lib/connection/connection.js:265:22) 2016-02-09T21:36:47.64+0530 [App/0] OUT at Socket.emit (events.js:107:17) 2016-02-09T21:36:47.64+0530 [App/0] OUT at readableAddChunk (_stream_readable.js:163:16) 2016-02-09T21:36:47.64+0530 [App/0] OUT at Socket.Readable.push (_stream_readable.js:126:10) 2016-02-09T21:36:47.64+0530 [App/0] OUT at TCP.onread (net.js:540:20)

knolleary commented 8 years ago

Great - that's the bug then. The mongostorage plugin is quite old and unloved - really should move it out to its own repo so it can be maintained properly

purval commented 8 years ago

Is there a solution for this problem? I have a similar setup like Fraggys. I am using mongodb for storing data as well as node red flow. When I am trying to use http request node, it gives me the same error as fraggy has provided in the previous comment.

knolleary commented 8 years ago

@purval you'll need to patch mongostorage.js so it doesn't try to use keys with . in their name.