From 479983ae434683423f7de585a6683e3cf250fbd2 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 16 Jun 2023 23:38:33 +0000 Subject: [PATCH 1/2] feat!: move billling over to ESM using generator --- packages/google-cloud-billing/README.md | 175 +- .../google-cloud-billing/esm/src/index.ts | 28 + .../esm/src/v1/cloud_billing_client.ts | 1461 ++++++++++++++++ .../src/v1/cloud_billing_client_config.json | 76 + .../esm/src/v1/cloud_billing_proto_list.json | 4 + .../esm/src/v1/cloud_catalog_client.ts | 798 +++++++++ .../src/v1/cloud_catalog_client_config.json | 36 + .../esm/src/v1/cloud_catalog_proto_list.json | 4 + .../google-cloud-billing/esm/src/v1/index.ts | 20 + .../system-test/fixtures/sample/src/index.js | 28 + .../system-test/fixtures/sample/src/index.ts | 38 + .../esm/system-test/install.ts | 49 + .../esm/test/gapic_cloud_billing_v1.ts | 1550 +++++++++++++++++ .../esm/test/gapic_cloud_catalog_v1.ts | 689 ++++++++ packages/google-cloud-billing/package.json | 99 +- .../cloud_billing.create_billing_account.js | 2 +- .../v1/cloud_billing.get_billing_account.js | 2 +- .../v1/cloud_billing.get_iam_policy.js | 2 +- .../cloud_billing.get_project_billing_info.js | 2 +- .../v1/cloud_billing.list_billing_accounts.js | 2 +- ...cloud_billing.list_project_billing_info.js | 2 +- .../v1/cloud_billing.set_iam_policy.js | 2 +- .../v1/cloud_billing.test_iam_permissions.js | 4 +- .../cloud_billing.update_billing_account.js | 2 +- ...oud_billing.update_project_billing_info.js | 2 +- .../v1/cloud_catalog.list_services.js | 2 +- .../generated/v1/cloud_catalog.list_skus.js | 2 +- ...ppet_metadata_google.cloud.billing.v1.json | 563 ++++++ .../google-cloud-billing/tsconfig.esm.json | 23 + packages/google-cloud-billing/tsconfig.json | 14 +- .../google-cloud-billing/webpack.config.cjs | 64 + 31 files changed, 5516 insertions(+), 229 deletions(-) create mode 100644 packages/google-cloud-billing/esm/src/index.ts create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_billing_client.ts create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_billing_client_config.json create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_billing_proto_list.json create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_catalog_client.ts create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_catalog_client_config.json create mode 100644 packages/google-cloud-billing/esm/src/v1/cloud_catalog_proto_list.json create mode 100644 packages/google-cloud-billing/esm/src/v1/index.ts create mode 100644 packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.js create mode 100644 packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.ts create mode 100644 packages/google-cloud-billing/esm/system-test/install.ts create mode 100644 packages/google-cloud-billing/esm/test/gapic_cloud_billing_v1.ts create mode 100644 packages/google-cloud-billing/esm/test/gapic_cloud_catalog_v1.ts create mode 100644 packages/google-cloud-billing/samples/generated/v1/snippet_metadata_google.cloud.billing.v1.json create mode 100644 packages/google-cloud-billing/tsconfig.esm.json create mode 100644 packages/google-cloud-billing/webpack.config.cjs diff --git a/packages/google-cloud-billing/README.md b/packages/google-cloud-billing/README.md index f91fec725cc..4f22cab915e 100644 --- a/packages/google-cloud-billing/README.md +++ b/packages/google-cloud-billing/README.md @@ -1,174 +1 @@ -[//]: # "This README.md file is auto-generated, all changes to this file will be lost." -[//]: # "To regenerate it, use `python -m synthtool`." -Google Cloud Platform logo - -# [Cloud Billing: Node.js Client](https://github.com/googleapis/google-cloud-node) - -[![release level](https://img.shields.io/badge/release%20level-stable-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages) -[![npm version](https://img.shields.io/npm/v/@google-cloud/billing.svg)](https://www.npmjs.org/package/@google-cloud/billing) - - - - -Billing client for Node.js - - -A comprehensive list of changes in each version may be found in -[the CHANGELOG](https://github.com/googleapis/google-cloud-node/tree/main/packages/google-cloud-billing/CHANGELOG.md). - -* [Cloud Billing Node.js Client API Reference][client-docs] -* [Cloud Billing Documentation][product-docs] -* [github.com/googleapis/google-cloud-node/packages/google-cloud-billing](https://github.com/googleapis/google-cloud-node/tree/main/packages/google-cloud-billing) - -Read more about the client libraries for Cloud APIs, including the older -Google APIs Client Libraries, in [Client Libraries Explained][explained]. - -[explained]: https://cloud.google.com/apis/docs/client-libraries-explained - -**Table of contents:** - - -* [Quickstart](#quickstart) - * [Before you begin](#before-you-begin) - * [Installing the client library](#installing-the-client-library) - * [Using the client library](#using-the-client-library) -* [Samples](#samples) -* [Versioning](#versioning) -* [Contributing](#contributing) -* [License](#license) - -## Quickstart - -### Before you begin - -1. [Select or create a Cloud Platform project][projects]. -1. [Enable billing for your project][billing]. -1. [Enable the Cloud Billing API][enable_api]. -1. [Set up authentication with a service account][auth] so you can access the - API from your local workstation. - -### Installing the client library - -```bash -npm install @google-cloud/billing -``` - - -### Using the client library - -```javascript -// Imports the Google Cloud client library -const {CloudBillingClient} = require('@google-cloud/billing'); - -// Creates a client -const client = new CloudBillingClient(); - -// name = 'my-project' // Project name to list billing accounts for. - -async function listBillingAccounts() { - const [accounts] = await client.listBillingAccounts({ - name, - }); - console.info(`found ${accounts.length} billing accounts:`); - for (const account of accounts) { - console.info(`${account.displayName}:`); - console.info(`\topen: ${account.open}`); - console.info(`\tparentBillingAccount: ${account.masterBillingAccount}`); - } -} -listBillingAccounts(); - -``` - - - -## Samples - -Samples are in the [`samples/`](https://github.com/googleapis/google-cloud-node/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample. - -| Sample | Source Code | Try it | -| --------------------------- | --------------------------------- | ------ | -| Cloud_billing.create_billing_account | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js,samples/README.md) | -| Cloud_billing.get_billing_account | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js,samples/README.md) | -| Cloud_billing.get_iam_policy | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js,samples/README.md) | -| Cloud_billing.get_project_billing_info | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js,samples/README.md) | -| Cloud_billing.list_billing_accounts | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js,samples/README.md) | -| Cloud_billing.list_project_billing_info | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js,samples/README.md) | -| Cloud_billing.set_iam_policy | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js,samples/README.md) | -| Cloud_billing.test_iam_permissions | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js,samples/README.md) | -| Cloud_billing.update_billing_account | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js,samples/README.md) | -| Cloud_billing.update_project_billing_info | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js,samples/README.md) | -| Cloud_catalog.list_services | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js,samples/README.md) | -| Cloud_catalog.list_skus | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js,samples/README.md) | -| Quickstart | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/quickstart.js,samples/README.md) | -| Quickstart | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-billing/samples/test/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-billing/samples/test/quickstart.js,samples/README.md) | - - - -The [Cloud Billing Node.js Client API Reference][client-docs] documentation -also contains samples. - -## Supported Node.js Versions - -Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/). -Libraries are compatible with all current _active_ and _maintenance_ versions of -Node.js. -If you are using an end-of-life version of Node.js, we recommend that you update -as soon as possible to an actively supported LTS version. - -Google's client libraries support legacy versions of Node.js runtimes on a -best-efforts basis with the following warnings: - -* Legacy versions are not tested in continuous integration. -* Some security patches and features cannot be backported. -* Dependencies cannot be kept up-to-date. - -Client libraries targeting some end-of-life versions of Node.js are available, and -can be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag). -The dist-tags follow the naming convention `legacy-(version)`. -For example, `npm install @google-cloud/billing@legacy-8` installs client libraries -for versions compatible with Node.js 8. - -## Versioning - -This library follows [Semantic Versioning](http://semver.org/). - - - -This library is considered to be **stable**. The code surface will not change in backwards-incompatible ways -unless absolutely necessary (e.g. because of critical security issues) or with -an extensive deprecation period. Issues and requests against **stable** libraries -are addressed with the highest priority. - - - - - - -More Information: [Google Cloud Platform Launch Stages][launch_stages] - -[launch_stages]: https://cloud.google.com/terms/launch-stages - -## Contributing - -Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/google-cloud-node/blob/main/CONTRIBUTING.md). - -Please note that this `README.md`, the `samples/README.md`, -and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) -are generated from a central template. To edit one of these files, make an edit -to its templates in -[directory](https://github.com/googleapis/synthtool). - -## License - -Apache Version 2.0 - -See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/LICENSE) - -[client-docs]: https://cloud.google.com/nodejs/docs/reference/billing/latest -[product-docs]: https://cloud.google.com/billing/docs -[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png -[projects]: https://console.cloud.google.com/project -[billing]: https://support.google.com/cloud/answer/6293499#enable-billing -[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=cloudbilling.googleapis.com -[auth]: https://cloud.google.com/docs/authentication/getting-started +Billing: Nodejs Client diff --git a/packages/google-cloud-billing/esm/src/index.ts b/packages/google-cloud-billing/esm/src/index.ts new file mode 100644 index 00000000000..e4778cee81a --- /dev/null +++ b/packages/google-cloud-billing/esm/src/index.ts @@ -0,0 +1,28 @@ +// Copyright 2023 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 +// +// 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. ** + +import * as v1 from './v1/index.js'; +const CloudBillingClient = v1.CloudBillingClient; +type CloudBillingClient = v1.CloudBillingClient; +const CloudCatalogClient = v1.CloudCatalogClient; +type CloudCatalogClient = v1.CloudCatalogClient; +export {v1, CloudBillingClient, CloudCatalogClient}; +export default {v1, CloudBillingClient, CloudCatalogClient}; +// @ts-ignore +import * as protos from '../../protos/protos.js'; +export {protos} diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_billing_client.ts b/packages/google-cloud-billing/esm/src/v1/cloud_billing_client.ts new file mode 100644 index 00000000000..3b59a37e86e --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_billing_client.ts @@ -0,0 +1,1461 @@ +// Copyright 2023 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 +// +// 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. ** + +/* global window */ +import * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax'; +import {Transform} from 'stream'; +// @ts-ignore +import type * as protos from '../../../protos/protos'; +import * as cloud_billing_client_config from './cloud_billing_client_config.json'; +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; +const filename = fileURLToPath(import.meta.url); +const dirname = path.dirname(filename); + +/** + * Client JSON configuration object, loaded from + * `src/v1/cloud_billing_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +const gapicConfig = JSON.parse(fs.readFileSync(path.join(dirname, 'cloud_billing_client_config.json'),'utf8')); +const jsonProtos = JSON.parse(fs.readFileSync(path.join(dirname, '..', '..', '..', 'protos/protos.json'), 'utf8')); +const version = JSON.parse(fs.readFileSync(path.join(dirname, '..', '..', '..', '..', 'package.json'), 'utf8')).version; + +/** + * Retrieves the Google Cloud Console billing accounts and associates them with + * projects. + * @class + * @memberof v1 + */ +export class CloudBillingClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; + cloudBillingStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of CloudBillingClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. + * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new CloudBillingClient({fallback: 'rest'}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof CloudBillingClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = gax as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else if (opts.fallback === 'rest' ) { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Add ESM headers + const isEsm = true; + if (opts.libVersion && isEsm) { + clientHeader.push(`${opts.libVersion}-esm`); + } else if (opts.libVersion && !isEsm) { + clientHeader.push(`${opts.libVersion}-cjs`); + } + + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos as gax.protobuf.INamespace); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + billingAccountPathTemplate: new this._gaxModule.PathTemplate( + 'billingAccounts/{billing_account}' + ), + servicePathTemplate: new this._gaxModule.PathTemplate( + 'services/{service}' + ), + skuPathTemplate: new this._gaxModule.PathTemplate( + 'services/{service}/skus/{sku}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listBillingAccounts: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'billingAccounts'), + listProjectBillingInfo: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'projectBillingInfo') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.cloud.billing.v1.CloudBilling', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.cloudBillingStub) { + return this.cloudBillingStub; + } + + // Put together the "service stub" for + // google.cloud.billing.v1.CloudBilling. + this.cloudBillingStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.billing.v1.CloudBilling') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.cloud.billing.v1.CloudBilling, + this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const cloudBillingStubMethods = + ['getBillingAccount', 'listBillingAccounts', 'updateBillingAccount', 'createBillingAccount', 'listProjectBillingInfo', 'getProjectBillingInfo', 'updateProjectBillingInfo', 'getIamPolicy', 'setIamPolicy', 'testIamPermissions']; + for (const methodName of cloudBillingStubMethods) { + const callPromise = this.cloudBillingStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.cloudBillingStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'cloudbilling.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'cloudbilling.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-billing', + 'https://www.googleapis.com/auth/cloud-billing.readonly', + 'https://www.googleapis.com/auth/cloud-platform' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- +/** + * Gets information about a billing account. The current authenticated user + * must be a [viewer of the billing + * account](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the billing account to retrieve. For + * example, `billingAccounts/012345-567890-ABCDEF`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.get_billing_account.js + * region_tag:cloudbilling_v1_generated_CloudBilling_GetBillingAccount_async + */ + getBillingAccount( + request?: protos.google.cloud.billing.v1.IGetBillingAccountRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|undefined, {}|undefined + ]>; + getBillingAccount( + request: protos.google.cloud.billing.v1.IGetBillingAccountRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + getBillingAccount( + request: protos.google.cloud.billing.v1.IGetBillingAccountRequest, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + getBillingAccount( + request?: protos.google.cloud.billing.v1.IGetBillingAccountRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IGetBillingAccountRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.getBillingAccount(request, options, callback); + } +/** + * Updates a billing account's fields. + * Currently the only field that can be edited is `display_name`. + * The current authenticated user must have the `billing.accounts.update` + * IAM permission, which is typically given to the + * [administrator](https://cloud.google.com/billing/docs/how-to/billing-access) + * of the billing account. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the billing account resource to be updated. + * @param {google.cloud.billing.v1.BillingAccount} request.account + * Required. The billing account resource to replace the resource on the + * server. + * @param {google.protobuf.FieldMask} request.updateMask + * The update mask applied to the resource. + * Only "display_name" is currently supported. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.update_billing_account.js + * region_tag:cloudbilling_v1_generated_CloudBilling_UpdateBillingAccount_async + */ + updateBillingAccount( + request?: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|undefined, {}|undefined + ]>; + updateBillingAccount( + request: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + updateBillingAccount( + request: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + updateBillingAccount( + request?: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.IUpdateBillingAccountRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.updateBillingAccount(request, options, callback); + } +/** + * This method creates [billing + * subaccounts](https://cloud.google.com/billing/docs/concepts#subaccounts). + * + * Google Cloud resellers should use the + * Channel Services APIs, + * [accounts.customers.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers/create) + * and + * [accounts.customers.entitlements.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers.entitlements/create). + * + * When creating a subaccount, the current authenticated user must have the + * `billing.accounts.update` IAM permission on the parent account, which is + * typically given to billing account + * [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). + * This method will return an error if the parent account has not been + * provisioned as a reseller account. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.cloud.billing.v1.BillingAccount} request.billingAccount + * Required. The billing account resource to create. + * Currently CreateBillingAccount only supports subaccount creation, so + * any created billing accounts must be under a provided parent billing + * account. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.create_billing_account.js + * region_tag:cloudbilling_v1_generated_CloudBilling_CreateBillingAccount_async + */ + createBillingAccount( + request?: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|undefined, {}|undefined + ]>; + createBillingAccount( + request: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + createBillingAccount( + request: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, + callback: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|null|undefined, + {}|null|undefined>): void; + createBillingAccount( + request?: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount, + protos.google.cloud.billing.v1.ICreateBillingAccountRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + this.initialize(); + return this.innerApiCalls.createBillingAccount(request, options, callback); + } +/** + * Gets the billing information for a project. The current authenticated user + * must have the `resourcemanager.projects.get` permission for the project, + * which can be granted by assigning the [Project + * Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles) + * role. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the project for which billing information is + * retrieved. For example, `projects/tokyo-rain-123`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.cloud.billing.v1.ProjectBillingInfo|ProjectBillingInfo}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.get_project_billing_info.js + * region_tag:cloudbilling_v1_generated_CloudBilling_GetProjectBillingInfo_async + */ + getProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|undefined, {}|undefined + ]>; + getProjectBillingInfo( + request: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): void; + getProjectBillingInfo( + request: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, + callback: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): void; + getProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.getProjectBillingInfo(request, options, callback); + } +/** + * Sets or updates the billing account associated with a project. You specify + * the new billing account by setting the `billing_account_name` in the + * `ProjectBillingInfo` resource to the resource name of a billing account. + * Associating a project with an open billing account enables billing on the + * project and allows charges for resource usage. If the project already had a + * billing account, this method changes the billing account used for resource + * usage charges. + * + * *Note:* Incurred charges that have not yet been reported in the transaction + * history of the Google Cloud Console might be billed to the new billing + * account, even if the charge occurred before the new billing account was + * assigned to the project. + * + * The current authenticated user must have ownership privileges for both the + * [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo + * ) and the [billing + * account](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * You can disable billing on the project by setting the + * `billing_account_name` field to empty. This action disassociates the + * current billing account from the project. Any billable activity of your + * in-use services will stop, and your application could stop functioning as + * expected. Any unbilled charges to date will be billed to the previously + * associated account. The current authenticated user must be either an owner + * of the project or an owner of the billing account for the project. + * + * Note that associating a project with a *closed* billing account will have + * much the same effect as disabling billing on the project: any paid + * resources used by the project will be shut down. Thus, unless you wish to + * disable billing, you should always call this method with the name of an + * *open* billing account. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the project associated with the billing + * information that you want to update. For example, + * `projects/tokyo-rain-123`. + * @param {google.cloud.billing.v1.ProjectBillingInfo} request.projectBillingInfo + * The new billing information for the project. Read-only fields are ignored; + * thus, you can leave empty all fields except `billing_account_name`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.cloud.billing.v1.ProjectBillingInfo|ProjectBillingInfo}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.update_project_billing_info.js + * region_tag:cloudbilling_v1_generated_CloudBilling_UpdateProjectBillingInfo_async + */ + updateProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|undefined, {}|undefined + ]>; + updateProjectBillingInfo( + request: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): void; + updateProjectBillingInfo( + request: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, + callback: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): void; + updateProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo, + protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.updateProjectBillingInfo(request, options, callback); + } +/** + * Gets the access control policy for a billing account. + * The caller must have the `billing.accounts.getIamPolicy` permission on the + * account, which is often given to billing account + * [viewers](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {google.iam.v1.GetPolicyOptions} request.options + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.iam.v1.Policy|Policy}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.get_iam_policy.js + * region_tag:cloudbilling_v1_generated_CloudBilling_GetIamPolicy_async + */ + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request: protos.google.iam.v1.IGetIamPolicyRequest, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + getIamPolicy( + request?: protos.google.iam.v1.IGetIamPolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.IGetIamPolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'resource': request.resource ?? '', + }); + this.initialize(); + return this.innerApiCalls.getIamPolicy(request, options, callback); + } +/** + * Sets the access control policy for a billing account. Replaces any existing + * policy. + * The caller must have the `billing.accounts.setIamPolicy` permission on the + * account, which is often given to billing account + * [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy is being specified. + * See the operation documentation for the appropriate value for this field. + * @param {google.iam.v1.Policy} request.policy + * REQUIRED: The complete policy to be applied to the `resource`. The size of + * the policy is limited to a few 10s of KB. An empty policy is a + * valid policy but certain Cloud Platform services (such as Projects) + * might reject them. + * @param {google.protobuf.FieldMask} request.updateMask + * OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only + * the fields in the mask will be modified. If no mask is provided, the + * following default mask is used: + * + * `paths: "bindings, etag"` + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.iam.v1.Policy|Policy}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.set_iam_policy.js + * region_tag:cloudbilling_v1_generated_CloudBilling_SetIamPolicy_async + */ + setIamPolicy( + request?: protos.google.iam.v1.ISetIamPolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|undefined, {}|undefined + ]>; + setIamPolicy( + request: protos.google.iam.v1.ISetIamPolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + setIamPolicy( + request: protos.google.iam.v1.ISetIamPolicyRequest, + callback: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|null|undefined, + {}|null|undefined>): void; + setIamPolicy( + request?: protos.google.iam.v1.ISetIamPolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.iam.v1.IPolicy, + protos.google.iam.v1.ISetIamPolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'resource': request.resource ?? '', + }); + this.initialize(); + return this.innerApiCalls.setIamPolicy(request, options, callback); + } +/** + * Tests the access control policy for a billing account. This method takes + * the resource and a set of permissions as input and returns the subset of + * the input permissions that the caller is allowed for that resource. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.resource + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + * @param {string[]} request.permissions + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing {@link protos.google.iam.v1.TestIamPermissionsResponse|TestIamPermissionsResponse}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.test_iam_permissions.js + * region_tag:cloudbilling_v1_generated_CloudBilling_TestIamPermissions_async + */ + testIamPermissions( + request?: protos.google.iam.v1.ITestIamPermissionsRequest, + options?: CallOptions): + Promise<[ + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|undefined, {}|undefined + ]>; + testIamPermissions( + request: protos.google.iam.v1.ITestIamPermissionsRequest, + options: CallOptions, + callback: Callback< + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|null|undefined, + {}|null|undefined>): void; + testIamPermissions( + request: protos.google.iam.v1.ITestIamPermissionsRequest, + callback: Callback< + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|null|undefined, + {}|null|undefined>): void; + testIamPermissions( + request?: protos.google.iam.v1.ITestIamPermissionsRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.iam.v1.ITestIamPermissionsResponse, + protos.google.iam.v1.ITestIamPermissionsRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'resource': request.resource ?? '', + }); + this.initialize(); + return this.innerApiCalls.testIamPermissions(request, options, callback); + } + + /** + * Lists the billing accounts that the current authenticated user has + * permission to + * [view](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListBillingAccounts` + * call. If unspecified, the first page of results is returned. + * @param {string} request.filter + * Options for how to filter the returned billing accounts. + * Currently this only supports filtering for + * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a + * single provided reseller billing account. + * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). + * Boolean algebra and other fields are not currently supported. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listBillingAccountsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listBillingAccounts( + request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount[], + protos.google.cloud.billing.v1.IListBillingAccountsRequest|null, + protos.google.cloud.billing.v1.IListBillingAccountsResponse + ]>; + listBillingAccounts( + request: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListBillingAccountsRequest, + protos.google.cloud.billing.v1.IListBillingAccountsResponse|null|undefined, + protos.google.cloud.billing.v1.IBillingAccount>): void; + listBillingAccounts( + request: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListBillingAccountsRequest, + protos.google.cloud.billing.v1.IListBillingAccountsResponse|null|undefined, + protos.google.cloud.billing.v1.IBillingAccount>): void; + listBillingAccounts( + request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.billing.v1.IListBillingAccountsRequest, + protos.google.cloud.billing.v1.IListBillingAccountsResponse|null|undefined, + protos.google.cloud.billing.v1.IBillingAccount>, + callback?: PaginationCallback< + protos.google.cloud.billing.v1.IListBillingAccountsRequest, + protos.google.cloud.billing.v1.IListBillingAccountsResponse|null|undefined, + protos.google.cloud.billing.v1.IBillingAccount>): + Promise<[ + protos.google.cloud.billing.v1.IBillingAccount[], + protos.google.cloud.billing.v1.IListBillingAccountsRequest|null, + protos.google.cloud.billing.v1.IListBillingAccountsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + this.initialize(); + return this.innerApiCalls.listBillingAccounts(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListBillingAccounts` + * call. If unspecified, the first page of results is returned. + * @param {string} request.filter + * Options for how to filter the returned billing accounts. + * Currently this only supports filtering for + * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a + * single provided reseller billing account. + * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). + * Boolean algebra and other fields are not currently supported. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listBillingAccountsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listBillingAccountsStream( + request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + const defaultCallSettings = this._defaults['listBillingAccounts']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listBillingAccounts.createStream( + this.innerApiCalls.listBillingAccounts as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listBillingAccounts`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListBillingAccounts` + * call. If unspecified, the first page of results is returned. + * @param {string} request.filter + * Options for how to filter the returned billing accounts. + * Currently this only supports filtering for + * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a + * single provided reseller billing account. + * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). + * Boolean algebra and other fields are not currently supported. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.billing.v1.BillingAccount|BillingAccount}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.list_billing_accounts.js + * region_tag:cloudbilling_v1_generated_CloudBilling_ListBillingAccounts_async + */ + listBillingAccountsAsync( + request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + const defaultCallSettings = this._defaults['listBillingAccounts']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listBillingAccounts.asyncIterate( + this.innerApiCalls['listBillingAccounts'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists the projects associated with a billing account. The current + * authenticated user must have the `billing.resourceAssociations.list` IAM + * permission, which is often given to billing account + * [viewers](https://cloud.google.com/billing/docs/how-to/billing-access). + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the billing account associated with the + * projects that you want to list. For example, + * `billingAccounts/012345-567890-ABCDEF`. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous `ListProjectBillingInfo` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of {@link protos.google.cloud.billing.v1.ProjectBillingInfo|ProjectBillingInfo}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listProjectBillingInfoAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo[], + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest|null, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse + ]>; + listProjectBillingInfo( + request: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse|null|undefined, + protos.google.cloud.billing.v1.IProjectBillingInfo>): void; + listProjectBillingInfo( + request: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse|null|undefined, + protos.google.cloud.billing.v1.IProjectBillingInfo>): void; + listProjectBillingInfo( + request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse|null|undefined, + protos.google.cloud.billing.v1.IProjectBillingInfo>, + callback?: PaginationCallback< + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse|null|undefined, + protos.google.cloud.billing.v1.IProjectBillingInfo>): + Promise<[ + protos.google.cloud.billing.v1.IProjectBillingInfo[], + protos.google.cloud.billing.v1.IListProjectBillingInfoRequest|null, + protos.google.cloud.billing.v1.IListProjectBillingInfoResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.listProjectBillingInfo(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the billing account associated with the + * projects that you want to list. For example, + * `billingAccounts/012345-567890-ABCDEF`. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous `ListProjectBillingInfo` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.billing.v1.ProjectBillingInfo|ProjectBillingInfo} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listProjectBillingInfoAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listProjectBillingInfoStream( + request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listProjectBillingInfo']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listProjectBillingInfo.createStream( + this.innerApiCalls.listProjectBillingInfo as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listProjectBillingInfo`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The resource name of the billing account associated with the + * projects that you want to list. For example, + * `billingAccounts/012345-567890-ABCDEF`. + * @param {number} request.pageSize + * Requested page size. The maximum page size is 100; this is also the + * default. + * @param {string} request.pageToken + * A token identifying a page of results to be returned. This should be a + * `next_page_token` value returned from a previous `ListProjectBillingInfo` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.billing.v1.ProjectBillingInfo|ProjectBillingInfo}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_billing.list_project_billing_info.js + * region_tag:cloudbilling_v1_generated_CloudBilling_ListProjectBillingInfo_async + */ + listProjectBillingInfoAsync( + request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'name': request.name ?? '', + }); + const defaultCallSettings = this._defaults['listProjectBillingInfo']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listProjectBillingInfo.asyncIterate( + this.innerApiCalls['listProjectBillingInfo'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified billingAccount resource name string. + * + * @param {string} billing_account + * @returns {string} Resource name string. + */ + billingAccountPath(billingAccount:string) { + return this.pathTemplates.billingAccountPathTemplate.render({ + billing_account: billingAccount, + }); + } + + /** + * Parse the billing_account from BillingAccount resource. + * + * @param {string} billingAccountName + * A fully-qualified path representing BillingAccount resource. + * @returns {string} A string representing the billing_account. + */ + matchBillingAccountFromBillingAccountName(billingAccountName: string) { + return this.pathTemplates.billingAccountPathTemplate.match(billingAccountName).billing_account; + } + + /** + * Return a fully-qualified service resource name string. + * + * @param {string} service + * @returns {string} Resource name string. + */ + servicePath(service:string) { + return this.pathTemplates.servicePathTemplate.render({ + service: service, + }); + } + + /** + * Parse the service from Service resource. + * + * @param {string} serviceName + * A fully-qualified path representing Service resource. + * @returns {string} A string representing the service. + */ + matchServiceFromServiceName(serviceName: string) { + return this.pathTemplates.servicePathTemplate.match(serviceName).service; + } + + /** + * Return a fully-qualified sku resource name string. + * + * @param {string} service + * @param {string} sku + * @returns {string} Resource name string. + */ + skuPath(service:string,sku:string) { + return this.pathTemplates.skuPathTemplate.render({ + service: service, + sku: sku, + }); + } + + /** + * Parse the service from Sku resource. + * + * @param {string} skuName + * A fully-qualified path representing Sku resource. + * @returns {string} A string representing the service. + */ + matchServiceFromSkuName(skuName: string) { + return this.pathTemplates.skuPathTemplate.match(skuName).service; + } + + /** + * Parse the sku from Sku resource. + * + * @param {string} skuName + * A fully-qualified path representing Sku resource. + * @returns {string} A string representing the sku. + */ + matchSkuFromSkuName(skuName: string) { + return this.pathTemplates.skuPathTemplate.match(skuName).sku; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.cloudBillingStub && !this._terminated) { + return this.cloudBillingStub.then(stub => { + this._terminated = true; + stub.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_billing_client_config.json b/packages/google-cloud-billing/esm/src/v1/cloud_billing_client_config.json new file mode 100644 index 00000000000..e98db6a6e4b --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_billing_client_config.json @@ -0,0 +1,76 @@ +{ + "interfaces": { + "google.cloud.billing.v1.CloudBilling": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "GetBillingAccount": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "ListBillingAccounts": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "UpdateBillingAccount": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "CreateBillingAccount": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListProjectBillingInfo": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetProjectBillingInfo": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "UpdateProjectBillingInfo": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "GetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "SetIamPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, + "TestIamPermissions": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_billing_proto_list.json b/packages/google-cloud-billing/esm/src/v1/cloud_billing_proto_list.json new file mode 100644 index 00000000000..e34eb066aa5 --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_billing_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/cloud/billing/v1/cloud_billing.proto", + "../../protos/google/cloud/billing/v1/cloud_catalog.proto" +] diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client.ts b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client.ts new file mode 100644 index 00000000000..5f5873a0e3d --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client.ts @@ -0,0 +1,798 @@ +// Copyright 2023 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 +// +// 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. ** + +/* global window */ +import * as gax from 'google-gax'; +import type {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax'; +import {Transform} from 'stream'; +// @ts-ignore +import type * as protos from '../../../protos/protos'; +import * as cloud_catalog_client_config from './cloud_catalog_client_config.json'; +import fs from 'fs'; +import path from 'path'; +import {fileURLToPath} from 'url'; +const filename = fileURLToPath(import.meta.url); +const dirname = path.dirname(filename); + +/** + * Client JSON configuration object, loaded from + * `src/v1/cloud_catalog_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +const gapicConfig = JSON.parse(fs.readFileSync(path.join(dirname, 'cloud_catalog_client_config.json'),'utf8')); +const jsonProtos = JSON.parse(fs.readFileSync(path.join(dirname, '..', '..', '..', 'protos/protos.json'), 'utf8')); +const version = JSON.parse(fs.readFileSync(path.join(dirname, '..', '..', '..', '..', 'package.json'), 'utf8')).version; + +/** + * A catalog of Google Cloud Platform services and SKUs. + * Provides pricing information and metadata on Google Cloud Platform services + * and SKUs. + * @class + * @memberof v1 + */ +export class CloudCatalogClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; + cloudCatalogStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of CloudCatalogClient. + * + * @param {object} [options] - The configuration object. + * The options accepted by the constructor are described in detail + * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * API remote host. + * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. + * Follows the structure of {@link gapicConfig}. + * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. + * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. + * For more information, please check the + * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. + * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you + * need to avoid loading the default gRPC version and want to use the fallback + * HTTP implementation. Load only fallback version and pass it to the constructor: + * ``` + * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC + * const client = new CloudCatalogClient({fallback: 'rest'}, gax); + * ``` + */ + constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof CloudCatalogClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Load google-gax module synchronously if needed + if (!gaxInstance) { + gaxInstance = gax as typeof gax; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else if (opts.fallback === 'rest' ) { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Add ESM headers + const isEsm = true; + if (opts.libVersion && isEsm) { + clientHeader.push(`${opts.libVersion}-esm`); + } else if (opts.libVersion && !isEsm) { + clientHeader.push(`${opts.libVersion}-cjs`); + } + + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos as gax.protobuf.INamespace); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + servicePathTemplate: new this._gaxModule.PathTemplate( + 'services/{service}' + ), + skuPathTemplate: new this._gaxModule.PathTemplate( + 'services/{service}/skus/{sku}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listServices: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'services'), + listSkus: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'skus') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.cloud.billing.v1.CloudCatalog', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = this._gaxModule.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.cloudCatalogStub) { + return this.cloudCatalogStub; + } + + // Put together the "service stub" for + // google.cloud.billing.v1.CloudCatalog. + this.cloudCatalogStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.billing.v1.CloudCatalog') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.cloud.billing.v1.CloudCatalog, + this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const cloudCatalogStubMethods = + ['listServices', 'listSkus']; + for (const methodName of cloudCatalogStubMethods) { + const callPromise = this.cloudCatalogStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor, + this._opts.fallback + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.cloudCatalogStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'cloudbilling.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'cloudbilling.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-billing', + 'https://www.googleapis.com/auth/cloud-billing.readonly', + 'https://www.googleapis.com/auth/cloud-platform' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- + + /** + * Lists all public cloud services. + * + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListServices` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of {@link protos.google.cloud.billing.v1.Service|Service}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listServicesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listServices( + request?: protos.google.cloud.billing.v1.IListServicesRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.IService[], + protos.google.cloud.billing.v1.IListServicesRequest|null, + protos.google.cloud.billing.v1.IListServicesResponse + ]>; + listServices( + request: protos.google.cloud.billing.v1.IListServicesRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListServicesRequest, + protos.google.cloud.billing.v1.IListServicesResponse|null|undefined, + protos.google.cloud.billing.v1.IService>): void; + listServices( + request: protos.google.cloud.billing.v1.IListServicesRequest, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListServicesRequest, + protos.google.cloud.billing.v1.IListServicesResponse|null|undefined, + protos.google.cloud.billing.v1.IService>): void; + listServices( + request?: protos.google.cloud.billing.v1.IListServicesRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.billing.v1.IListServicesRequest, + protos.google.cloud.billing.v1.IListServicesResponse|null|undefined, + protos.google.cloud.billing.v1.IService>, + callback?: PaginationCallback< + protos.google.cloud.billing.v1.IListServicesRequest, + protos.google.cloud.billing.v1.IListServicesResponse|null|undefined, + protos.google.cloud.billing.v1.IService>): + Promise<[ + protos.google.cloud.billing.v1.IService[], + protos.google.cloud.billing.v1.IListServicesRequest|null, + protos.google.cloud.billing.v1.IListServicesResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + this.initialize(); + return this.innerApiCalls.listServices(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListServices` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.billing.v1.Service|Service} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listServicesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listServicesStream( + request?: protos.google.cloud.billing.v1.IListServicesRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + const defaultCallSettings = this._defaults['listServices']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listServices.createStream( + this.innerApiCalls.listServices as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listServices`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListServices` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.billing.v1.Service|Service}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_catalog.list_services.js + * region_tag:cloudbilling_v1_generated_CloudCatalog_ListServices_async + */ + listServicesAsync( + request?: protos.google.cloud.billing.v1.IListServicesRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + const defaultCallSettings = this._defaults['listServices']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listServices.asyncIterate( + this.innerApiCalls['listServices'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + /** + * Lists all publicly available SKUs for a given cloud service. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the service. + * Example: "services/DA34-426B-A397" + * @param {google.protobuf.Timestamp} request.startTime + * Optional inclusive start time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {google.protobuf.Timestamp} request.endTime + * Optional exclusive end time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {string} request.currencyCode + * The ISO 4217 currency code for the pricing info in the response proto. + * Will use the conversion rate as of start_time. + * Optional. If not specified USD will be used. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListSkus` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of {@link protos.google.cloud.billing.v1.Sku|Sku}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listSkusAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listSkus( + request?: protos.google.cloud.billing.v1.IListSkusRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.billing.v1.ISku[], + protos.google.cloud.billing.v1.IListSkusRequest|null, + protos.google.cloud.billing.v1.IListSkusResponse + ]>; + listSkus( + request: protos.google.cloud.billing.v1.IListSkusRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListSkusRequest, + protos.google.cloud.billing.v1.IListSkusResponse|null|undefined, + protos.google.cloud.billing.v1.ISku>): void; + listSkus( + request: protos.google.cloud.billing.v1.IListSkusRequest, + callback: PaginationCallback< + protos.google.cloud.billing.v1.IListSkusRequest, + protos.google.cloud.billing.v1.IListSkusResponse|null|undefined, + protos.google.cloud.billing.v1.ISku>): void; + listSkus( + request?: protos.google.cloud.billing.v1.IListSkusRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.billing.v1.IListSkusRequest, + protos.google.cloud.billing.v1.IListSkusResponse|null|undefined, + protos.google.cloud.billing.v1.ISku>, + callback?: PaginationCallback< + protos.google.cloud.billing.v1.IListSkusRequest, + protos.google.cloud.billing.v1.IListSkusResponse|null|undefined, + protos.google.cloud.billing.v1.ISku>): + Promise<[ + protos.google.cloud.billing.v1.ISku[], + protos.google.cloud.billing.v1.IListSkusRequest|null, + protos.google.cloud.billing.v1.IListSkusResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + this.initialize(); + return this.innerApiCalls.listSkus(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the service. + * Example: "services/DA34-426B-A397" + * @param {google.protobuf.Timestamp} request.startTime + * Optional inclusive start time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {google.protobuf.Timestamp} request.endTime + * Optional exclusive end time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {string} request.currencyCode + * The ISO 4217 currency code for the pricing info in the response proto. + * Will use the conversion rate as of start_time. + * Optional. If not specified USD will be used. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListSkus` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing {@link protos.google.cloud.billing.v1.Sku|Sku} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listSkusAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + */ + listSkusStream( + request?: protos.google.cloud.billing.v1.IListSkusRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + const defaultCallSettings = this._defaults['listSkus']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSkus.createStream( + this.innerApiCalls.listSkus as GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listSkus`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the service. + * Example: "services/DA34-426B-A397" + * @param {google.protobuf.Timestamp} request.startTime + * Optional inclusive start time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {google.protobuf.Timestamp} request.endTime + * Optional exclusive end time of the time range for which the pricing + * versions will be returned. Timestamps in the future are not allowed. + * The time range has to be within a single calendar month in + * America/Los_Angeles timezone. Time range as a whole is optional. If not + * specified, the latest pricing will be returned (up to 12 hours old at + * most). + * @param {string} request.currencyCode + * The ISO 4217 currency code for the pricing info in the response proto. + * Will use the conversion rate as of start_time. + * Optional. If not specified USD will be used. + * @param {number} request.pageSize + * Requested page size. Defaults to 5000. + * @param {string} request.pageToken + * A token identifying a page of results to return. This should be a + * `next_page_token` value returned from a previous `ListSkus` + * call. If unspecified, the first page of results is returned. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | async iteration }. + * When you iterate the returned iterable, each element will be an object representing + * {@link protos.google.cloud.billing.v1.Sku|Sku}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination | documentation } + * for more details and examples. + * @example include:samples/generated/v1/cloud_catalog.list_skus.js + * region_tag:cloudbilling_v1_generated_CloudCatalog_ListSkus_async + */ + listSkusAsync( + request?: protos.google.cloud.billing.v1.IListSkusRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = this._gaxModule.routingHeader.fromParams({ + 'parent': request.parent ?? '', + }); + const defaultCallSettings = this._defaults['listSkus']; + const callSettings = defaultCallSettings.merge(options); + this.initialize(); + return this.descriptors.page.listSkus.asyncIterate( + this.innerApiCalls['listSkus'] as GaxCall, + request as {}, + callSettings + ) as AsyncIterable; + } + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified service resource name string. + * + * @param {string} service + * @returns {string} Resource name string. + */ + servicePath(service:string) { + return this.pathTemplates.servicePathTemplate.render({ + service: service, + }); + } + + /** + * Parse the service from Service resource. + * + * @param {string} serviceName + * A fully-qualified path representing Service resource. + * @returns {string} A string representing the service. + */ + matchServiceFromServiceName(serviceName: string) { + return this.pathTemplates.servicePathTemplate.match(serviceName).service; + } + + /** + * Return a fully-qualified sku resource name string. + * + * @param {string} service + * @param {string} sku + * @returns {string} Resource name string. + */ + skuPath(service:string,sku:string) { + return this.pathTemplates.skuPathTemplate.render({ + service: service, + sku: sku, + }); + } + + /** + * Parse the service from Sku resource. + * + * @param {string} skuName + * A fully-qualified path representing Sku resource. + * @returns {string} A string representing the service. + */ + matchServiceFromSkuName(skuName: string) { + return this.pathTemplates.skuPathTemplate.match(skuName).service; + } + + /** + * Parse the sku from Sku resource. + * + * @param {string} skuName + * A fully-qualified path representing Sku resource. + * @returns {string} A string representing the sku. + */ + matchSkuFromSkuName(skuName: string) { + return this.pathTemplates.skuPathTemplate.match(skuName).sku; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + if (this.cloudCatalogStub && !this._terminated) { + return this.cloudCatalogStub.then(stub => { + this._terminated = true; + stub.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client_config.json b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client_config.json new file mode 100644 index 00000000000..65eb2dffc09 --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_client_config.json @@ -0,0 +1,36 @@ +{ + "interfaces": { + "google.cloud.billing.v1.CloudCatalog": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "ListServices": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, + "ListSkus": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + } + } + } + } +} diff --git a/packages/google-cloud-billing/esm/src/v1/cloud_catalog_proto_list.json b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_proto_list.json new file mode 100644 index 00000000000..e34eb066aa5 --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/cloud_catalog_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/cloud/billing/v1/cloud_billing.proto", + "../../protos/google/cloud/billing/v1/cloud_catalog.proto" +] diff --git a/packages/google-cloud-billing/esm/src/v1/index.ts b/packages/google-cloud-billing/esm/src/v1/index.ts new file mode 100644 index 00000000000..45a30400923 --- /dev/null +++ b/packages/google-cloud-billing/esm/src/v1/index.ts @@ -0,0 +1,20 @@ +// Copyright 2023 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 +// +// 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. ** + +export {CloudBillingClient} from './cloud_billing_client.js'; +export {CloudCatalogClient} from './cloud_catalog_client.js'; diff --git a/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.js b/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.js new file mode 100644 index 00000000000..32a20ec186e --- /dev/null +++ b/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.js @@ -0,0 +1,28 @@ +// Copyright 2023 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 +// +// 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. ** + + +/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ +const billing = require('billing'); + +function main() { + const cloudBillingClient = new billing.CloudBillingClient(); + const cloudCatalogClient = new billing.CloudCatalogClient(); +} + +main(); diff --git a/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.ts b/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.ts new file mode 100644 index 00000000000..38349b08232 --- /dev/null +++ b/packages/google-cloud-billing/esm/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,38 @@ +// Copyright 2023 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 +// +// 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. ** + +import {CloudBillingClient, CloudCatalogClient} from 'billing'; + +// check that the client class type name can be used +function doStuffWithCloudBillingClient(client: CloudBillingClient) { + client.close(); +} +function doStuffWithCloudCatalogClient(client: CloudCatalogClient) { + client.close(); +} + +function main() { + // check that the client instance can be created + const cloudBillingClient = new CloudBillingClient(); + doStuffWithCloudBillingClient(cloudBillingClient); + // check that the client instance can be created + const cloudCatalogClient = new CloudCatalogClient(); + doStuffWithCloudCatalogClient(cloudCatalogClient); +} + +main(); diff --git a/packages/google-cloud-billing/esm/system-test/install.ts b/packages/google-cloud-billing/esm/system-test/install.ts new file mode 100644 index 00000000000..c8f81b25a86 --- /dev/null +++ b/packages/google-cloud-billing/esm/system-test/install.ts @@ -0,0 +1,49 @@ +// Copyright 2023 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 +// +// 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. ** + +import {packNTest} from 'pack-n-play'; +import {readFileSync} from 'fs'; +import {describe, it} from 'mocha'; + +describe('📦 pack-n-play test', () => { + + it('TypeScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'TypeScript user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); + }); + + it('JavaScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'JavaScript user can use the library', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); + }); + +}); diff --git a/packages/google-cloud-billing/esm/test/gapic_cloud_billing_v1.ts b/packages/google-cloud-billing/esm/test/gapic_cloud_billing_v1.ts new file mode 100644 index 00000000000..ae1e5f8c39e --- /dev/null +++ b/packages/google-cloud-billing/esm/test/gapic_cloud_billing_v1.ts @@ -0,0 +1,1550 @@ +// Copyright 2023 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 +// +// 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. ** + +// @ts-ignore +import * as protos from '../../protos/protos'; +import assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as cloudbillingModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.CloudBillingClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = cloudbillingModule.v1.CloudBillingClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = cloudbillingModule.v1.CloudBillingClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = cloudbillingModule.v1.CloudBillingClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new cloudbillingModule.v1.CloudBillingClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.cloudBillingStub, undefined); + await client.initialize(); + assert(client.cloudBillingStub); + }); + + it('has close method for the initialized client', done => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.cloudBillingStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.cloudBillingStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error|null, projectId?: string|null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + }); + + describe('getBillingAccount', () => { + it('invokes getBillingAccount without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.getBillingAccount = stubSimpleCall(expectedResponse); + const [response] = await client.getBillingAccount(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getBillingAccount without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.getBillingAccount = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getBillingAccount( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IBillingAccount|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getBillingAccount with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getBillingAccount = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getBillingAccount(request), expectedError); + const actualRequest = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getBillingAccount with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getBillingAccount(request), expectedError); + }); + }); + + describe('updateBillingAccount', () => { + it('invokes updateBillingAccount without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.updateBillingAccount = stubSimpleCall(expectedResponse); + const [response] = await client.updateBillingAccount(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateBillingAccount without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.updateBillingAccount = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateBillingAccount( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IBillingAccount|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateBillingAccount with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateBillingAccount = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updateBillingAccount(request), expectedError); + const actualRequest = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateBillingAccount as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateBillingAccount with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateBillingAccountRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.updateBillingAccount(request), expectedError); + }); + }); + + describe('createBillingAccount', () => { + it('invokes createBillingAccount without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.CreateBillingAccountRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.createBillingAccount = stubSimpleCall(expectedResponse); + const [response] = await client.createBillingAccount(request); + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes createBillingAccount without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.CreateBillingAccountRequest() + ); + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.BillingAccount() + ); + client.innerApiCalls.createBillingAccount = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createBillingAccount( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IBillingAccount|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes createBillingAccount with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.CreateBillingAccountRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.createBillingAccount = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createBillingAccount(request), expectedError); + }); + + it('invokes createBillingAccount with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.CreateBillingAccountRequest() + ); + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.createBillingAccount(request), expectedError); + }); + }); + + describe('getProjectBillingInfo', () => { + it('invokes getProjectBillingInfo without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.ProjectBillingInfo() + ); + client.innerApiCalls.getProjectBillingInfo = stubSimpleCall(expectedResponse); + const [response] = await client.getProjectBillingInfo(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getProjectBillingInfo without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.ProjectBillingInfo() + ); + client.innerApiCalls.getProjectBillingInfo = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getProjectBillingInfo( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IProjectBillingInfo|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getProjectBillingInfo with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getProjectBillingInfo = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getProjectBillingInfo(request), expectedError); + const actualRequest = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getProjectBillingInfo with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.GetProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getProjectBillingInfo(request), expectedError); + }); + }); + + describe('updateProjectBillingInfo', () => { + it('invokes updateProjectBillingInfo without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.ProjectBillingInfo() + ); + client.innerApiCalls.updateProjectBillingInfo = stubSimpleCall(expectedResponse); + const [response] = await client.updateProjectBillingInfo(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateProjectBillingInfo without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.billing.v1.ProjectBillingInfo() + ); + client.innerApiCalls.updateProjectBillingInfo = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updateProjectBillingInfo( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IProjectBillingInfo|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateProjectBillingInfo with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.updateProjectBillingInfo = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updateProjectBillingInfo(request), expectedError); + const actualRequest = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.updateProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes updateProjectBillingInfo with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.updateProjectBillingInfo(request), expectedError); + }); + }); + + describe('getIamPolicy', () => { + it('invokes getIamPolicy without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.getIamPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.getIamPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getIamPolicy( + request, + (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.getIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getIamPolicy(request), expectedError); + const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes getIamPolicy with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.GetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.getIamPolicy(request), expectedError); + }); + }); + + describe('setIamPolicy', () => { + it('invokes setIamPolicy without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.SetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.setIamPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes setIamPolicy without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.SetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.Policy() + ); + client.innerApiCalls.setIamPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.setIamPolicy( + request, + (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes setIamPolicy with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.SetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.setIamPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.setIamPolicy(request), expectedError); + const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes setIamPolicy with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.SetIamPolicyRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); + request.resource = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.setIamPolicy(request), expectedError); + }); + }); + + describe('testIamPermissions', () => { + it('invokes testIamPermissions without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsResponse() + ); + client.innerApiCalls.testIamPermissions = stubSimpleCall(expectedResponse); + const [response] = await client.testIamPermissions(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes testIamPermissions without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsResponse() + ); + client.innerApiCalls.testIamPermissions = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.testIamPermissions( + request, + (err?: Error|null, result?: protos.google.iam.v1.ITestIamPermissionsResponse|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes testIamPermissions with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); + request.resource = defaultValue1; + const expectedHeaderRequestParams = `resource=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.testIamPermissions = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.testIamPermissions(request), expectedError); + const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes testIamPermissions with closed client', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.iam.v1.TestIamPermissionsRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); + request.resource = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.testIamPermissions(request), expectedError); + }); + }); + + describe('listBillingAccounts', () => { + it('invokes listBillingAccounts without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + );const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + ]; + client.innerApiCalls.listBillingAccounts = stubSimpleCall(expectedResponse); + const [response] = await client.listBillingAccounts(request); + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes listBillingAccounts without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + );const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + ]; + client.innerApiCalls.listBillingAccounts = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listBillingAccounts( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IBillingAccount[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes listBillingAccounts with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.listBillingAccounts = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listBillingAccounts(request), expectedError); + }); + + it('invokes listBillingAccountsStream without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + ); + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + ]; + client.descriptors.page.listBillingAccounts.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listBillingAccountsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.BillingAccount[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.BillingAccount) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listBillingAccounts.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listBillingAccounts, request)); + }); + + it('invokes listBillingAccountsStream with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + ); + const expectedError = new Error('expected'); + client.descriptors.page.listBillingAccounts.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listBillingAccountsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.BillingAccount[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.BillingAccount) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listBillingAccounts.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listBillingAccounts, request)); + }); + + it('uses async iteration with listBillingAccounts without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + ); + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + generateSampleMessage(new protos.google.cloud.billing.v1.BillingAccount()), + ]; + client.descriptors.page.listBillingAccounts.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.billing.v1.IBillingAccount[] = []; + const iterable = client.listBillingAccountsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listBillingAccounts.asyncIterate as SinonStub) + .getCall(0).args[1], request); + }); + + it('uses async iteration with listBillingAccounts with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListBillingAccountsRequest() + ); + const expectedError = new Error('expected'); + client.descriptors.page.listBillingAccounts.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listBillingAccountsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.billing.v1.IBillingAccount[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listBillingAccounts.asyncIterate as SinonStub) + .getCall(0).args[1], request); + }); + }); + + describe('listProjectBillingInfo', () => { + it('invokes listProjectBillingInfo without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + ]; + client.innerApiCalls.listProjectBillingInfo = stubSimpleCall(expectedResponse); + const [response] = await client.listProjectBillingInfo(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listProjectBillingInfo without error using callback', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + ]; + client.innerApiCalls.listProjectBillingInfo = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listProjectBillingInfo( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IProjectBillingInfo[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listProjectBillingInfo with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listProjectBillingInfo = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listProjectBillingInfo(request), expectedError); + const actualRequest = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listProjectBillingInfo as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listProjectBillingInfoStream without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + ]; + client.descriptors.page.listProjectBillingInfo.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listProjectBillingInfoStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.ProjectBillingInfo[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.ProjectBillingInfo) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listProjectBillingInfo.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listProjectBillingInfo, request)); + assert( + (client.descriptors.page.listProjectBillingInfo.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listProjectBillingInfoStream with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listProjectBillingInfo.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listProjectBillingInfoStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.ProjectBillingInfo[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.ProjectBillingInfo) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listProjectBillingInfo.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listProjectBillingInfo, request)); + assert( + (client.descriptors.page.listProjectBillingInfo.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listProjectBillingInfo without error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + generateSampleMessage(new protos.google.cloud.billing.v1.ProjectBillingInfo()), + ]; + client.descriptors.page.listProjectBillingInfo.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.billing.v1.IProjectBillingInfo[] = []; + const iterable = client.listProjectBillingInfoAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listProjectBillingInfo.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listProjectBillingInfo.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listProjectBillingInfo with error', async () => { + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListProjectBillingInfoRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listProjectBillingInfo.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listProjectBillingInfoAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.billing.v1.IProjectBillingInfo[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listProjectBillingInfo.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listProjectBillingInfo.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('Path templates', () => { + + describe('billingAccount', () => { + const fakePath = "/rendered/path/billingAccount"; + const expectedParameters = { + billing_account: "billingAccountValue", + }; + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.billingAccountPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.billingAccountPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('billingAccountPath', () => { + const result = client.billingAccountPath("billingAccountValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.billingAccountPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchBillingAccountFromBillingAccountName', () => { + const result = client.matchBillingAccountFromBillingAccountName(fakePath); + assert.strictEqual(result, "billingAccountValue"); + assert((client.pathTemplates.billingAccountPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('service', () => { + const fakePath = "/rendered/path/service"; + const expectedParameters = { + service: "serviceValue", + }; + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.servicePathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.servicePathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('servicePath', () => { + const result = client.servicePath("serviceValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.servicePathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchServiceFromServiceName', () => { + const result = client.matchServiceFromServiceName(fakePath); + assert.strictEqual(result, "serviceValue"); + assert((client.pathTemplates.servicePathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('sku', () => { + const fakePath = "/rendered/path/sku"; + const expectedParameters = { + service: "serviceValue", + sku: "skuValue", + }; + const client = new cloudbillingModule.v1.CloudBillingClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.skuPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.skuPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('skuPath', () => { + const result = client.skuPath("serviceValue", "skuValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.skuPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchServiceFromSkuName', () => { + const result = client.matchServiceFromSkuName(fakePath); + assert.strictEqual(result, "serviceValue"); + assert((client.pathTemplates.skuPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSkuFromSkuName', () => { + const result = client.matchSkuFromSkuName(fakePath); + assert.strictEqual(result, "skuValue"); + assert((client.pathTemplates.skuPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/packages/google-cloud-billing/esm/test/gapic_cloud_catalog_v1.ts b/packages/google-cloud-billing/esm/test/gapic_cloud_catalog_v1.ts new file mode 100644 index 00000000000..4afe249c72c --- /dev/null +++ b/packages/google-cloud-billing/esm/test/gapic_cloud_catalog_v1.ts @@ -0,0 +1,689 @@ +// Copyright 2023 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 +// +// 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. ** + +// @ts-ignore +import * as protos from '../../protos/protos'; +import assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as cloudcatalogModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf} from 'google-gax'; + +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.CloudCatalogClient', () => { + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = cloudcatalogModule.v1.CloudCatalogClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = cloudcatalogModule.v1.CloudCatalogClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = cloudcatalogModule.v1.CloudCatalogClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.cloudCatalogStub, undefined); + await client.initialize(); + assert(client.cloudCatalogStub); + }); + + it('has close method for the initialized client', done => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.cloudCatalogStub); + client.close().then(() => { + done(); + }); + }); + + it('has close method for the non-initialized client', done => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.cloudCatalogStub, undefined); + client.close().then(() => { + done(); + }); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error|null, projectId?: string|null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + }); + + describe('listServices', () => { + it('invokes listServices without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + );const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + ]; + client.innerApiCalls.listServices = stubSimpleCall(expectedResponse); + const [response] = await client.listServices(request); + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes listServices without error using callback', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + );const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + ]; + client.innerApiCalls.listServices = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listServices( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.IService[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + }); + + it('invokes listServices with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + ); + const expectedError = new Error('expected'); + client.innerApiCalls.listServices = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listServices(request), expectedError); + }); + + it('invokes listServicesStream without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + ); + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + ]; + client.descriptors.page.listServices.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listServicesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.Service[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.Service) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listServices.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listServices, request)); + }); + + it('invokes listServicesStream with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + ); + const expectedError = new Error('expected'); + client.descriptors.page.listServices.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listServicesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.Service[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.Service) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listServices.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listServices, request)); + }); + + it('uses async iteration with listServices without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + ); + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + generateSampleMessage(new protos.google.cloud.billing.v1.Service()), + ]; + client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.billing.v1.IService[] = []; + const iterable = client.listServicesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listServices.asyncIterate as SinonStub) + .getCall(0).args[1], request); + }); + + it('uses async iteration with listServices with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListServicesRequest() + ); + const expectedError = new Error('expected'); + client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listServicesAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.billing.v1.IService[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listServices.asyncIterate as SinonStub) + .getCall(0).args[1], request); + }); + }); + + describe('listSkus', () => { + it('invokes listSkus without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + ]; + client.innerApiCalls.listSkus = stubSimpleCall(expectedResponse); + const [response] = await client.listSkus(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSkus without error using callback', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`;const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + ]; + client.innerApiCalls.listSkus = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listSkus( + request, + (err?: Error|null, result?: protos.google.cloud.billing.v1.ISku[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSkus with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.listSkus = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listSkus(request), expectedError); + const actualRequest = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = (client.innerApiCalls.listSkus as SinonStub) + .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes listSkusStream without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + ]; + client.descriptors.page.listSkus.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listSkusStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.Sku[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.Sku) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listSkus.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSkus, request)); + assert( + (client.descriptors.page.listSkus.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('invokes listSkusStream with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSkus.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listSkusStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.billing.v1.Sku[] = []; + stream.on('data', (response: protos.google.cloud.billing.v1.Sku) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listSkus.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listSkus, request)); + assert( + (client.descriptors.page.listSkus.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSkus without error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), + ]; + client.descriptors.page.listSkus.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.billing.v1.ISku[] = []; + const iterable = client.listSkusAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listSkus.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSkus.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + + it('uses async iteration with listSkus with error', async () => { + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.billing.v1.ListSkusRequest() + ); + const defaultValue1 = + getTypeDefaultValue('.google.cloud.billing.v1.ListSkusRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; + const expectedError = new Error('expected'); + client.descriptors.page.listSkus.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listSkusAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.billing.v1.ISku[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listSkus.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert( + (client.descriptors.page.listSkus.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) + ); + }); + }); + + describe('Path templates', () => { + + describe('service', () => { + const fakePath = "/rendered/path/service"; + const expectedParameters = { + service: "serviceValue", + }; + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.servicePathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.servicePathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('servicePath', () => { + const result = client.servicePath("serviceValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.servicePathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchServiceFromServiceName', () => { + const result = client.matchServiceFromServiceName(fakePath); + assert.strictEqual(result, "serviceValue"); + assert((client.pathTemplates.servicePathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('sku', () => { + const fakePath = "/rendered/path/sku"; + const expectedParameters = { + service: "serviceValue", + sku: "skuValue", + }; + const client = new cloudcatalogModule.v1.CloudCatalogClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.skuPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.skuPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('skuPath', () => { + const result = client.skuPath("serviceValue", "skuValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.skuPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchServiceFromSkuName', () => { + const result = client.matchServiceFromSkuName(fakePath); + assert.strictEqual(result, "serviceValue"); + assert((client.pathTemplates.skuPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchSkuFromSkuName', () => { + const result = client.matchSkuFromSkuName(fakePath); + assert.strictEqual(result, "skuValue"); + assert((client.pathTemplates.skuPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/packages/google-cloud-billing/package.json b/packages/google-cloud-billing/package.json index 7bbc9ae5557..cafd71cbe76 100644 --- a/packages/google-cloud-billing/package.json +++ b/packages/google-cloud-billing/package.json @@ -1,61 +1,86 @@ { - "name": "@google-cloud/billing", - "version": "3.3.2", + "name": "billing", + "version": "0.1.0", "description": "Billing client for Node.js", - "repository": { - "type": "git", - "directory": "packages/google-cloud-billing", - "url": "https://github.com/googleapis/google-cloud-node.git" - }, + "repository": "googleapis/nodejs-billing", "license": "Apache-2.0", "author": "Google LLC", + "main": "./build/cjs/src/index.cjs", + "types": "./build/cjs/src/index.d.ts", + "type": "module", + "exports": { + ".": { + "import": { + "types": "./build/cjs/src/index.d.ts", + "default": "./build/esm/src/index.js" + }, + "require": { + "types": "./build/cjs/src/index.d.ts", + "default": "./build/cjs/src/index.cjs" + } + } + }, "files": [ - "build/src", + "build/esm", + "build/cjs", "build/protos", - "!build/src/**/*.map" + "!build/esm/**/*.map", + "!build/cjs/**/*.map" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google billing", + "billing", + "cloud billing", + "cloud catalog" ], - "main": "build/src/index.js", "scripts": { "clean": "gts clean", - "compile": "tsc -p . && cp -r protos build/", "compile-protos": "compileProtos src", "docs": "jsdoc -c .jsdoc.js", + "postpack": "minifyProtoJson build/cjs && minifyProtoJson build/esm", "predocs-test": "npm run docs", "docs-test": "linkinator docs", "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "prelint": "cd samples; npm link ../; npm i", - "postpack": "minifyProtoJson", - "samples-test": "cd samples/ && npm link ../ && npm i && npm test", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "system-test": "c8 mocha build/cjs/system-test", + "test:cjs": "c8 mocha build/cjs/test", + "test:esm": "c8 mocha --loader=esmock build/esm/test", + "test": "npm run test:cjs && npm run test:esm", + "compile:esm": "tsc -p ./tsconfig.esm.json", + "compile:cjs": "tsc -p ./tsconfig.json", + "compile": "npm run compile:esm && npm run compile:cjs && cp -r protos" }, "dependencies": { - "google-gax": "^3.5.8" + "google-gax": "^3.6.0" }, "devDependencies": { - "@types/mocha": "^9.0.0", - "@types/node": "^18.0.0", - "@types/sinon": "^10.0.0", - "c8": "^7.0.0", - "gts": "^3.1.0", - "jsdoc": "^4.0.0", - "jsdoc-fresh": "^2.0.0", - "jsdoc-region-tag": "^2.0.0", - "linkinator": "4.1.2", - "long": "^5.2.3", - "mocha": "^9.2.2", - "null-loader": "^4.0.0", + "@types/mocha": "^10.0.1", + "@types/node": "^18.11.18", + "@types/sinon": "^10.0.15", + "c8": "^7.14.0", + "gts": "^3.1.1", + "jsdoc": "^4.0.2", + "jsdoc-fresh": "^2.0.2", + "jsdoc-region-tag": "^2.0.1", + "mocha": "^10.2.0", + "null-loader": "^4.0.1", "pack-n-play": "^1.0.0-2", - "sinon": "^15.0.0", - "ts-loader": "^9.0.0", - "typescript": "^4.6.4", - "webpack": "^5.0.0", - "webpack-cli": "^5.0.0" + "sinon": "^15.1.0", + "ts-loader": "^8.4.0", + "typescript": "^4.9.5", + "webpack": "^4.46.0", + "webpack-cli": "^4.10.0" }, "engines": { - "node": ">=12.0.0" - }, - "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/google-cloud-billing" + "node": ">=14.0.0" + } } diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js index 0f0b859ecab..346c587a713 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.create_billing_account.js @@ -37,7 +37,7 @@ function main(billingAccount) { // const billingAccount = {} // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js index f4b7caa1aee..fb3954d760a 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_billing_account.js @@ -35,7 +35,7 @@ function main(name) { // const name = 'abc123' // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js index f469ae8a9ed..26bbb58b98c 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_iam_policy.js @@ -40,7 +40,7 @@ function main(resource) { // const options = {} // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js index 251ca2b34ff..648db98129d 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.get_project_billing_info.js @@ -35,7 +35,7 @@ function main(name) { // const name = 'abc123' // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js index acea3f19a26..cdfa0d7dead 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_billing_accounts.js @@ -50,7 +50,7 @@ function main() { // const filter = 'abc123' // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js index 8fe2bd4bed4..790d2c4cdfe 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.list_project_billing_info.js @@ -47,7 +47,7 @@ function main(name) { // const pageToken = 'abc123' // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js index df5114628b9..d240eb5889a 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.set_iam_policy.js @@ -49,7 +49,7 @@ function main(resource, policy) { // const updateMask = {} // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js index 49f18706d4f..7b37e85928f 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.test_iam_permissions.js @@ -39,10 +39,10 @@ function main(resource, permissions) { * information see * IAM Overview (https://cloud.google.com/iam/docs/overview#permissions). */ - // const permissions = 'abc123' + // const permissions = ['abc','def'] // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js index 5235304c131..24cf71e8a14 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_billing_account.js @@ -44,7 +44,7 @@ function main(name, account) { // const updateMask = {} // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js index ecf923aa2a4..0c5af3d6662 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_billing.update_project_billing_info.js @@ -41,7 +41,7 @@ function main(name) { // const projectBillingInfo = {} // Imports the Billing library - const {CloudBillingClient} = require('@google-cloud/billing').v1; + const {CloudBillingClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudBillingClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js b/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js index a06bee8c811..c88d5332f89 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_services.js @@ -40,7 +40,7 @@ function main() { // const pageToken = 'abc123' // Imports the Billing library - const {CloudCatalogClient} = require('@google-cloud/billing').v1; + const {CloudCatalogClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudCatalogClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js b/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js index 7e9f491fc7b..a4a9e175a2c 100644 --- a/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js +++ b/packages/google-cloud-billing/samples/generated/v1/cloud_catalog.list_skus.js @@ -69,7 +69,7 @@ function main(parent) { // const pageToken = 'abc123' // Imports the Billing library - const {CloudCatalogClient} = require('@google-cloud/billing').v1; + const {CloudCatalogClient} = require('billing').v1; // Instantiates a client const billingClient = new CloudCatalogClient(); diff --git a/packages/google-cloud-billing/samples/generated/v1/snippet_metadata_google.cloud.billing.v1.json b/packages/google-cloud-billing/samples/generated/v1/snippet_metadata_google.cloud.billing.v1.json new file mode 100644 index 00000000000..0744c589f24 --- /dev/null +++ b/packages/google-cloud-billing/samples/generated/v1/snippet_metadata_google.cloud.billing.v1.json @@ -0,0 +1,563 @@ +{ + "clientLibrary": { + "name": "nodejs-billing", + "version": "0.1.0", + "language": "TYPESCRIPT", + "apis": [ + { + "id": "google.cloud.billing.v1", + "version": "v1" + } + ] + }, + "snippets": [ + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_GetBillingAccount_async", + "title": "CloudBilling getBillingAccount Sample", + "origin": "API_DEFINITION", + "description": " Gets information about a billing account. The current authenticated user must be a [viewer of the billing account](https://cloud.google.com/billing/docs/how-to/billing-access).", + "canonical": true, + "file": "cloud_billing.get_billing_account.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 54, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "GetBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.GetBillingAccount", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.BillingAccount", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "GetBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.GetBillingAccount", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_ListBillingAccounts_async", + "title": "CloudBilling listBillingAccounts Sample", + "origin": "API_DEFINITION", + "description": " Lists the billing accounts that the current authenticated user has permission to [view](https://cloud.google.com/billing/docs/how-to/billing-access).", + "canonical": true, + "file": "cloud_billing.list_billing_accounts.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 70, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListBillingAccounts", + "fullName": "google.cloud.billing.v1.CloudBilling.ListBillingAccounts", + "async": true, + "parameters": [ + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + }, + { + "name": "filter", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.ListBillingAccountsResponse", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "ListBillingAccounts", + "fullName": "google.cloud.billing.v1.CloudBilling.ListBillingAccounts", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_UpdateBillingAccount_async", + "title": "CloudBilling updateBillingAccount Sample", + "origin": "API_DEFINITION", + "description": " Updates a billing account's fields. Currently the only field that can be edited is `display_name`. The current authenticated user must have the `billing.accounts.update` IAM permission, which is typically given to the [administrator](https://cloud.google.com/billing/docs/how-to/billing-access) of the billing account.", + "canonical": true, + "file": "cloud_billing.update_billing_account.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 64, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "UpdateBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.UpdateBillingAccount", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "account", + "type": ".google.cloud.billing.v1.BillingAccount" + }, + { + "name": "update_mask", + "type": ".google.protobuf.FieldMask" + } + ], + "resultType": ".google.cloud.billing.v1.BillingAccount", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "UpdateBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.UpdateBillingAccount", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_CreateBillingAccount_async", + "title": "CloudBilling createBillingAccount Sample", + "origin": "API_DEFINITION", + "description": " This method creates [billing subaccounts](https://cloud.google.com/billing/docs/concepts#subaccounts). Google Cloud resellers should use the Channel Services APIs, [accounts.customers.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers/create) and [accounts.customers.entitlements.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers.entitlements/create). When creating a subaccount, the current authenticated user must have the `billing.accounts.update` IAM permission on the parent account, which is typically given to billing account [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). This method will return an error if the parent account has not been provisioned as a reseller account.", + "canonical": true, + "file": "cloud_billing.create_billing_account.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 56, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "CreateBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.CreateBillingAccount", + "async": true, + "parameters": [ + { + "name": "billing_account", + "type": ".google.cloud.billing.v1.BillingAccount" + } + ], + "resultType": ".google.cloud.billing.v1.BillingAccount", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "CreateBillingAccount", + "fullName": "google.cloud.billing.v1.CloudBilling.CreateBillingAccount", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_ListProjectBillingInfo_async", + "title": "CloudBilling listProjectBillingInfo Sample", + "origin": "API_DEFINITION", + "description": " Lists the projects associated with a billing account. The current authenticated user must have the `billing.resourceAssociations.list` IAM permission, which is often given to billing account [viewers](https://cloud.google.com/billing/docs/how-to/billing-access).", + "canonical": true, + "file": "cloud_billing.list_project_billing_info.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 68, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.ListProjectBillingInfo", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.ListProjectBillingInfoResponse", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "ListProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.ListProjectBillingInfo", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_GetProjectBillingInfo_async", + "title": "CloudBilling getProjectBillingInfo Sample", + "origin": "API_DEFINITION", + "description": " Gets the billing information for a project. The current authenticated user must have the `resourcemanager.projects.get` permission for the project, which can be granted by assigning the [Project Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles) role.", + "canonical": true, + "file": "cloud_billing.get_project_billing_info.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 54, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "GetProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.GetProjectBillingInfo", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.ProjectBillingInfo", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "GetProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.GetProjectBillingInfo", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_UpdateProjectBillingInfo_async", + "title": "CloudBilling updateProjectBillingInfo Sample", + "origin": "API_DEFINITION", + "description": " Sets or updates the billing account associated with a project. You specify the new billing account by setting the `billing_account_name` in the `ProjectBillingInfo` resource to the resource name of a billing account. Associating a project with an open billing account enables billing on the project and allows charges for resource usage. If the project already had a billing account, this method changes the billing account used for resource usage charges. *Note:* Incurred charges that have not yet been reported in the transaction history of the Google Cloud Console might be billed to the new billing account, even if the charge occurred before the new billing account was assigned to the project. The current authenticated user must have ownership privileges for both the [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo ) and the [billing account](https://cloud.google.com/billing/docs/how-to/billing-access). You can disable billing on the project by setting the `billing_account_name` field to empty. This action disassociates the current billing account from the project. Any billable activity of your in-use services will stop, and your application could stop functioning as expected. Any unbilled charges to date will be billed to the previously associated account. The current authenticated user must be either an owner of the project or an owner of the billing account for the project. Note that associating a project with a *closed* billing account will have much the same effect as disabling billing on the project: any paid resources used by the project will be shut down. Thus, unless you wish to disable billing, you should always call this method with the name of an *open* billing account.", + "canonical": true, + "file": "cloud_billing.update_project_billing_info.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 60, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "UpdateProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.UpdateProjectBillingInfo", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + }, + { + "name": "project_billing_info", + "type": ".google.cloud.billing.v1.ProjectBillingInfo" + } + ], + "resultType": ".google.cloud.billing.v1.ProjectBillingInfo", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "UpdateProjectBillingInfo", + "fullName": "google.cloud.billing.v1.CloudBilling.UpdateProjectBillingInfo", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_GetIamPolicy_async", + "title": "CloudBilling getIamPolicy Sample", + "origin": "API_DEFINITION", + "description": " Gets the access control policy for a billing account. The caller must have the `billing.accounts.getIamPolicy` permission on the account, which is often given to billing account [viewers](https://cloud.google.com/billing/docs/how-to/billing-access).", + "canonical": true, + "file": "cloud_billing.get_iam_policy.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 59, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "GetIamPolicy", + "fullName": "google.cloud.billing.v1.CloudBilling.GetIamPolicy", + "async": true, + "parameters": [ + { + "name": "resource", + "type": "TYPE_STRING" + }, + { + "name": "options", + "type": ".google.iam.v1.GetPolicyOptions" + } + ], + "resultType": ".google.iam.v1.Policy", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "GetIamPolicy", + "fullName": "google.cloud.billing.v1.CloudBilling.GetIamPolicy", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_SetIamPolicy_async", + "title": "CloudBilling setIamPolicy Sample", + "origin": "API_DEFINITION", + "description": " Sets the access control policy for a billing account. Replaces any existing policy. The caller must have the `billing.accounts.setIamPolicy` permission on the account, which is often given to billing account [administrators](https://cloud.google.com/billing/docs/how-to/billing-access).", + "canonical": true, + "file": "cloud_billing.set_iam_policy.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 69, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "SetIamPolicy", + "fullName": "google.cloud.billing.v1.CloudBilling.SetIamPolicy", + "async": true, + "parameters": [ + { + "name": "resource", + "type": "TYPE_STRING" + }, + { + "name": "policy", + "type": ".google.iam.v1.Policy" + }, + { + "name": "update_mask", + "type": ".google.protobuf.FieldMask" + } + ], + "resultType": ".google.iam.v1.Policy", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "SetIamPolicy", + "fullName": "google.cloud.billing.v1.CloudBilling.SetIamPolicy", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudBilling_TestIamPermissions_async", + "title": "CloudBilling testIamPermissions Sample", + "origin": "API_DEFINITION", + "description": " Tests the access control policy for a billing account. This method takes the resource and a set of permissions as input and returns the subset of the input permissions that the caller is allowed for that resource.", + "canonical": true, + "file": "cloud_billing.test_iam_permissions.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 62, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "TestIamPermissions", + "fullName": "google.cloud.billing.v1.CloudBilling.TestIamPermissions", + "async": true, + "parameters": [ + { + "name": "resource", + "type": "TYPE_STRING" + }, + { + "name": "permissions", + "type": "TYPE_STRING[]" + } + ], + "resultType": ".google.iam.v1.TestIamPermissionsResponse", + "client": { + "shortName": "CloudBillingClient", + "fullName": "google.cloud.billing.v1.CloudBillingClient" + }, + "method": { + "shortName": "TestIamPermissions", + "fullName": "google.cloud.billing.v1.CloudBilling.TestIamPermissions", + "service": { + "shortName": "CloudBilling", + "fullName": "google.cloud.billing.v1.CloudBilling" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudCatalog_ListServices_async", + "title": "CloudBilling listServices Sample", + "origin": "API_DEFINITION", + "description": " Lists all public cloud services.", + "canonical": true, + "file": "cloud_catalog.list_services.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 60, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListServices", + "fullName": "google.cloud.billing.v1.CloudCatalog.ListServices", + "async": true, + "parameters": [ + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.ListServicesResponse", + "client": { + "shortName": "CloudCatalogClient", + "fullName": "google.cloud.billing.v1.CloudCatalogClient" + }, + "method": { + "shortName": "ListServices", + "fullName": "google.cloud.billing.v1.CloudCatalog.ListServices", + "service": { + "shortName": "CloudCatalog", + "fullName": "google.cloud.billing.v1.CloudCatalog" + } + } + } + }, + { + "regionTag": "cloudbilling_v1_generated_CloudCatalog_ListSkus_async", + "title": "CloudBilling listSkus Sample", + "origin": "API_DEFINITION", + "description": " Lists all publicly available SKUs for a given cloud service.", + "canonical": true, + "file": "cloud_catalog.list_skus.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 90, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ListSkus", + "fullName": "google.cloud.billing.v1.CloudCatalog.ListSkus", + "async": true, + "parameters": [ + { + "name": "parent", + "type": "TYPE_STRING" + }, + { + "name": "start_time", + "type": ".google.protobuf.Timestamp" + }, + { + "name": "end_time", + "type": ".google.protobuf.Timestamp" + }, + { + "name": "currency_code", + "type": "TYPE_STRING" + }, + { + "name": "page_size", + "type": "TYPE_INT32" + }, + { + "name": "page_token", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.billing.v1.ListSkusResponse", + "client": { + "shortName": "CloudCatalogClient", + "fullName": "google.cloud.billing.v1.CloudCatalogClient" + }, + "method": { + "shortName": "ListSkus", + "fullName": "google.cloud.billing.v1.CloudCatalog.ListSkus", + "service": { + "shortName": "CloudCatalog", + "fullName": "google.cloud.billing.v1.CloudCatalog" + } + } + } + } + ] +} diff --git a/packages/google-cloud-billing/tsconfig.esm.json b/packages/google-cloud-billing/tsconfig.esm.json new file mode 100644 index 00000000000..cc6023c7eb5 --- /dev/null +++ b/packages/google-cloud-billing/tsconfig.esm.json @@ -0,0 +1,23 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build", + "resolveJsonModule": true, + "module": "es2020", + "moduleResolution": "node", + "esModuleInterop": true, + "sourceMap": false, + "lib": [ + "es2020", + "DOM" + ] + }, + "include": [ + "esm/src/*.ts", + "esm/src/**/*.ts", + "esm/test/*.ts", + "esm/test/**/*.ts", + "esm/system-test/*.ts" + ] +} diff --git a/packages/google-cloud-billing/tsconfig.json b/packages/google-cloud-billing/tsconfig.json index c78f1c884ef..ddb5dba5e99 100644 --- a/packages/google-cloud-billing/tsconfig.json +++ b/packages/google-cloud-billing/tsconfig.json @@ -4,16 +4,20 @@ "rootDir": ".", "outDir": "build", "resolveJsonModule": true, + "moduleResolution": "node", + "esModuleInterop": true, + "sourceMap": false, + "module": "CommonJS", "lib": [ "es2018", "dom" ] }, "include": [ - "src/*.ts", - "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts" + "esm/src/*.ts", + "esm/src/**/*.ts", + "esm/test/*.ts", + "esm/test/**/*.ts", + "esm/system-test/*.ts" ] } diff --git a/packages/google-cloud-billing/webpack.config.cjs b/packages/google-cloud-billing/webpack.config.cjs new file mode 100644 index 00000000000..d2282430c03 --- /dev/null +++ b/packages/google-cloud-billing/webpack.config.cjs @@ -0,0 +1,64 @@ +// Copyright 2021 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 +// +// 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. + +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + library: 'CloudBilling', + filename: './cloud-billing.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + alias: { + '../../../package.json': path.resolve(__dirname, 'package.json'), + }, + extensions: ['.js', '.json', '.ts'], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /node_modules[\\/]@grpc[\\/]grpc-js/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]grpc/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]retry-request/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]https?-proxy-agent/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]gtoken/, + use: 'null-loader' + }, + ], + }, + mode: 'production', +}; From 6dc9253cda1931d9c9538364d8ddb0c592b9dc69 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 16 Jun 2023 23:50:40 +0000 Subject: [PATCH 2/2] delete src --- packages/google-cloud-billing/src/index.ts | 29 - .../src/v1/cloud_billing_client.ts | 1686 -------------- .../src/v1/cloud_billing_client_config.json | 76 - .../src/v1/cloud_billing_proto_list.json | 4 - .../src/v1/cloud_catalog_client.ts | 837 ------- .../src/v1/cloud_catalog_client_config.json | 36 - .../src/v1/cloud_catalog_proto_list.json | 4 - .../src/v1/gapic_metadata.json | 173 -- packages/google-cloud-billing/src/v1/index.ts | 20 - .../test/gapic_cloud_billing_v1.ts | 1950 ----------------- .../test/gapic_cloud_catalog_v1.ts | 819 ------- 11 files changed, 5634 deletions(-) delete mode 100644 packages/google-cloud-billing/src/index.ts delete mode 100644 packages/google-cloud-billing/src/v1/cloud_billing_client.ts delete mode 100644 packages/google-cloud-billing/src/v1/cloud_billing_client_config.json delete mode 100644 packages/google-cloud-billing/src/v1/cloud_billing_proto_list.json delete mode 100644 packages/google-cloud-billing/src/v1/cloud_catalog_client.ts delete mode 100644 packages/google-cloud-billing/src/v1/cloud_catalog_client_config.json delete mode 100644 packages/google-cloud-billing/src/v1/cloud_catalog_proto_list.json delete mode 100644 packages/google-cloud-billing/src/v1/gapic_metadata.json delete mode 100644 packages/google-cloud-billing/src/v1/index.ts delete mode 100644 packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts delete mode 100644 packages/google-cloud-billing/test/gapic_cloud_catalog_v1.ts diff --git a/packages/google-cloud-billing/src/index.ts b/packages/google-cloud-billing/src/index.ts deleted file mode 100644 index 3ea1da2ff89..00000000000 --- a/packages/google-cloud-billing/src/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2023 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 -// -// 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 synthtool. ** -// ** https://github.com/googleapis/synthtool ** -// ** All changes to this file may be overwritten. ** - -import * as v1 from './v1'; - -const CloudBillingClient = v1.CloudBillingClient; -type CloudBillingClient = v1.CloudBillingClient; -const CloudCatalogClient = v1.CloudCatalogClient; -type CloudCatalogClient = v1.CloudCatalogClient; - -export {v1, CloudBillingClient, CloudCatalogClient}; -export default {v1, CloudBillingClient, CloudCatalogClient}; -import * as protos from '../protos/protos'; -export {protos}; diff --git a/packages/google-cloud-billing/src/v1/cloud_billing_client.ts b/packages/google-cloud-billing/src/v1/cloud_billing_client.ts deleted file mode 100644 index a775297baeb..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_billing_client.ts +++ /dev/null @@ -1,1686 +0,0 @@ -// Copyright 2023 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 -// -// 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. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type { - Callback, - CallOptions, - Descriptors, - ClientOptions, - PaginationCallback, - GaxCall, -} from 'google-gax'; -import {Transform} from 'stream'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v1/cloud_billing_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './cloud_billing_client_config.json'; -const version = require('../../../package.json').version; - -/** - * Retrieves the Google Cloud Console billing accounts and associates them with - * projects. - * @class - * @memberof v1 - */ -export class CloudBillingClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - pathTemplates: {[name: string]: gax.PathTemplate}; - cloudBillingStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of CloudBillingClient. - * - * @param {object} [options] - The configuration object. - * The options accepted by the constructor are described in detail - * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. - * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. - * For more information, please check the - * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. - * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you - * need to avoid loading the default gRPC version and want to use the fallback - * HTTP implementation. Load only fallback version and pass it to the constructor: - * ``` - * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC - * const client = new CloudBillingClient({fallback: 'rest'}, gax); - * ``` - */ - constructor( - opts?: ClientOptions, - gaxInstance?: typeof gax | typeof gax.fallback - ) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof CloudBillingClient; - const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; - this._providedCustomServicePath = !!( - opts?.servicePath || opts?.apiEndpoint - ); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = - opts?.fallback ?? - (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Load google-gax module synchronously if needed - if (!gaxInstance) { - gaxInstance = require('google-gax') as typeof gax; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - - // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else if (opts.fallback === 'rest') { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - billingAccountPathTemplate: new this._gaxModule.PathTemplate( - 'billingAccounts/{billing_account}' - ), - servicePathTemplate: new this._gaxModule.PathTemplate( - 'services/{service}' - ), - skuPathTemplate: new this._gaxModule.PathTemplate( - 'services/{service}/skus/{sku}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listBillingAccounts: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'billingAccounts' - ), - listProjectBillingInfo: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'projectBillingInfo' - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.billing.v1.CloudBilling', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')} - ); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.cloudBillingStub) { - return this.cloudBillingStub; - } - - // Put together the "service stub" for - // google.cloud.billing.v1.CloudBilling. - this.cloudBillingStub = this._gaxGrpc.createStub( - this._opts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.cloud.billing.v1.CloudBilling' - ) - : // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.cloud.billing.v1.CloudBilling, - this._opts, - this._providedCustomServicePath - ) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const cloudBillingStubMethods = [ - 'getBillingAccount', - 'listBillingAccounts', - 'updateBillingAccount', - 'createBillingAccount', - 'listProjectBillingInfo', - 'getProjectBillingInfo', - 'updateProjectBillingInfo', - 'getIamPolicy', - 'setIamPolicy', - 'testIamPermissions', - ]; - for (const methodName of cloudBillingStubMethods) { - const callPromise = this.cloudBillingStub.then( - stub => - (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error | null | undefined) => () => { - throw err; - } - ); - - const descriptor = this.descriptors.page[methodName] || undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.cloudBillingStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'cloudbilling.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'cloudbilling.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-billing', - 'https://www.googleapis.com/auth/cloud-billing.readonly', - 'https://www.googleapis.com/auth/cloud-platform', - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId( - callback?: Callback - ): Promise | void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - /** - * Gets information about a billing account. The current authenticated user - * must be a [viewer of the billing - * account](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the billing account to retrieve. For - * example, `billingAccounts/012345-567890-ABCDEF`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.cloud.billing.v1.BillingAccount | BillingAccount}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.get_billing_account.js - * region_tag:cloudbilling_v1_generated_CloudBilling_GetBillingAccount_async - */ - getBillingAccount( - request?: protos.google.cloud.billing.v1.IGetBillingAccountRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.IGetBillingAccountRequest | undefined, - {} | undefined - ] - >; - getBillingAccount( - request: protos.google.cloud.billing.v1.IGetBillingAccountRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IGetBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - getBillingAccount( - request: protos.google.cloud.billing.v1.IGetBillingAccountRequest, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IGetBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - getBillingAccount( - request?: protos.google.cloud.billing.v1.IGetBillingAccountRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IGetBillingAccountRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IGetBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.IGetBillingAccountRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.getBillingAccount(request, options, callback); - } - /** - * Updates a billing account's fields. - * Currently the only field that can be edited is `display_name`. - * The current authenticated user must have the `billing.accounts.update` - * IAM permission, which is typically given to the - * [administrator](https://cloud.google.com/billing/docs/how-to/billing-access) - * of the billing account. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The name of the billing account resource to be updated. - * @param {google.cloud.billing.v1.BillingAccount} request.account - * Required. The billing account resource to replace the resource on the - * server. - * @param {google.protobuf.FieldMask} request.updateMask - * The update mask applied to the resource. - * Only "display_name" is currently supported. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.cloud.billing.v1.BillingAccount | BillingAccount}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.update_billing_account.js - * region_tag:cloudbilling_v1_generated_CloudBilling_UpdateBillingAccount_async - */ - updateBillingAccount( - request?: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.IUpdateBillingAccountRequest | undefined, - {} | undefined - ] - >; - updateBillingAccount( - request: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IUpdateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - updateBillingAccount( - request: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IUpdateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - updateBillingAccount( - request?: protos.google.cloud.billing.v1.IUpdateBillingAccountRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IUpdateBillingAccountRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.IUpdateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.IUpdateBillingAccountRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.updateBillingAccount(request, options, callback); - } - /** - * This method creates [billing - * subaccounts](https://cloud.google.com/billing/docs/concepts#subaccounts). - * - * Google Cloud resellers should use the - * Channel Services APIs, - * [accounts.customers.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers/create) - * and - * [accounts.customers.entitlements.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers.entitlements/create). - * - * When creating a subaccount, the current authenticated user must have the - * `billing.accounts.update` IAM permission on the parent account, which is - * typically given to billing account - * [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). - * This method will return an error if the parent account has not been - * provisioned as a reseller account. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.cloud.billing.v1.BillingAccount} request.billingAccount - * Required. The billing account resource to create. - * Currently CreateBillingAccount only supports subaccount creation, so - * any created billing accounts must be under a provided parent billing - * account. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.cloud.billing.v1.BillingAccount | BillingAccount}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.create_billing_account.js - * region_tag:cloudbilling_v1_generated_CloudBilling_CreateBillingAccount_async - */ - createBillingAccount( - request?: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.ICreateBillingAccountRequest | undefined, - {} | undefined - ] - >; - createBillingAccount( - request: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.ICreateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - createBillingAccount( - request: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, - callback: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.ICreateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): void; - createBillingAccount( - request?: protos.google.cloud.billing.v1.ICreateBillingAccountRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.ICreateBillingAccountRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.billing.v1.IBillingAccount, - | protos.google.cloud.billing.v1.ICreateBillingAccountRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount, - protos.google.cloud.billing.v1.ICreateBillingAccountRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - this.initialize(); - return this.innerApiCalls.createBillingAccount(request, options, callback); - } - /** - * Gets the billing information for a project. The current authenticated user - * must have the `resourcemanager.projects.get` permission for the project, - * which can be granted by assigning the [Project - * Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles) - * role. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the project for which billing information is - * retrieved. For example, `projects/tokyo-rain-123`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.cloud.billing.v1.ProjectBillingInfo | ProjectBillingInfo}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.get_project_billing_info.js - * region_tag:cloudbilling_v1_generated_CloudBilling_GetProjectBillingInfo_async - */ - getProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo, - protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest | undefined, - {} | undefined - ] - >; - getProjectBillingInfo( - request: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): void; - getProjectBillingInfo( - request: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, - callback: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): void; - getProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo, - protos.google.cloud.billing.v1.IGetProjectBillingInfoRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.getProjectBillingInfo(request, options, callback); - } - /** - * Sets or updates the billing account associated with a project. You specify - * the new billing account by setting the `billing_account_name` in the - * `ProjectBillingInfo` resource to the resource name of a billing account. - * Associating a project with an open billing account enables billing on the - * project and allows charges for resource usage. If the project already had a - * billing account, this method changes the billing account used for resource - * usage charges. - * - * *Note:* Incurred charges that have not yet been reported in the transaction - * history of the Google Cloud Console might be billed to the new billing - * account, even if the charge occurred before the new billing account was - * assigned to the project. - * - * The current authenticated user must have ownership privileges for both the - * [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo - * ) and the [billing - * account](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * You can disable billing on the project by setting the - * `billing_account_name` field to empty. This action disassociates the - * current billing account from the project. Any billable activity of your - * in-use services will stop, and your application could stop functioning as - * expected. Any unbilled charges to date will be billed to the previously - * associated account. The current authenticated user must be either an owner - * of the project or an owner of the billing account for the project. - * - * Note that associating a project with a *closed* billing account will have - * much the same effect as disabling billing on the project: any paid - * resources used by the project will be shut down. Thus, unless you wish to - * disable billing, you should always call this method with the name of an - * *open* billing account. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the project associated with the billing - * information that you want to update. For example, - * `projects/tokyo-rain-123`. - * @param {google.cloud.billing.v1.ProjectBillingInfo} request.projectBillingInfo - * The new billing information for the project. Read-only fields are ignored; - * thus, you can leave empty all fields except `billing_account_name`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.cloud.billing.v1.ProjectBillingInfo | ProjectBillingInfo}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.update_project_billing_info.js - * region_tag:cloudbilling_v1_generated_CloudBilling_UpdateProjectBillingInfo_async - */ - updateProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo, - ( - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | undefined - ), - {} | undefined - ] - >; - updateProjectBillingInfo( - request: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): void; - updateProjectBillingInfo( - request: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, - callback: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): void; - updateProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.billing.v1.IProjectBillingInfo, - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo, - ( - | protos.google.cloud.billing.v1.IUpdateProjectBillingInfoRequest - | undefined - ), - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.updateProjectBillingInfo( - request, - options, - callback - ); - } - /** - * Gets the access control policy for a billing account. - * The caller must have the `billing.accounts.getIamPolicy` permission on the - * account, which is often given to billing account - * [viewers](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {google.iam.v1.GetPolicyOptions} request.options - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.get_iam_policy.js - * region_tag:cloudbilling_v1_generated_CloudBilling_GetIamPolicy_async - */ - getIamPolicy( - request?: protos.google.iam.v1.IGetIamPolicyRequest, - options?: CallOptions - ): Promise< - [ - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | undefined, - {} | undefined - ] - >; - getIamPolicy( - request: protos.google.iam.v1.IGetIamPolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): void; - getIamPolicy( - request: protos.google.iam.v1.IGetIamPolicyRequest, - callback: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): void; - getIamPolicy( - request?: protos.google.iam.v1.IGetIamPolicyRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.IGetIamPolicyRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - resource: request.resource ?? '', - }); - this.initialize(); - return this.innerApiCalls.getIamPolicy(request, options, callback); - } - /** - * Sets the access control policy for a billing account. Replaces any existing - * policy. - * The caller must have the `billing.accounts.setIamPolicy` permission on the - * account, which is often given to billing account - * [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy is being specified. - * See the operation documentation for the appropriate value for this field. - * @param {google.iam.v1.Policy} request.policy - * REQUIRED: The complete policy to be applied to the `resource`. The size of - * the policy is limited to a few 10s of KB. An empty policy is a - * valid policy but certain Cloud Platform services (such as Projects) - * might reject them. - * @param {google.protobuf.FieldMask} request.updateMask - * OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only - * the fields in the mask will be modified. If no mask is provided, the - * following default mask is used: - * - * `paths: "bindings, etag"` - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.Policy | Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.set_iam_policy.js - * region_tag:cloudbilling_v1_generated_CloudBilling_SetIamPolicy_async - */ - setIamPolicy( - request?: protos.google.iam.v1.ISetIamPolicyRequest, - options?: CallOptions - ): Promise< - [ - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | undefined, - {} | undefined - ] - >; - setIamPolicy( - request: protos.google.iam.v1.ISetIamPolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): void; - setIamPolicy( - request: protos.google.iam.v1.ISetIamPolicyRequest, - callback: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): void; - setIamPolicy( - request?: protos.google.iam.v1.ISetIamPolicyRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | null | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.iam.v1.IPolicy, - protos.google.iam.v1.ISetIamPolicyRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - resource: request.resource ?? '', - }); - this.initialize(); - return this.innerApiCalls.setIamPolicy(request, options, callback); - } - /** - * Tests the access control policy for a billing account. This method takes - * the resource and a set of permissions as input and returns the subset of - * the input permissions that the caller is allowed for that resource. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.resource - * REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param {string[]} request.permissions - * The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see - * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing {@link google.iam.v1.TestIamPermissionsResponse | TestIamPermissionsResponse}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.test_iam_permissions.js - * region_tag:cloudbilling_v1_generated_CloudBilling_TestIamPermissions_async - */ - testIamPermissions( - request?: protos.google.iam.v1.ITestIamPermissionsRequest, - options?: CallOptions - ): Promise< - [ - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | undefined, - {} | undefined - ] - >; - testIamPermissions( - request: protos.google.iam.v1.ITestIamPermissionsRequest, - options: CallOptions, - callback: Callback< - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ): void; - testIamPermissions( - request: protos.google.iam.v1.ITestIamPermissionsRequest, - callback: Callback< - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ): void; - testIamPermissions( - request?: protos.google.iam.v1.ITestIamPermissionsRequest, - optionsOrCallback?: - | CallOptions - | Callback< - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.iam.v1.ITestIamPermissionsResponse, - protos.google.iam.v1.ITestIamPermissionsRequest | undefined, - {} | undefined - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - resource: request.resource ?? '', - }); - this.initialize(); - return this.innerApiCalls.testIamPermissions(request, options, callback); - } - - /** - * Lists the billing accounts that the current authenticated user has - * permission to - * [view](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListBillingAccounts` - * call. If unspecified, the first page of results is returned. - * @param {string} request.filter - * Options for how to filter the returned billing accounts. - * Currently this only supports filtering for - * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a - * single provided reseller billing account. - * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). - * Boolean algebra and other fields are not currently supported. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of {@link google.cloud.billing.v1.BillingAccount | BillingAccount}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listBillingAccountsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listBillingAccounts( - request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount[], - protos.google.cloud.billing.v1.IListBillingAccountsRequest | null, - protos.google.cloud.billing.v1.IListBillingAccountsResponse - ] - >; - listBillingAccounts( - request: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListBillingAccountsRequest, - | protos.google.cloud.billing.v1.IListBillingAccountsResponse - | null - | undefined, - protos.google.cloud.billing.v1.IBillingAccount - > - ): void; - listBillingAccounts( - request: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListBillingAccountsRequest, - | protos.google.cloud.billing.v1.IListBillingAccountsResponse - | null - | undefined, - protos.google.cloud.billing.v1.IBillingAccount - > - ): void; - listBillingAccounts( - request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.cloud.billing.v1.IListBillingAccountsRequest, - | protos.google.cloud.billing.v1.IListBillingAccountsResponse - | null - | undefined, - protos.google.cloud.billing.v1.IBillingAccount - >, - callback?: PaginationCallback< - protos.google.cloud.billing.v1.IListBillingAccountsRequest, - | protos.google.cloud.billing.v1.IListBillingAccountsResponse - | null - | undefined, - protos.google.cloud.billing.v1.IBillingAccount - > - ): Promise< - [ - protos.google.cloud.billing.v1.IBillingAccount[], - protos.google.cloud.billing.v1.IListBillingAccountsRequest | null, - protos.google.cloud.billing.v1.IListBillingAccountsResponse - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - this.initialize(); - return this.innerApiCalls.listBillingAccounts(request, options, callback); - } - - /** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListBillingAccounts` - * call. If unspecified, the first page of results is returned. - * @param {string} request.filter - * Options for how to filter the returned billing accounts. - * Currently this only supports filtering for - * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a - * single provided reseller billing account. - * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). - * Boolean algebra and other fields are not currently supported. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link google.cloud.billing.v1.BillingAccount | BillingAccount} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listBillingAccountsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listBillingAccountsStream( - request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - options?: CallOptions - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const defaultCallSettings = this._defaults['listBillingAccounts']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listBillingAccounts.createStream( - this.innerApiCalls.listBillingAccounts as GaxCall, - request, - callSettings - ); - } - - /** - * Equivalent to `listBillingAccounts`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListBillingAccounts` - * call. If unspecified, the first page of results is returned. - * @param {string} request.filter - * Options for how to filter the returned billing accounts. - * Currently this only supports filtering for - * [subaccounts](https://cloud.google.com/billing/docs/concepts) under a - * single provided reseller billing account. - * (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). - * Boolean algebra and other fields are not currently supported. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.billing.v1.BillingAccount | BillingAccount}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.list_billing_accounts.js - * region_tag:cloudbilling_v1_generated_CloudBilling_ListBillingAccounts_async - */ - listBillingAccountsAsync( - request?: protos.google.cloud.billing.v1.IListBillingAccountsRequest, - options?: CallOptions - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const defaultCallSettings = this._defaults['listBillingAccounts']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listBillingAccounts.asyncIterate( - this.innerApiCalls['listBillingAccounts'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists the projects associated with a billing account. The current - * authenticated user must have the `billing.resourceAssociations.list` IAM - * permission, which is often given to billing account - * [viewers](https://cloud.google.com/billing/docs/how-to/billing-access). - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the billing account associated with the - * projects that you want to list. For example, - * `billingAccounts/012345-567890-ABCDEF`. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to be returned. This should be a - * `next_page_token` value returned from a previous `ListProjectBillingInfo` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of {@link google.cloud.billing.v1.ProjectBillingInfo | ProjectBillingInfo}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listProjectBillingInfoAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo[], - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest | null, - protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - ] - >; - listProjectBillingInfo( - request: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - | protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - | null - | undefined, - protos.google.cloud.billing.v1.IProjectBillingInfo - > - ): void; - listProjectBillingInfo( - request: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - | protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - | null - | undefined, - protos.google.cloud.billing.v1.IProjectBillingInfo - > - ): void; - listProjectBillingInfo( - request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - | protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - | null - | undefined, - protos.google.cloud.billing.v1.IProjectBillingInfo - >, - callback?: PaginationCallback< - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - | protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - | null - | undefined, - protos.google.cloud.billing.v1.IProjectBillingInfo - > - ): Promise< - [ - protos.google.cloud.billing.v1.IProjectBillingInfo[], - protos.google.cloud.billing.v1.IListProjectBillingInfoRequest | null, - protos.google.cloud.billing.v1.IListProjectBillingInfoResponse - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - this.initialize(); - return this.innerApiCalls.listProjectBillingInfo( - request, - options, - callback - ); - } - - /** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the billing account associated with the - * projects that you want to list. For example, - * `billingAccounts/012345-567890-ABCDEF`. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to be returned. This should be a - * `next_page_token` value returned from a previous `ListProjectBillingInfo` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link google.cloud.billing.v1.ProjectBillingInfo | ProjectBillingInfo} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listProjectBillingInfoAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listProjectBillingInfoStream( - request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - options?: CallOptions - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - const defaultCallSettings = this._defaults['listProjectBillingInfo']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listProjectBillingInfo.createStream( - this.innerApiCalls.listProjectBillingInfo as GaxCall, - request, - callSettings - ); - } - - /** - * Equivalent to `listProjectBillingInfo`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The resource name of the billing account associated with the - * projects that you want to list. For example, - * `billingAccounts/012345-567890-ABCDEF`. - * @param {number} request.pageSize - * Requested page size. The maximum page size is 100; this is also the - * default. - * @param {string} request.pageToken - * A token identifying a page of results to be returned. This should be a - * `next_page_token` value returned from a previous `ListProjectBillingInfo` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.billing.v1.ProjectBillingInfo | ProjectBillingInfo}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example include:samples/generated/v1/cloud_billing.list_project_billing_info.js - * region_tag:cloudbilling_v1_generated_CloudBilling_ListProjectBillingInfo_async - */ - listProjectBillingInfoAsync( - request?: protos.google.cloud.billing.v1.IListProjectBillingInfoRequest, - options?: CallOptions - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - name: request.name ?? '', - }); - const defaultCallSettings = this._defaults['listProjectBillingInfo']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listProjectBillingInfo.asyncIterate( - this.innerApiCalls['listProjectBillingInfo'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified billingAccount resource name string. - * - * @param {string} billing_account - * @returns {string} Resource name string. - */ - billingAccountPath(billingAccount: string) { - return this.pathTemplates.billingAccountPathTemplate.render({ - billing_account: billingAccount, - }); - } - - /** - * Parse the billing_account from BillingAccount resource. - * - * @param {string} billingAccountName - * A fully-qualified path representing BillingAccount resource. - * @returns {string} A string representing the billing_account. - */ - matchBillingAccountFromBillingAccountName(billingAccountName: string) { - return this.pathTemplates.billingAccountPathTemplate.match( - billingAccountName - ).billing_account; - } - - /** - * Return a fully-qualified service resource name string. - * - * @param {string} service - * @returns {string} Resource name string. - */ - servicePath(service: string) { - return this.pathTemplates.servicePathTemplate.render({ - service: service, - }); - } - - /** - * Parse the service from Service resource. - * - * @param {string} serviceName - * A fully-qualified path representing Service resource. - * @returns {string} A string representing the service. - */ - matchServiceFromServiceName(serviceName: string) { - return this.pathTemplates.servicePathTemplate.match(serviceName).service; - } - - /** - * Return a fully-qualified sku resource name string. - * - * @param {string} service - * @param {string} sku - * @returns {string} Resource name string. - */ - skuPath(service: string, sku: string) { - return this.pathTemplates.skuPathTemplate.render({ - service: service, - sku: sku, - }); - } - - /** - * Parse the service from Sku resource. - * - * @param {string} skuName - * A fully-qualified path representing Sku resource. - * @returns {string} A string representing the service. - */ - matchServiceFromSkuName(skuName: string) { - return this.pathTemplates.skuPathTemplate.match(skuName).service; - } - - /** - * Parse the sku from Sku resource. - * - * @param {string} skuName - * A fully-qualified path representing Sku resource. - * @returns {string} A string representing the sku. - */ - matchSkuFromSkuName(skuName: string) { - return this.pathTemplates.skuPathTemplate.match(skuName).sku; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.cloudBillingStub && !this._terminated) { - return this.cloudBillingStub.then(stub => { - this._terminated = true; - stub.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/packages/google-cloud-billing/src/v1/cloud_billing_client_config.json b/packages/google-cloud-billing/src/v1/cloud_billing_client_config.json deleted file mode 100644 index e98db6a6e4b..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_billing_client_config.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "interfaces": { - "google.cloud.billing.v1.CloudBilling": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "GetBillingAccount": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "ListBillingAccounts": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "UpdateBillingAccount": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "CreateBillingAccount": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListProjectBillingInfo": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "GetProjectBillingInfo": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "UpdateProjectBillingInfo": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "GetIamPolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "SetIamPolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - }, - "TestIamPermissions": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "default" - } - } - } - } -} diff --git a/packages/google-cloud-billing/src/v1/cloud_billing_proto_list.json b/packages/google-cloud-billing/src/v1/cloud_billing_proto_list.json deleted file mode 100644 index e34eb066aa5..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_billing_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/cloud/billing/v1/cloud_billing.proto", - "../../protos/google/cloud/billing/v1/cloud_catalog.proto" -] diff --git a/packages/google-cloud-billing/src/v1/cloud_catalog_client.ts b/packages/google-cloud-billing/src/v1/cloud_catalog_client.ts deleted file mode 100644 index a7f63761b12..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_catalog_client.ts +++ /dev/null @@ -1,837 +0,0 @@ -// Copyright 2023 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 -// -// 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. ** - -/* global window */ -import type * as gax from 'google-gax'; -import type { - Callback, - CallOptions, - Descriptors, - ClientOptions, - PaginationCallback, - GaxCall, -} from 'google-gax'; -import {Transform} from 'stream'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v1/cloud_catalog_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './cloud_catalog_client_config.json'; -const version = require('../../../package.json').version; - -/** - * A catalog of Google Cloud Platform services and SKUs. - * Provides pricing information and metadata on Google Cloud Platform services - * and SKUs. - * @class - * @memberof v1 - */ -export class CloudCatalogClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - pathTemplates: {[name: string]: gax.PathTemplate}; - cloudCatalogStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of CloudCatalogClient. - * - * @param {object} [options] - The configuration object. - * The options accepted by the constructor are described in detail - * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * API remote host. - * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. - * Follows the structure of {@link gapicConfig}. - * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode. - * Pass "rest" to use HTTP/1.1 REST API instead of gRPC. - * For more information, please check the - * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}. - * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you - * need to avoid loading the default gRPC version and want to use the fallback - * HTTP implementation. Load only fallback version and pass it to the constructor: - * ``` - * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC - * const client = new CloudCatalogClient({fallback: 'rest'}, gax); - * ``` - */ - constructor( - opts?: ClientOptions, - gaxInstance?: typeof gax | typeof gax.fallback - ) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof CloudCatalogClient; - const servicePath = - opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; - this._providedCustomServicePath = !!( - opts?.servicePath || opts?.apiEndpoint - ); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = - opts?.fallback ?? - (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); - - // Request numeric enum values if REST transport is used. - opts.numericEnums = true; - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Load google-gax module synchronously if needed - if (!gaxInstance) { - gaxInstance = require('google-gax') as typeof gax; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - - // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else if (opts.fallback === 'rest') { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - servicePathTemplate: new this._gaxModule.PathTemplate( - 'services/{service}' - ), - skuPathTemplate: new this._gaxModule.PathTemplate( - 'services/{service}/skus/{sku}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listServices: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'services' - ), - listSkus: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'skus' - ), - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.billing.v1.CloudCatalog', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')} - ); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = this._gaxModule.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.cloudCatalogStub) { - return this.cloudCatalogStub; - } - - // Put together the "service stub" for - // google.cloud.billing.v1.CloudCatalog. - this.cloudCatalogStub = this._gaxGrpc.createStub( - this._opts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.cloud.billing.v1.CloudCatalog' - ) - : // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.cloud.billing.v1.CloudCatalog, - this._opts, - this._providedCustomServicePath - ) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const cloudCatalogStubMethods = ['listServices', 'listSkus']; - for (const methodName of cloudCatalogStubMethods) { - const callPromise = this.cloudCatalogStub.then( - stub => - (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error | null | undefined) => () => { - throw err; - } - ); - - const descriptor = this.descriptors.page[methodName] || undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor, - this._opts.fallback - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.cloudCatalogStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'cloudbilling.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'cloudbilling.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-billing', - 'https://www.googleapis.com/auth/cloud-billing.readonly', - 'https://www.googleapis.com/auth/cloud-platform', - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId( - callback?: Callback - ): Promise | void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - - /** - * Lists all public cloud services. - * - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListServices` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of {@link google.cloud.billing.v1.Service | Service}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listServicesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listServices( - request?: protos.google.cloud.billing.v1.IListServicesRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.IService[], - protos.google.cloud.billing.v1.IListServicesRequest | null, - protos.google.cloud.billing.v1.IListServicesResponse - ] - >; - listServices( - request: protos.google.cloud.billing.v1.IListServicesRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListServicesRequest, - protos.google.cloud.billing.v1.IListServicesResponse | null | undefined, - protos.google.cloud.billing.v1.IService - > - ): void; - listServices( - request: protos.google.cloud.billing.v1.IListServicesRequest, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListServicesRequest, - protos.google.cloud.billing.v1.IListServicesResponse | null | undefined, - protos.google.cloud.billing.v1.IService - > - ): void; - listServices( - request?: protos.google.cloud.billing.v1.IListServicesRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.cloud.billing.v1.IListServicesRequest, - | protos.google.cloud.billing.v1.IListServicesResponse - | null - | undefined, - protos.google.cloud.billing.v1.IService - >, - callback?: PaginationCallback< - protos.google.cloud.billing.v1.IListServicesRequest, - protos.google.cloud.billing.v1.IListServicesResponse | null | undefined, - protos.google.cloud.billing.v1.IService - > - ): Promise< - [ - protos.google.cloud.billing.v1.IService[], - protos.google.cloud.billing.v1.IListServicesRequest | null, - protos.google.cloud.billing.v1.IListServicesResponse - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - this.initialize(); - return this.innerApiCalls.listServices(request, options, callback); - } - - /** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListServices` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link google.cloud.billing.v1.Service | Service} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listServicesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listServicesStream( - request?: protos.google.cloud.billing.v1.IListServicesRequest, - options?: CallOptions - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const defaultCallSettings = this._defaults['listServices']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listServices.createStream( - this.innerApiCalls.listServices as GaxCall, - request, - callSettings - ); - } - - /** - * Equivalent to `listServices`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListServices` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.billing.v1.Service | Service}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example include:samples/generated/v1/cloud_catalog.list_services.js - * region_tag:cloudbilling_v1_generated_CloudCatalog_ListServices_async - */ - listServicesAsync( - request?: protos.google.cloud.billing.v1.IListServicesRequest, - options?: CallOptions - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - const defaultCallSettings = this._defaults['listServices']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listServices.asyncIterate( - this.innerApiCalls['listServices'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - /** - * Lists all publicly available SKUs for a given cloud service. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the service. - * Example: "services/DA34-426B-A397" - * @param {google.protobuf.Timestamp} request.startTime - * Optional inclusive start time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {google.protobuf.Timestamp} request.endTime - * Optional exclusive end time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {string} request.currencyCode - * The ISO 4217 currency code for the pricing info in the response proto. - * Will use the conversion rate as of start_time. - * Optional. If not specified USD will be used. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListSkus` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of {@link google.cloud.billing.v1.Sku | Sku}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listSkusAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listSkus( - request?: protos.google.cloud.billing.v1.IListSkusRequest, - options?: CallOptions - ): Promise< - [ - protos.google.cloud.billing.v1.ISku[], - protos.google.cloud.billing.v1.IListSkusRequest | null, - protos.google.cloud.billing.v1.IListSkusResponse - ] - >; - listSkus( - request: protos.google.cloud.billing.v1.IListSkusRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListSkusRequest, - protos.google.cloud.billing.v1.IListSkusResponse | null | undefined, - protos.google.cloud.billing.v1.ISku - > - ): void; - listSkus( - request: protos.google.cloud.billing.v1.IListSkusRequest, - callback: PaginationCallback< - protos.google.cloud.billing.v1.IListSkusRequest, - protos.google.cloud.billing.v1.IListSkusResponse | null | undefined, - protos.google.cloud.billing.v1.ISku - > - ): void; - listSkus( - request?: protos.google.cloud.billing.v1.IListSkusRequest, - optionsOrCallback?: - | CallOptions - | PaginationCallback< - protos.google.cloud.billing.v1.IListSkusRequest, - protos.google.cloud.billing.v1.IListSkusResponse | null | undefined, - protos.google.cloud.billing.v1.ISku - >, - callback?: PaginationCallback< - protos.google.cloud.billing.v1.IListSkusRequest, - protos.google.cloud.billing.v1.IListSkusResponse | null | undefined, - protos.google.cloud.billing.v1.ISku - > - ): Promise< - [ - protos.google.cloud.billing.v1.ISku[], - protos.google.cloud.billing.v1.IListSkusRequest | null, - protos.google.cloud.billing.v1.IListSkusResponse - ] - > | void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - this.initialize(); - return this.innerApiCalls.listSkus(request, options, callback); - } - - /** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the service. - * Example: "services/DA34-426B-A397" - * @param {google.protobuf.Timestamp} request.startTime - * Optional inclusive start time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {google.protobuf.Timestamp} request.endTime - * Optional exclusive end time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {string} request.currencyCode - * The ISO 4217 currency code for the pricing info in the response proto. - * Will use the conversion rate as of start_time. - * Optional. If not specified USD will be used. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListSkus` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing {@link google.cloud.billing.v1.Sku | Sku} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listSkusAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listSkusStream( - request?: protos.google.cloud.billing.v1.IListSkusRequest, - options?: CallOptions - ): Transform { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listSkus']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSkus.createStream( - this.innerApiCalls.listSkus as GaxCall, - request, - callSettings - ); - } - - /** - * Equivalent to `listSkus`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The name of the service. - * Example: "services/DA34-426B-A397" - * @param {google.protobuf.Timestamp} request.startTime - * Optional inclusive start time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {google.protobuf.Timestamp} request.endTime - * Optional exclusive end time of the time range for which the pricing - * versions will be returned. Timestamps in the future are not allowed. - * The time range has to be within a single calendar month in - * America/Los_Angeles timezone. Time range as a whole is optional. If not - * specified, the latest pricing will be returned (up to 12 hours old at - * most). - * @param {string} request.currencyCode - * The ISO 4217 currency code for the pricing info in the response proto. - * Will use the conversion rate as of start_time. - * Optional. If not specified USD will be used. - * @param {number} request.pageSize - * Requested page size. Defaults to 5000. - * @param {string} request.pageToken - * A token identifying a page of results to return. This should be a - * `next_page_token` value returned from a previous `ListSkus` - * call. If unspecified, the first page of results is returned. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * {@link google.cloud.billing.v1.Sku | Sku}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example include:samples/generated/v1/cloud_catalog.list_skus.js - * region_tag:cloudbilling_v1_generated_CloudCatalog_ListSkus_async - */ - listSkusAsync( - request?: protos.google.cloud.billing.v1.IListSkusRequest, - options?: CallOptions - ): AsyncIterable { - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers['x-goog-request-params'] = - this._gaxModule.routingHeader.fromParams({ - parent: request.parent ?? '', - }); - const defaultCallSettings = this._defaults['listSkus']; - const callSettings = defaultCallSettings.merge(options); - this.initialize(); - return this.descriptors.page.listSkus.asyncIterate( - this.innerApiCalls['listSkus'] as GaxCall, - request as {}, - callSettings - ) as AsyncIterable; - } - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified service resource name string. - * - * @param {string} service - * @returns {string} Resource name string. - */ - servicePath(service: string) { - return this.pathTemplates.servicePathTemplate.render({ - service: service, - }); - } - - /** - * Parse the service from Service resource. - * - * @param {string} serviceName - * A fully-qualified path representing Service resource. - * @returns {string} A string representing the service. - */ - matchServiceFromServiceName(serviceName: string) { - return this.pathTemplates.servicePathTemplate.match(serviceName).service; - } - - /** - * Return a fully-qualified sku resource name string. - * - * @param {string} service - * @param {string} sku - * @returns {string} Resource name string. - */ - skuPath(service: string, sku: string) { - return this.pathTemplates.skuPathTemplate.render({ - service: service, - sku: sku, - }); - } - - /** - * Parse the service from Sku resource. - * - * @param {string} skuName - * A fully-qualified path representing Sku resource. - * @returns {string} A string representing the service. - */ - matchServiceFromSkuName(skuName: string) { - return this.pathTemplates.skuPathTemplate.match(skuName).service; - } - - /** - * Parse the sku from Sku resource. - * - * @param {string} skuName - * A fully-qualified path representing Sku resource. - * @returns {string} A string representing the sku. - */ - matchSkuFromSkuName(skuName: string) { - return this.pathTemplates.skuPathTemplate.match(skuName).sku; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - if (this.cloudCatalogStub && !this._terminated) { - return this.cloudCatalogStub.then(stub => { - this._terminated = true; - stub.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/packages/google-cloud-billing/src/v1/cloud_catalog_client_config.json b/packages/google-cloud-billing/src/v1/cloud_catalog_client_config.json deleted file mode 100644 index 65eb2dffc09..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_catalog_client_config.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "interfaces": { - "google.cloud.billing.v1.CloudCatalog": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "ListServices": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - }, - "ListSkus": { - "timeout_millis": 60000, - "retry_codes_name": "non_idempotent", - "retry_params_name": "default" - } - } - } - } -} diff --git a/packages/google-cloud-billing/src/v1/cloud_catalog_proto_list.json b/packages/google-cloud-billing/src/v1/cloud_catalog_proto_list.json deleted file mode 100644 index e34eb066aa5..00000000000 --- a/packages/google-cloud-billing/src/v1/cloud_catalog_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/cloud/billing/v1/cloud_billing.proto", - "../../protos/google/cloud/billing/v1/cloud_catalog.proto" -] diff --git a/packages/google-cloud-billing/src/v1/gapic_metadata.json b/packages/google-cloud-billing/src/v1/gapic_metadata.json deleted file mode 100644 index 57395f94def..00000000000 --- a/packages/google-cloud-billing/src/v1/gapic_metadata.json +++ /dev/null @@ -1,173 +0,0 @@ -{ - "schema": "1.0", - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "typescript", - "protoPackage": "google.cloud.billing.v1", - "libraryPackage": "@google-cloud/billing", - "services": { - "CloudBilling": { - "clients": { - "grpc": { - "libraryClient": "CloudBillingClient", - "rpcs": { - "GetBillingAccount": { - "methods": [ - "getBillingAccount" - ] - }, - "UpdateBillingAccount": { - "methods": [ - "updateBillingAccount" - ] - }, - "CreateBillingAccount": { - "methods": [ - "createBillingAccount" - ] - }, - "GetProjectBillingInfo": { - "methods": [ - "getProjectBillingInfo" - ] - }, - "UpdateProjectBillingInfo": { - "methods": [ - "updateProjectBillingInfo" - ] - }, - "GetIamPolicy": { - "methods": [ - "getIamPolicy" - ] - }, - "SetIamPolicy": { - "methods": [ - "setIamPolicy" - ] - }, - "TestIamPermissions": { - "methods": [ - "testIamPermissions" - ] - }, - "ListBillingAccounts": { - "methods": [ - "listBillingAccounts", - "listBillingAccountsStream", - "listBillingAccountsAsync" - ] - }, - "ListProjectBillingInfo": { - "methods": [ - "listProjectBillingInfo", - "listProjectBillingInfoStream", - "listProjectBillingInfoAsync" - ] - } - } - }, - "grpc-fallback": { - "libraryClient": "CloudBillingClient", - "rpcs": { - "GetBillingAccount": { - "methods": [ - "getBillingAccount" - ] - }, - "UpdateBillingAccount": { - "methods": [ - "updateBillingAccount" - ] - }, - "CreateBillingAccount": { - "methods": [ - "createBillingAccount" - ] - }, - "GetProjectBillingInfo": { - "methods": [ - "getProjectBillingInfo" - ] - }, - "UpdateProjectBillingInfo": { - "methods": [ - "updateProjectBillingInfo" - ] - }, - "GetIamPolicy": { - "methods": [ - "getIamPolicy" - ] - }, - "SetIamPolicy": { - "methods": [ - "setIamPolicy" - ] - }, - "TestIamPermissions": { - "methods": [ - "testIamPermissions" - ] - }, - "ListBillingAccounts": { - "methods": [ - "listBillingAccounts", - "listBillingAccountsStream", - "listBillingAccountsAsync" - ] - }, - "ListProjectBillingInfo": { - "methods": [ - "listProjectBillingInfo", - "listProjectBillingInfoStream", - "listProjectBillingInfoAsync" - ] - } - } - } - } - }, - "CloudCatalog": { - "clients": { - "grpc": { - "libraryClient": "CloudCatalogClient", - "rpcs": { - "ListServices": { - "methods": [ - "listServices", - "listServicesStream", - "listServicesAsync" - ] - }, - "ListSkus": { - "methods": [ - "listSkus", - "listSkusStream", - "listSkusAsync" - ] - } - } - }, - "grpc-fallback": { - "libraryClient": "CloudCatalogClient", - "rpcs": { - "ListServices": { - "methods": [ - "listServices", - "listServicesStream", - "listServicesAsync" - ] - }, - "ListSkus": { - "methods": [ - "listSkus", - "listSkusStream", - "listSkusAsync" - ] - } - } - } - } - } - } -} diff --git a/packages/google-cloud-billing/src/v1/index.ts b/packages/google-cloud-billing/src/v1/index.ts deleted file mode 100644 index 4a2e6d700cb..00000000000 --- a/packages/google-cloud-billing/src/v1/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 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 -// -// 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. ** - -export {CloudBillingClient} from './cloud_billing_client'; -export {CloudCatalogClient} from './cloud_catalog_client'; diff --git a/packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts b/packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts deleted file mode 100644 index f0625f299a5..00000000000 --- a/packages/google-cloud-billing/test/gapic_cloud_billing_v1.ts +++ /dev/null @@ -1,1950 +0,0 @@ -// Copyright 2023 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 -// -// 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. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudbillingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - require('../protos/protos.json') -).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = ( - instance.constructor as typeof protobuf.Message - ).toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject( - filledObject - ) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error - ? sinon.stub().rejects(error) - : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback( - response?: ResponseType, - error?: Error -) { - return error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall( - responses?: ResponseType[], - error?: Error -) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { - mockStream.write({}); - }); - } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall( - responses?: ResponseType[], - error?: Error -) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - }, - }; - }, - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.CloudBillingClient', () => { - describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = cloudbillingModule.v1.CloudBillingClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = cloudbillingModule.v1.CloudBillingClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = cloudbillingModule.v1.CloudBillingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudbillingModule.v1.CloudBillingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudBillingStub, undefined); - await client.initialize(); - assert(client.cloudBillingStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - assert(client.cloudBillingStub); - client.close().then(() => { - done(); - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudBillingStub, undefined); - client.close().then(() => { - done(); - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('getBillingAccount', () => { - it('invokes getBillingAccount without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.getBillingAccount = stubSimpleCall(expectedResponse); - const [response] = await client.getBillingAccount(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBillingAccount without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.getBillingAccount = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBillingAccount( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IBillingAccount | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBillingAccount with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBillingAccount = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.getBillingAccount(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBillingAccount with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getBillingAccount(request), expectedError); - }); - }); - - describe('updateBillingAccount', () => { - it('invokes updateBillingAccount without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.updateBillingAccount = - stubSimpleCall(expectedResponse); - const [response] = await client.updateBillingAccount(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBillingAccount without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.updateBillingAccount = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBillingAccount( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IBillingAccount | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBillingAccount with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBillingAccount = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.updateBillingAccount(request), expectedError); - const actualRequest = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateBillingAccount as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBillingAccount with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateBillingAccountRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateBillingAccountRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.updateBillingAccount(request), expectedError); - }); - }); - - describe('createBillingAccount', () => { - it('invokes createBillingAccount without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.CreateBillingAccountRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.createBillingAccount = - stubSimpleCall(expectedResponse); - const [response] = await client.createBillingAccount(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createBillingAccount without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.CreateBillingAccountRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ); - client.innerApiCalls.createBillingAccount = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBillingAccount( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IBillingAccount | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createBillingAccount with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.CreateBillingAccountRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createBillingAccount = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.createBillingAccount(request), expectedError); - }); - - it('invokes createBillingAccount with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.CreateBillingAccountRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.createBillingAccount(request), expectedError); - }); - }); - - describe('getProjectBillingInfo', () => { - it('invokes getProjectBillingInfo without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ); - client.innerApiCalls.getProjectBillingInfo = - stubSimpleCall(expectedResponse); - const [response] = await client.getProjectBillingInfo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProjectBillingInfo without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ); - client.innerApiCalls.getProjectBillingInfo = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProjectBillingInfo( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IProjectBillingInfo | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProjectBillingInfo with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getProjectBillingInfo = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects( - client.getProjectBillingInfo(request), - expectedError - ); - const actualRequest = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProjectBillingInfo with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.GetProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.GetProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects( - client.getProjectBillingInfo(request), - expectedError - ); - }); - }); - - describe('updateProjectBillingInfo', () => { - it('invokes updateProjectBillingInfo without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ); - client.innerApiCalls.updateProjectBillingInfo = - stubSimpleCall(expectedResponse); - const [response] = await client.updateProjectBillingInfo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProjectBillingInfo without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ); - client.innerApiCalls.updateProjectBillingInfo = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateProjectBillingInfo( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IProjectBillingInfo | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProjectBillingInfo with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateProjectBillingInfo = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects( - client.updateProjectBillingInfo(request), - expectedError - ); - const actualRequest = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.updateProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProjectBillingInfo with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.UpdateProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.UpdateProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects( - client.updateProjectBillingInfo(request), - expectedError - ); - }); - }); - - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.GetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.GetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - ( - err?: Error | null, - result?: protos.google.iam.v1.IPolicy | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.GetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.getIamPolicy = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.getIamPolicy(request), expectedError); - const actualRequest = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.getIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.GetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.getIamPolicy(request), expectedError); - }); - }); - - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.SetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.setIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.SetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - ( - err?: Error | null, - result?: protos.google.iam.v1.IPolicy | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.SetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.setIamPolicy = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.setIamPolicy(request), expectedError); - const actualRequest = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.setIamPolicy as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.SetIamPolicyRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.setIamPolicy(request), expectedError); - }); - }); - - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.TestIamPermissionsRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = - stubSimpleCall(expectedResponse); - const [response] = await client.testIamPermissions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.TestIamPermissionsRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - ( - err?: Error | null, - result?: protos.google.iam.v1.ITestIamPermissionsResponse | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.TestIamPermissionsRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.testIamPermissions = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.testIamPermissions(request), expectedError); - const actualRequest = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.testIamPermissions as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with closed client', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.iam.v1.TestIamPermissionsRequest', - ['resource'] - ); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close(); - await assert.rejects(client.testIamPermissions(request), expectedError); - }); - }); - - describe('listBillingAccounts', () => { - it('invokes listBillingAccounts without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - ]; - client.innerApiCalls.listBillingAccounts = - stubSimpleCall(expectedResponse); - const [response] = await client.listBillingAccounts(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listBillingAccounts without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - ]; - client.innerApiCalls.listBillingAccounts = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBillingAccounts( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IBillingAccount[] | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listBillingAccounts with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listBillingAccounts = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.listBillingAccounts(request), expectedError); - }); - - it('invokes listBillingAccountsStream without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - ]; - client.descriptors.page.listBillingAccounts.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listBillingAccountsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.BillingAccount[] = []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.BillingAccount) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listBillingAccounts.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listBillingAccounts, request) - ); - }); - - it('invokes listBillingAccountsStream with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listBillingAccounts.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listBillingAccountsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.BillingAccount[] = []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.BillingAccount) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listBillingAccounts.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listBillingAccounts, request) - ); - }); - - it('uses async iteration with listBillingAccounts without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.BillingAccount() - ), - ]; - client.descriptors.page.listBillingAccounts.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.billing.v1.IBillingAccount[] = []; - const iterable = client.listBillingAccountsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listBillingAccounts.asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - }); - - it('uses async iteration with listBillingAccounts with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListBillingAccountsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listBillingAccounts.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBillingAccountsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.billing.v1.IBillingAccount[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listBillingAccounts.asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - }); - }); - - describe('listProjectBillingInfo', () => { - it('invokes listProjectBillingInfo without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - ]; - client.innerApiCalls.listProjectBillingInfo = - stubSimpleCall(expectedResponse); - const [response] = await client.listProjectBillingInfo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProjectBillingInfo without error using callback', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - ]; - client.innerApiCalls.listProjectBillingInfo = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listProjectBillingInfo( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IProjectBillingInfo[] | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProjectBillingInfo with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listProjectBillingInfo = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects( - client.listProjectBillingInfo(request), - expectedError - ); - const actualRequest = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listProjectBillingInfo as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProjectBillingInfoStream without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - ]; - client.descriptors.page.listProjectBillingInfo.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listProjectBillingInfoStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.ProjectBillingInfo[] = - []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.ProjectBillingInfo) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .createStream as SinonStub - ) - .getCall(0) - .calledWith(client.innerApiCalls.listProjectBillingInfo, request) - ); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .createStream as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listProjectBillingInfoStream with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listProjectBillingInfo.createStream = - stubPageStreamingCall(undefined, expectedError); - const stream = client.listProjectBillingInfoStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.ProjectBillingInfo[] = - []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.ProjectBillingInfo) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .createStream as SinonStub - ) - .getCall(0) - .calledWith(client.innerApiCalls.listProjectBillingInfo, request) - ); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .createStream as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProjectBillingInfo without error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - generateSampleMessage( - new protos.google.cloud.billing.v1.ProjectBillingInfo() - ), - ]; - client.descriptors.page.listProjectBillingInfo.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.billing.v1.IProjectBillingInfo[] = - []; - const iterable = client.listProjectBillingInfoAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listProjectBillingInfo - .asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProjectBillingInfo with error', async () => { - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListProjectBillingInfoRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListProjectBillingInfoRequest', - ['name'] - ); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listProjectBillingInfo.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listProjectBillingInfoAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.billing.v1.IProjectBillingInfo[] = - []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listProjectBillingInfo - .asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - assert( - ( - client.descriptors.page.listProjectBillingInfo - .asyncIterate as SinonStub - ) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - describe('billingAccount', () => { - const fakePath = '/rendered/path/billingAccount'; - const expectedParameters = { - billing_account: 'billingAccountValue', - }; - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.billingAccountPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.billingAccountPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('billingAccountPath', () => { - const result = client.billingAccountPath('billingAccountValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.billingAccountPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchBillingAccountFromBillingAccountName', () => { - const result = - client.matchBillingAccountFromBillingAccountName(fakePath); - assert.strictEqual(result, 'billingAccountValue'); - assert( - (client.pathTemplates.billingAccountPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - }); - - describe('service', () => { - const fakePath = '/rendered/path/service'; - const expectedParameters = { - service: 'serviceValue', - }; - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.servicePathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.servicePathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('servicePath', () => { - const result = client.servicePath('serviceValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.servicePathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchServiceFromServiceName', () => { - const result = client.matchServiceFromServiceName(fakePath); - assert.strictEqual(result, 'serviceValue'); - assert( - (client.pathTemplates.servicePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - }); - - describe('sku', () => { - const fakePath = '/rendered/path/sku'; - const expectedParameters = { - service: 'serviceValue', - sku: 'skuValue', - }; - const client = new cloudbillingModule.v1.CloudBillingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.skuPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.skuPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('skuPath', () => { - const result = client.skuPath('serviceValue', 'skuValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.skuPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchServiceFromSkuName', () => { - const result = client.matchServiceFromSkuName(fakePath); - assert.strictEqual(result, 'serviceValue'); - assert( - (client.pathTemplates.skuPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - - it('matchSkuFromSkuName', () => { - const result = client.matchSkuFromSkuName(fakePath); - assert.strictEqual(result, 'skuValue'); - assert( - (client.pathTemplates.skuPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - }); - }); -}); diff --git a/packages/google-cloud-billing/test/gapic_cloud_catalog_v1.ts b/packages/google-cloud-billing/test/gapic_cloud_catalog_v1.ts deleted file mode 100644 index 5d622d5061c..00000000000 --- a/packages/google-cloud-billing/test/gapic_cloud_catalog_v1.ts +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright 2023 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 -// -// 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. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudcatalogModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - require('../protos/protos.json') -).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = ( - instance.constructor as typeof protobuf.Message - ).toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject( - filledObject - ) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error - ? sinon.stub().rejects(error) - : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback( - response?: ResponseType, - error?: Error -) { - return error - ? sinon.stub().callsArgWith(2, error) - : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall( - responses?: ResponseType[], - error?: Error -) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error - ? sinon.stub().callsArgWith(2, error) - : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { - mockStream.write({}); - }); - } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); - }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall( - responses?: ResponseType[], - error?: Error -) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - }, - }; - }, - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.CloudCatalogClient', () => { - describe('Common methods', () => { - it('has servicePath', () => { - const servicePath = cloudcatalogModule.v1.CloudCatalogClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = cloudcatalogModule.v1.CloudCatalogClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = cloudcatalogModule.v1.CloudCatalogClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudCatalogStub, undefined); - await client.initialize(); - assert(client.cloudCatalogStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - assert(client.cloudCatalogStub); - client.close().then(() => { - done(); - }); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudCatalogStub, undefined); - client.close().then(() => { - done(); - }); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('listServices', () => { - it('invokes listServices without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - ]; - client.innerApiCalls.listServices = stubSimpleCall(expectedResponse); - const [response] = await client.listServices(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listServices without error using callback', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - ]; - client.innerApiCalls.listServices = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServices( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.IService[] | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listServices with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listServices = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(client.listServices(request), expectedError); - }); - - it('invokes listServicesStream without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - ]; - client.descriptors.page.listServices.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.Service[] = []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.Service) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listServices, request) - ); - }); - - it('invokes listServicesStream with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listServices.createStream = stubPageStreamingCall( - undefined, - expectedError - ); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.Service[] = []; - stream.on( - 'data', - (response: protos.google.cloud.billing.v1.Service) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listServices, request) - ); - }); - - it('uses async iteration with listServices without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - generateSampleMessage(new protos.google.cloud.billing.v1.Service()), - ]; - client.descriptors.page.listServices.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.billing.v1.IService[] = []; - const iterable = client.listServicesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - ( - client.descriptors.page.listServices.asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - }); - - it('uses async iteration with listServices with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListServicesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listServices.asyncIterate = - stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServicesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.billing.v1.IService[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - ( - client.descriptors.page.listServices.asyncIterate as SinonStub - ).getCall(0).args[1], - request - ); - }); - }); - - describe('listSkus', () => { - it('invokes listSkus without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - ]; - client.innerApiCalls.listSkus = stubSimpleCall(expectedResponse); - const [response] = await client.listSkus(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSkus without error using callback', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - ]; - client.innerApiCalls.listSkus = - stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSkus( - request, - ( - err?: Error | null, - result?: protos.google.cloud.billing.v1.ISku[] | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSkus with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSkus = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSkus(request), expectedError); - const actualRequest = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = ( - client.innerApiCalls.listSkus as SinonStub - ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSkusStream without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - ]; - client.descriptors.page.listSkus.createStream = - stubPageStreamingCall(expectedResponse); - const stream = client.listSkusStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.Sku[] = []; - stream.on('data', (response: protos.google.cloud.billing.v1.Sku) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listSkus.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listSkus, request) - ); - assert( - (client.descriptors.page.listSkus.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSkusStream with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSkus.createStream = stubPageStreamingCall( - undefined, - expectedError - ); - const stream = client.listSkusStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.billing.v1.Sku[] = []; - stream.on('data', (response: protos.google.cloud.billing.v1.Sku) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert( - (client.descriptors.page.listSkus.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listSkus, request) - ); - assert( - (client.descriptors.page.listSkus.createStream as SinonStub) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSkus without error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - generateSampleMessage(new protos.google.cloud.billing.v1.Sku()), - ]; - client.descriptors.page.listSkus.asyncIterate = - stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.billing.v1.ISku[] = []; - const iterable = client.listSkusAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSkus.asyncIterate as SinonStub).getCall(0) - .args[1], - request - ); - assert( - (client.descriptors.page.listSkus.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSkus with error', async () => { - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.billing.v1.ListSkusRequest() - ); - const defaultValue1 = getTypeDefaultValue( - '.google.cloud.billing.v1.ListSkusRequest', - ['parent'] - ); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1}`; - const expectedError = new Error('expected'); - client.descriptors.page.listSkus.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); - const iterable = client.listSkusAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.billing.v1.ISku[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSkus.asyncIterate as SinonStub).getCall(0) - .args[1], - request - ); - assert( - (client.descriptors.page.listSkus.asyncIterate as SinonStub) - .getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - describe('service', () => { - const fakePath = '/rendered/path/service'; - const expectedParameters = { - service: 'serviceValue', - }; - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.servicePathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.servicePathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('servicePath', () => { - const result = client.servicePath('serviceValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.servicePathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchServiceFromServiceName', () => { - const result = client.matchServiceFromServiceName(fakePath); - assert.strictEqual(result, 'serviceValue'); - assert( - (client.pathTemplates.servicePathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - }); - - describe('sku', () => { - const fakePath = '/rendered/path/sku'; - const expectedParameters = { - service: 'serviceValue', - sku: 'skuValue', - }; - const client = new cloudcatalogModule.v1.CloudCatalogClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.skuPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.skuPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('skuPath', () => { - const result = client.skuPath('serviceValue', 'skuValue'); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.skuPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchServiceFromSkuName', () => { - const result = client.matchServiceFromSkuName(fakePath); - assert.strictEqual(result, 'serviceValue'); - assert( - (client.pathTemplates.skuPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - - it('matchSkuFromSkuName', () => { - const result = client.matchSkuFromSkuName(fakePath); - assert.strictEqual(result, 'skuValue'); - assert( - (client.pathTemplates.skuPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - }); - }); -});