customCommands stored as binary data (BinData)

gbyers at indue.com.au gbyers at indue.com.au
Tue Aug 25 18:59:46 EDT 2015


> I've written a custom command that connects to an OpenVPN server & determines
> info about a device based on its ProvisioningCode & SerialNumber. The result 
> of that command is always a string, yet it's stored in mongo as BinData, 
> represented as some sort of hash. Therefore, if I create an alias for this 
> custom command to display in the UI, the output isn't as expected. Here's an 
> example ;
>
> > db.devices.find({}, {_customCommands: true})
> { "_id" : "XXXXXXXXXXXXXXX", "_customCommands" : { "openvpn" : { "_value" : BinData(0,"XXXXXXXX"), 
> "_timestamp" : ISODate("2015-08-25T01:50:31.721Z") } } }
>
> Is there a way to coerce this into mongo as type: 'string', or do I need to decode this using a parameter
> renderer within the UI?


Alrighty then. Turns out to be a PEBKAC issue. I was using a ssh2 module for Node.js that was encoding the result in a Buffer object. This must have been a recent change & it caught me out. Dumping deviceUpdates ;

	{ customCommands: [ [ 'openvpn', <Buffer 4d 57 30 30 30 36> ] ] }

The simple fix was to add a toString() to the result of my custom command ;

	return callback(err, result.toString());


Grant


_______________________________________________
Users mailing list
Users at lists.genieacs.com
http://lists.genieacs.com/mailman/listinfo/users


More information about the Users mailing list