From c00c94f6917b80be4b7484e8d0ee95e5cc5dd7e6 Mon Sep 17 00:00:00 2001 From: "Leah E. Cole" <6719667+leahecole@users.noreply.github.com> Date: Wed, 29 May 2019 19:50:27 +0200 Subject: [PATCH] fix: add kokoro config for composer-storage-trigger (#1321) * Upgrade composer sample to Node 8 * fix: Add CI test config --- .kokoro/functions/composer-storage-trigger.cfg | 13 +++++++++++++ functions/composer-storage-trigger/index.js | 12 ++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .kokoro/functions/composer-storage-trigger.cfg diff --git a/.kokoro/functions/composer-storage-trigger.cfg b/.kokoro/functions/composer-storage-trigger.cfg new file mode 100644 index 0000000000..d593cb72ed --- /dev/null +++ b/.kokoro/functions/composer-storage-trigger.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Set the folder in which the tests are run +env_vars: { + key: "PROJECT" + value: "functions/composer-storage-trigger" +} + +# Tell the trampoline which build file to use. +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/nodejs-docs-samples/.kokoro/build.sh" +} diff --git a/functions/composer-storage-trigger/index.js b/functions/composer-storage-trigger/index.js index e30022c351..3e6877aa76 100644 --- a/functions/composer-storage-trigger/index.js +++ b/functions/composer-storage-trigger/index.js @@ -28,10 +28,10 @@ const FormData = require('form-data'); * and * https://cloud.google.com/iap/docs/authentication-howto * - * @param {!Object} event The Cloud Functions event. + * @param {!Object} data The Cloud Functions event data. * @returns {Promise} */ -exports.triggerDag = async event => { +exports.triggerDag = async data => { // Fill in your Composer environment information here. // The project that holds your function @@ -47,7 +47,7 @@ exports.triggerDag = async event => { // Other constants const WEBSERVER_URL = `https://${WEBSERVER_ID}.appspot.com/api/experimental/dags/${DAG_NAME}/dag_runs`; const USER_AGENT = 'gcf-event-trigger'; - const BODY = {conf: JSON.stringify(event.data)}; + const BODY = {conf: JSON.stringify(data)}; // Make the request try { @@ -86,7 +86,7 @@ const authorizeIap = async (clientId, projectId, userAgent) => { headers: {'User-Agent': userAgent, 'Metadata-Flavor': 'Google'}, } ); - const tokenResponse = res.json(); + const tokenResponse = await res.json(); if (tokenResponse.error) { return Promise.reject(tokenResponse.error); } @@ -116,7 +116,7 @@ const authorizeIap = async (clientId, projectId, userAgent) => { }, } ); - const blobJson = blob.json(); + const blobJson = await blob.json(); if (blobJson.error) { return Promise.reject(blobJson.error); } @@ -132,7 +132,7 @@ const authorizeIap = async (clientId, projectId, userAgent) => { method: 'POST', body: form, }); - const tokenJson = token.json(); + const tokenJson = await token.json(); if (tokenJson.error) { return Promise.reject(tokenJson.error); }