Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var _getBQClient = function() {
if (bigquery === null) {
bigquery = gcloud.bigquery({
// We're using the API from the same project as the Cloud Function
projectId: process.env.GCP_PROJECT,
});
}
return bigquery;
};
exports.handler = function(event, context) {
var bigquery = gcloud.bigquery({
projectId: config.project,
keyFilename: 'gcpkey.json'
});
var table = bigquery.dataset(config.dataset).table(config.table);
var rows = [], i, l, kinesis;
console.log(config);
console.log(JSON.stringify(event, null, ' '));
var now = Math.floor(Date.now() / 1000);
for(i = 0, l = event.Records.length; i < l; ++i) {
kinesis = event.Records[i].kinesis;
var sequenceNumber = kinesis.sequenceNumber;
try {
var payload = JSON.parse(new Buffer(kinesis.data, 'base64').toString('utf8'));
rows.push(_.merge({ id: sequenceNumber, time: now }, payload));
} catch (err) {
BigQueryTable.prototype.bq = function () {
return gcloud.bigquery(this.projectSettings);
};