diff --git a/packages/google-cloud-oslogin/README.md b/packages/google-cloud-oslogin/README.md index 99e001c88c7..94d68659697 100644 --- a/packages/google-cloud-oslogin/README.md +++ b/packages/google-cloud-oslogin/README.md @@ -57,18 +57,40 @@ npm install @google-cloud/os-login ### Using the client library ```javascript -const {OsLoginServiceClient} = require('@google-cloud/os-login'); -const client = new OsLoginServiceClient(); - -async function quickstart() { - const [loginProfile] = await client.getLoginProfile({ - name: 'users/beckwith@google.com', - }); - console.log('Login Profile:'); - console.log(loginProfile); +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +/** + * Required. The unique ID for the user in format `users/{user}`. + */ +// const name = 'abc123' +/** + * The project ID of the Google Cloud Platform project. + */ +// const projectId = 'abc123' +/** + * A system ID for filtering the results of the request. + */ +// const systemId = 'abc123' + +// Imports the Oslogin library +const {OsLoginServiceClient} = require('@google-cloud/os-login').v1; + +// Instantiates a client +const osloginClient = new OsLoginServiceClient(); + +async function callGetLoginProfile() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await osloginClient.getLoginProfile(request); + console.log(response[0]); } -quickstart(); +callGetLoginProfile(); ``` diff --git a/packages/google-cloud-oslogin/samples/package.json b/packages/google-cloud-oslogin/samples/package.json index 5b96a6babd3..eb4ab106659 100644 --- a/packages/google-cloud-oslogin/samples/package.json +++ b/packages/google-cloud-oslogin/samples/package.json @@ -20,4 +20,4 @@ "chai": "^4.2.0", "mocha": "^8.0.0" } -} \ No newline at end of file +} diff --git a/packages/google-cloud-oslogin/samples/quickstart.js b/packages/google-cloud-oslogin/samples/quickstart.js index 21ca56a5fe6..586ac2df520 100644 --- a/packages/google-cloud-oslogin/samples/quickstart.js +++ b/packages/google-cloud-oslogin/samples/quickstart.js @@ -1,34 +1,64 @@ -// Copyright 2017 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** 'use strict'; -async function main() { +function main(name) { // [START oslogin_quickstart] - const {OsLoginServiceClient} = require('@google-cloud/os-login'); - const client = new OsLoginServiceClient(); - - async function quickstart() { - const [loginProfile] = await client.getLoginProfile({ - name: 'users/beckwith@google.com', - }); - console.log('Login Profile:'); - console.log(loginProfile); + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The unique ID for the user in format `users/{user}`. + */ + // const name = 'abc123' + /** + * The project ID of the Google Cloud Platform project. + */ + // const projectId = 'abc123' + /** + * A system ID for filtering the results of the request. + */ + // const systemId = 'abc123' + + // Imports the Oslogin library + const {OsLoginServiceClient} = require('@google-cloud/os-login').v1; + + // Instantiates a client + const osloginClient = new OsLoginServiceClient(); + + async function callGetLoginProfile() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await osloginClient.getLoginProfile(request); + console.log(response[0]); } - quickstart(); + callGetLoginProfile(); // [END oslogin_quickstart] } -main(); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-oslogin/samples/test/sample.test.js b/packages/google-cloud-oslogin/samples/test/sample.test.js index 502158cb630..2aa01a15cb7 100644 --- a/packages/google-cloud-oslogin/samples/test/sample.test.js +++ b/packages/google-cloud-oslogin/samples/test/sample.test.js @@ -21,10 +21,10 @@ const {execSync} = require('child_process'); const exec = cmd => execSync(cmd, {encoding: 'utf8'}); describe('sample tests', () => { - // This test current fails because it requires setup in the google-cloud-node - // project, running VMs, and a fair amount of infrastructure. - it.skip('should run the quickstart', () => { - const output = exec('node quickstart'); - assert.include(output, 'Login Profile:'); + it('should run the quickstart', () => { + const output = exec( + 'node quickstart users/kokoro-system-test@long-door-651.iam.gserviceaccount.com' + ); + assert(output !== null); }); });