Skip to content

Instantly share code, notes, and snippets.

@alvarowolfx
Last active November 22, 2018 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvarowolfx/a58774867f39570ca8bd27cbcb631a11 to your computer and use it in GitHub Desktop.
Save alvarowolfx/a58774867f39570ca8bd27cbcb631a11 to your computer and use it in GitHub Desktop.
Google Cloud OTA Update Post - InsertBQ
const path = require( 'path' )
/**
* Generic background Cloud Function to be triggered by Cloud Storage.
*
* @param {object} data The event payload.
* @param {object} context The event metadata.
*/
exports.insertFirmwaresOnBigquery = ( data, context ) => {
const file = data;
const filename = path.basename( file.name )
const ext = path.extname( filename )
if ( ext !== '.bin' ) {
console.log( 'Not a firmware file.' )
return 'ok'
}
const filenameWithoutExt = path.basename( file.name, ext )
const dir = path.dirname( file.name )
const version = dir.split( '/' ).pop()
const variant = filenameWithoutExt.split( '_' ).pop()
const row = {
id : context.eventId,
bucket : file.bucket,
version,
fullname : file.name,
filename,
variant,
createdAt : file.timeCreated,
eventType : context.eventType,
}
console.log( 'Row to insert', row )
return insertIntoBigquery( row )
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment