-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: improve the quickstart sample (#172)
- Loading branch information
1 parent
ed5ea1b
commit 4509e8e
Showing
4 changed files
with
49 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
{ | ||
"name": "nodejs-docs-samples-os-login", | ||
"version": "0.0.1", | ||
"license": "Apache-2.0", | ||
"author": "Google Inc.", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"files": [ | ||
"*.js" | ||
], | ||
"repository": "googleapis/nodejs-os-login", | ||
"private": true, | ||
"semistandard": { | ||
"ignore": [ | ||
"node_modules" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "node -e 'console.log(`no tests`)'" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"@google-cloud/os-login": "^0.3.2" | ||
}, | ||
"devDependencies": { | ||
"@google-cloud/nodejs-repo-tools": "^3.0.0" | ||
"chai": "^4.2.0", | ||
"mocha": "^6.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,30 +16,19 @@ | |
|
||
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 {OsLoginServiceClient} = require('@google-cloud/os-login'); | ||
const client = new OsLoginServiceClient(); | ||
|
||
async function quickstart() { | ||
const [loginProfile] = await client.getLoginProfile({ | ||
name: 'users/[email protected]', | ||
}); | ||
console.log('Login Profile:'); | ||
console.log(loginProfile); | ||
} | ||
|
||
const oslogin = require('@google-cloud/os-login'); | ||
|
||
const projectId = process.env.GCLOUD_PROJECT; | ||
|
||
const client = new oslogin.OsLoginServiceClient({ | ||
projectId: projectId, | ||
}); | ||
|
||
const request = { | ||
name: 'users/1234abcd', | ||
}; | ||
|
||
const [loginProfile] = await client.getLoginProfile(request); | ||
console.log(loginProfile); | ||
quickstart(); | ||
// [END oslogin_quickstart] | ||
} | ||
|
||
main().catch(console.error); | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
env: | ||
mocha: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2019, Google LLC All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// 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. | ||
|
||
'use strict'; | ||
|
||
const {assert} = require('chai'); | ||
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:'); | ||
}); | ||
}); |