From c4d7d8549ef1fc93c2b82e346a077ffe48770adb Mon Sep 17 00:00:00 2001 From: praveenqlogic <44371467+praveenqlogic@users.noreply.github.com> Date: Wed, 21 Nov 2018 00:45:33 +0530 Subject: [PATCH] refactor(samples): replace promise with await async (#114) --- .../samples/quickstart.js | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/packages/google-cloud-oslogin/samples/quickstart.js b/packages/google-cloud-oslogin/samples/quickstart.js index 5de904d766d..0a7c931c862 100644 --- a/packages/google-cloud-oslogin/samples/quickstart.js +++ b/packages/google-cloud-oslogin/samples/quickstart.js @@ -14,35 +14,32 @@ 'use strict'; -// [START oslogin_quickstart] -if ( - !process.env.GCLOUD_PROJECT || - !process.env.GOOGLE_APPLICATION_CREDENTIALS -) { - throw new Error( - 'Usage: GCLOUD_PROJECT= GOOGLE_APPLICATION_CREDENTIALS= node #{$0}' - ); -} +async function main() { + // [START oslogin_quickstart] + if ( + !process.env.GCLOUD_PROJECT || + !process.env.GOOGLE_APPLICATION_CREDENTIALS + ) { + throw new Error( + 'Usage: GCLOUD_PROJECT= GOOGLE_APPLICATION_CREDENTIALS= node #{$0}' + ); + } -const oslogin = require('@google-cloud/os-login'); + const oslogin = require('@google-cloud/os-login'); -const projectId = process.env.GCLOUD_PROJECT; + const projectId = process.env.GCLOUD_PROJECT; -const client = new oslogin.OsLoginServiceClient({ - projectId: projectId, -}); + const client = new oslogin.OsLoginServiceClient({ + projectId: projectId, + }); -const request = { - name: 'users/1234abcd', -}; + const request = { + name: 'users/1234abcd', + }; -client - .getLoginProfile(request) - .then(responses => { - const loginProfile = responses[0]; - console.log(loginProfile); - }) - .catch(err => { - console.error('ERROR:', err); - }); -// [END oslogin_quickstart] + const [loginProfile] = await client.getLoginProfile(request); + console.log(loginProfile); + // [END oslogin_quickstart] +} + +main().catch(console.error);