-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend API Key Support (#1835)
* feat: Extend API Key Support * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Support `apiKey` as an ADC fallback * refactor: Move `apiKey` to base client options * docs: clarity * refactor: API Key Support * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: type * feat: Export Error Messages * test: Add tests for API Key Support * test: cleanup * docs: Clarifications * refactor: streamline * chore: merge cleanup * docs(sample): Add API Key Sample * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: OCD * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Apply suggestions from code review Co-authored-by: sofisl <[email protected]> * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: sofisl <[email protected]>
- Loading branch information
1 parent
e9459f3
commit 5fc3bcc
Showing
10 changed files
with
222 additions
and
50 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
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
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
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,63 @@ | ||
// Copyright 2024 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 | ||
// | ||
// 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. | ||
|
||
/** | ||
* Lists storage buckets by authenticating with ADC. | ||
*/ | ||
function main() { | ||
// [START apikeys_authenticate_api_key] | ||
|
||
const { | ||
v1: {LanguageServiceClient}, | ||
} = require('@google-cloud/language'); | ||
|
||
/** | ||
* Authenticates with an API key for Google Language service. | ||
* | ||
* @param {string} apiKey An API Key to use | ||
*/ | ||
async function authenticateWithAPIKey(apiKey) { | ||
const language = new LanguageServiceClient({apiKey}); | ||
|
||
// Alternatively: | ||
// const auth = new GoogleAuth({apiKey}); | ||
// const {GoogleAuth} = require('google-auth-library'); | ||
// const language = new LanguageServiceClient({auth}); | ||
|
||
const text = 'Hello, world!'; | ||
|
||
const [response] = await language.analyzeSentiment({ | ||
document: { | ||
content: text, | ||
type: 'PLAIN_TEXT', | ||
}, | ||
}); | ||
|
||
console.log(`Text: ${text}`); | ||
console.log( | ||
`Sentiment: ${response.documentSentiment.score}, ${response.documentSentiment.magnitude}` | ||
); | ||
console.log('Successfully authenticated using the API key'); | ||
} | ||
|
||
authenticateWithAPIKey(); | ||
// [END apikeys_authenticate_api_key] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
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
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
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
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
Oops, something went wrong.