Skip to content

Commit

Permalink
refactor(samples): replace promise with await async (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored and JustinBeckwith committed Nov 20, 2018
1 parent 18bf872 commit c4d7d85
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions packages/google-cloud-oslogin/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> node #{$0}'
);
}
async function main() {
// [START oslogin_quickstart]
if (
!process.env.GCLOUD_PROJECT ||
!process.env.GOOGLE_APPLICATION_CREDENTIALS
) {
throw new Error(
'Usage: GCLOUD_PROJECT=<project_id> GOOGLE_APPLICATION_CREDENTIALS=<path to key json file> 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);

0 comments on commit c4d7d85

Please sign in to comment.