From 16e8657b6022813b2173886968da95e18b758808 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:31:00 -0400 Subject: [PATCH 1/9] chore: ignore samples/build/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d4f03a0d..6e093592 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /docs/ /out/ /build/ +samples/build/ system-test/secrets.js system-test/*key.json *.lock From dcd4db6389446b7bd6b750fa3a9ed2819d8767f0 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:31:39 -0400 Subject: [PATCH 2/9] fix: convert string ports to number ports to match grpc --- src/pubsub.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pubsub.ts b/src/pubsub.ts index a2df1d01..ffc76eef 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -307,6 +307,11 @@ export class PubSub { allScopes[scope] = true; } } + + // The old type allows a string port value. If the user provided one, convert it. + if (typeof options?.port === 'string') { + options.port = Number.parseInt(options.port); + } this.options = Object.assign( { libName: 'gccl', From b517618afe8bd95794fcd9ab7401b293adc68cc4 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:33:40 -0400 Subject: [PATCH 3/9] feat: provide redacted topic and subscription admin clients --- src/pubsub.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/pubsub.ts b/src/pubsub.ts index ffc76eef..15b31709 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -57,7 +57,7 @@ import {PublishOptions} from './publisher'; import {CallOptions} from 'google-gax'; import {Transform} from 'stream'; import {google} from '../protos/protos'; -import {SchemaServiceClient} from './v1'; +import {PublisherClient, SchemaServiceClient, SubscriberClient} from './v1'; /** * Project ID placeholder. @@ -90,6 +90,33 @@ export interface ClientConfig extends gax.GrpcClientOptions { sslCreds?: gax.grpc.ChannelCredentials; } +const topicOmitted = ['publish']; +export type TopicAdminClient = Omit; + +const subOmitted = [ + 'pull', + 'modifyAckDeadline', + 'acknowledge', + 'seek', + 'streamingPull', +]; +export type SubscriptionAdminClient = Omit< + SubscriberClient, + 'pull' | 'modifyAckDeadline' | 'acknowledge' | 'seek' | 'streamingPull' +>; + +// This is just a temporary fix until we get fully separated gapic admin clients. +// It doesn't take much to work around these low-key guard-rails, but it's just +// there as a reminder to try to help avoiding code that won't be valid later. +// +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function removeMethods(obj: any, methods: string[]): T { + for (const m of methods) { + delete obj[m]; + } + return obj; +} + export interface PageOptions { gaxOpts?: CallOptions; pageSize?: number; @@ -285,6 +312,8 @@ export class PubSub { isOpen = true; private schemaClient?: SchemaServiceClient; + private topicAdminClient?: TopicAdminClient; + private subscriptionAdminClient?: SubscriptionAdminClient; constructor(options?: ClientConfig) { // Needed for potentially large responses that may come from using exactly-once delivery, @@ -1244,6 +1273,40 @@ export class PubSub { return this.options; } + /** + * Gets a topic admin client, creating one if needed. + * + * @returns {Promise} + */ + async getTopicAdminClient(): Promise { + if (!this.topicAdminClient) { + const options = await this.getClientConfig(); + this.topicAdminClient = removeMethods( + new v1.PublisherClient(options), + topicOmitted + ); + } + + return this.topicAdminClient; + } + + /** + * Gets a subscription admin client, creating one if needed. + * + * @returns {Promise} + */ + async getSubscriptionAdminClient(): Promise { + if (!this.subscriptionAdminClient) { + const options = await this.getClientConfig(); + this.subscriptionAdminClient = removeMethods( + new v1.SubscriberClient(options), + subOmitted + ); + } + + return this.subscriptionAdminClient; + } + /** * Gets a schema client, creating one if needed. This is a shortcut for * `new v1.SchemaServiceClient(await pubsub.getClientConfig())`. From 70ec138cb94ddf7779942cb8798e96c23b68fc48 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:34:03 -0400 Subject: [PATCH 4/9] tests: allow for storage bucket name gen --- samples/system-test/testResources.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/samples/system-test/testResources.ts b/samples/system-test/testResources.ts index 1887698a..045b0107 100644 --- a/samples/system-test/testResources.ts +++ b/samples/system-test/testResources.ts @@ -101,6 +101,16 @@ export class TestResources { ); } + /** + * Generates a unique resource name for one run of a test within + * a test suite for Cloud Storage resources. + */ + generateStorageName(testId: string): string { + return [normalizeId(this.getPrefix(testId)), this.tokenMaker.uuid()].join( + '_' + ); + } + /*! * Given a list of resource names (and a test ID), this will return * a list of all resources that should be deleted to clean up for From a2bd95b57934f1000a7e0bf22f15b33baee077d9 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:36:06 -0400 Subject: [PATCH 5/9] samples: add sample for subscription with cloud storage bucket --- samples/package.json | 1 + samples/system-test/subscriptions.test.ts | 32 +++++- .../createSubscriptionWithCloudStorage.ts | 97 +++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 samples/typescript/createSubscriptionWithCloudStorage.ts diff --git a/samples/package.json b/samples/package.json index c98b6fb5..8b6372ca 100644 --- a/samples/package.json +++ b/samples/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "@google-cloud/pubsub": "^4.4.0", + "@google-cloud/storage": "^7.11.1", "@opentelemetry/api": "^1.6.0", "@opentelemetry/tracing": "^0.24.0", "avro-js": "^1.11.3", diff --git a/samples/system-test/subscriptions.test.ts b/samples/system-test/subscriptions.test.ts index bcd60c3f..d3375e56 100644 --- a/samples/system-test/subscriptions.test.ts +++ b/samples/system-test/subscriptions.test.ts @@ -13,6 +13,7 @@ // limitations under the License. import {BigQuery} from '@google-cloud/bigquery'; +import {Bucket, Storage} from '@google-cloud/storage'; import { CreateSubscriptionOptions, PubSub, @@ -74,7 +75,7 @@ describe('subscriptions', () => { async function createBigQueryTable(datasetId: string, tableId: string) { const bigquery = new BigQuery({ - projectId: projectId, + projectId, }); const datasetOptions = { @@ -108,6 +109,17 @@ describe('subscriptions', () => { await bigquery.dataset(datasetId).delete(deleteOptions); } + async function createStorageBucket(testName: string): Promise { + const storage = new Storage({ + projectId, + }); + + const name = resources.generateStorageName(testName); + + const [bucket] = await storage.createBucket(name); + return bucket; + } + async function cleanSubs() { const [subscriptions] = await pubsub.getSubscriptions(); await Promise.all( @@ -428,6 +440,24 @@ describe('subscriptions', () => { assert(subscriptionDetached === true); }); + it('should create a subscription with a cloud storage config', async () => { + const testId = 'sub_storage'; + const topic = await createTopic(testId); + const subName = reserveSub(testId); + const bucket = await createStorageBucket(testId); + const bucketName = bucket.name; + try { + const output = execSync( + `${commandFor('createSubscriptionWithCloudStorage')} ${ + topic.name + } projects/${projectId}/subscriptions/${subName} ${bucketName} 'prefix' 'suffix' 60` + ); + assert.include(output, 'Created subscription'); + } finally { + bucket.delete(); + } + }); + it('should create a subscription with dead letter policy.', async () => { const testId = 'dead_letter'; const topic = await createTopic(testId), diff --git a/samples/typescript/createSubscriptionWithCloudStorage.ts b/samples/typescript/createSubscriptionWithCloudStorage.ts new file mode 100644 index 00000000..a99e14c0 --- /dev/null +++ b/samples/typescript/createSubscriptionWithCloudStorage.ts @@ -0,0 +1,97 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This snippet demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create a Cloud Storage subscription +// description: Demonstrates how to create a subscription with Cloud Storage. +// usage: node createSubscriptionWithCloudStorage.js + +// [START pubsub_create_cloud_storage_subscription] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicName = 'YOUR_TOPIC_NAME'; +// const subscriptionName = 'YOUR_SUBSCRIPTION_NAME'; +// const bucket = 'YOUR_BUCKET_ID'; +// const filenamePrefix = 'YOUR_FILENAME_PREFIX'; +// const filenameSuffix = 'YOUR_FILENAME_SUFFIX'; +// const maxDuration = 60; + +// Imports the Google Cloud client library +import {PubSub} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createSubscriptionWithCloudStorage( + topicName: string, + subscriptionName: string, + bucket: string, + filenamePrefix: string, + filenameSuffix: string, + maxDuration: number +) { + // Use a gapic client for admin operations + const subscriptionAdmin = await pubSubClient.getSubscriptionAdminClient(); + + // Creates a new subscription + await subscriptionAdmin.createSubscription({ + name: subscriptionName, + topic: topicName, + cloudStorageConfig: { + bucket, + filenamePrefix, + filenameSuffix, + maxDuration: { + seconds: maxDuration, + }, + }, + }); + + console.log( + `Created subscription ${subscriptionName} with a cloud storage configuration.` + ); +} +// [END pubsub_create_cloud_storage_subscription] + +function main( + topicName = 'YOUR_TOPIC_NAME', + subscriptionName = 'YOUR_SUBSCRIPTION_NAME', + bucket = 'YOUR_BUCKET_NAME', + filenamePrefix = 'YOUR_FILENAME_PREFIX', + filenameSuffix = 'YOUR_FILENAME_SUFFIX', + maxDuration = 60 +) { + createSubscriptionWithCloudStorage( + topicName, + subscriptionName, + bucket, + filenamePrefix, + filenameSuffix, + maxDuration + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); From a89be04a42079df7c0f1f405d56877fa3fb8c43a Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 11 Jun 2024 18:28:13 +0000 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 1 + samples/README.md | 20 ++++ samples/createSubscriptionWithCloudStorage.js | 101 ++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 samples/createSubscriptionWithCloudStorage.js diff --git a/README.md b/README.md index 175f24bb..73557136 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Create Push Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createPushSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createPushSubscription.js,samples/README.md) | | Create Push Subscription With No Wrapper | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createPushSubscriptionNoWrapper.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createPushSubscriptionNoWrapper.js,samples/README.md) | | Create Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscription.js,samples/README.md) | +| Create a Cloud Storage subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithCloudStorage.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithCloudStorage.js,samples/README.md) | | Create Subscription With Dead Letter Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithDeadLetterPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithDeadLetterPolicy.js,samples/README.md) | | Create an exactly-once delivery subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithExactlyOnceDelivery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithExactlyOnceDelivery.js,samples/README.md) | | Create Subscription With Filtering | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithFiltering.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithFiltering.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index b1b445b2..a855cc3f 100644 --- a/samples/README.md +++ b/samples/README.md @@ -28,6 +28,7 @@ guides. * [Create Push Subscription](#create-push-subscription) * [Create Push Subscription With No Wrapper](#create-push-subscription-with-no-wrapper) * [Create Subscription](#create-subscription) + * [Create a Cloud Storage subscription](#create-a-cloud-storage-subscription) * [Create Subscription With Dead Letter Policy](#create-subscription-with-dead-letter-policy) * [Create an exactly-once delivery subscription](#create-an-exactly-once-delivery-subscription) * [Create Subscription With Filtering](#create-subscription-with-filtering) @@ -253,6 +254,25 @@ __Usage:__ +### Create a Cloud Storage subscription + +Demonstrates how to create a subscription with Cloud Storage. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithCloudStorage.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithCloudStorage.js,samples/README.md) + +__Usage:__ + + +`node createSubscriptionWithCloudStorage.js ` + + +----- + + + + ### Create Subscription With Dead Letter Policy Creates a new subscription With Dead Letter Policy. diff --git a/samples/createSubscriptionWithCloudStorage.js b/samples/createSubscriptionWithCloudStorage.js new file mode 100644 index 00000000..1e96ab16 --- /dev/null +++ b/samples/createSubscriptionWithCloudStorage.js @@ -0,0 +1,101 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This snippet demonstrates how to perform basic operations on + * schemas with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create a Cloud Storage subscription +// description: Demonstrates how to create a subscription with Cloud Storage. +// usage: node createSubscriptionWithCloudStorage.js + +// [START pubsub_create_cloud_storage_subscription] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicName = 'YOUR_TOPIC_NAME'; +// const subscriptionName = 'YOUR_SUBSCRIPTION_NAME'; +// const bucket = 'YOUR_BUCKET_ID'; +// const filenamePrefix = 'YOUR_FILENAME_PREFIX'; +// const filenameSuffix = 'YOUR_FILENAME_SUFFIX'; +// const maxDuration = 60; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createSubscriptionWithCloudStorage( + topicName, + subscriptionName, + bucket, + filenamePrefix, + filenameSuffix, + maxDuration +) { + // Use a gapic client for admin operations + const subscriptionAdmin = await pubSubClient.getSubscriptionAdminClient(); + + // Creates a new subscription + await subscriptionAdmin.createSubscription({ + name: subscriptionName, + topic: topicName, + cloudStorageConfig: { + bucket, + filenamePrefix, + filenameSuffix, + maxDuration: { + seconds: maxDuration, + }, + }, + }); + + console.log( + `Created subscription ${subscriptionName} with a cloud storage configuration.` + ); +} +// [END pubsub_create_cloud_storage_subscription] + +function main( + topicName = 'YOUR_TOPIC_NAME', + subscriptionName = 'YOUR_SUBSCRIPTION_NAME', + bucket = 'YOUR_BUCKET_NAME', + filenamePrefix = 'YOUR_FILENAME_PREFIX', + filenameSuffix = 'YOUR_FILENAME_SUFFIX', + maxDuration = 60 +) { + createSubscriptionWithCloudStorage( + topicName, + subscriptionName, + bucket, + filenamePrefix, + filenameSuffix, + maxDuration + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); +} + +main(...process.argv.slice(2)); From b87f71d4eaaffbb38162b24b7f860a51aedfb9b1 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:52:44 -0400 Subject: [PATCH 7/9] samples: remove gapic getters to be split to another PR --- samples/createSubscriptionWithCloudStorage.js | 16 ++--- .../createSubscriptionWithCloudStorage.ts | 18 +++-- src/pubsub.ts | 69 +------------------ 3 files changed, 16 insertions(+), 87 deletions(-) diff --git a/samples/createSubscriptionWithCloudStorage.js b/samples/createSubscriptionWithCloudStorage.js index 1e96ab16..ffac5731 100644 --- a/samples/createSubscriptionWithCloudStorage.js +++ b/samples/createSubscriptionWithCloudStorage.js @@ -54,13 +54,7 @@ async function createSubscriptionWithCloudStorage( filenameSuffix, maxDuration ) { - // Use a gapic client for admin operations - const subscriptionAdmin = await pubSubClient.getSubscriptionAdminClient(); - - // Creates a new subscription - await subscriptionAdmin.createSubscription({ - name: subscriptionName, - topic: topicName, + const options = { cloudStorageConfig: { bucket, filenamePrefix, @@ -69,10 +63,14 @@ async function createSubscriptionWithCloudStorage( seconds: maxDuration, }, }, - }); + }; + + const [sub] = await pubSubClient + .topic(topicName) + .createSubscription(subscriptionName, options); console.log( - `Created subscription ${subscriptionName} with a cloud storage configuration.` + `Created subscription ${sub.name} with a cloud storage configuration.` ); } // [END pubsub_create_cloud_storage_subscription] diff --git a/samples/typescript/createSubscriptionWithCloudStorage.ts b/samples/typescript/createSubscriptionWithCloudStorage.ts index a99e14c0..1fca6986 100644 --- a/samples/typescript/createSubscriptionWithCloudStorage.ts +++ b/samples/typescript/createSubscriptionWithCloudStorage.ts @@ -37,7 +37,7 @@ // const maxDuration = 60; // Imports the Google Cloud client library -import {PubSub} from '@google-cloud/pubsub'; +import {CreateSubscriptionOptions, PubSub} from '@google-cloud/pubsub'; // Creates a client; cache this for further use const pubSubClient = new PubSub(); @@ -50,13 +50,7 @@ async function createSubscriptionWithCloudStorage( filenameSuffix: string, maxDuration: number ) { - // Use a gapic client for admin operations - const subscriptionAdmin = await pubSubClient.getSubscriptionAdminClient(); - - // Creates a new subscription - await subscriptionAdmin.createSubscription({ - name: subscriptionName, - topic: topicName, + const options: CreateSubscriptionOptions = { cloudStorageConfig: { bucket, filenamePrefix, @@ -65,10 +59,14 @@ async function createSubscriptionWithCloudStorage( seconds: maxDuration, }, }, - }); + }; + + const [sub] = await pubSubClient + .topic(topicName) + .createSubscription(subscriptionName, options); console.log( - `Created subscription ${subscriptionName} with a cloud storage configuration.` + `Created subscription ${sub.name} with a cloud storage configuration.` ); } // [END pubsub_create_cloud_storage_subscription] diff --git a/src/pubsub.ts b/src/pubsub.ts index 15b31709..03a2ff9e 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -57,7 +57,7 @@ import {PublishOptions} from './publisher'; import {CallOptions} from 'google-gax'; import {Transform} from 'stream'; import {google} from '../protos/protos'; -import {PublisherClient, SchemaServiceClient, SubscriberClient} from './v1'; +import {SchemaServiceClient} from './v1'; /** * Project ID placeholder. @@ -90,33 +90,6 @@ export interface ClientConfig extends gax.GrpcClientOptions { sslCreds?: gax.grpc.ChannelCredentials; } -const topicOmitted = ['publish']; -export type TopicAdminClient = Omit; - -const subOmitted = [ - 'pull', - 'modifyAckDeadline', - 'acknowledge', - 'seek', - 'streamingPull', -]; -export type SubscriptionAdminClient = Omit< - SubscriberClient, - 'pull' | 'modifyAckDeadline' | 'acknowledge' | 'seek' | 'streamingPull' ->; - -// This is just a temporary fix until we get fully separated gapic admin clients. -// It doesn't take much to work around these low-key guard-rails, but it's just -// there as a reminder to try to help avoiding code that won't be valid later. -// -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function removeMethods(obj: any, methods: string[]): T { - for (const m of methods) { - delete obj[m]; - } - return obj; -} - export interface PageOptions { gaxOpts?: CallOptions; pageSize?: number; @@ -312,8 +285,6 @@ export class PubSub { isOpen = true; private schemaClient?: SchemaServiceClient; - private topicAdminClient?: TopicAdminClient; - private subscriptionAdminClient?: SubscriptionAdminClient; constructor(options?: ClientConfig) { // Needed for potentially large responses that may come from using exactly-once delivery, @@ -337,10 +308,6 @@ export class PubSub { } } - // The old type allows a string port value. If the user provided one, convert it. - if (typeof options?.port === 'string') { - options.port = Number.parseInt(options.port); - } this.options = Object.assign( { libName: 'gccl', @@ -1273,40 +1240,6 @@ export class PubSub { return this.options; } - /** - * Gets a topic admin client, creating one if needed. - * - * @returns {Promise} - */ - async getTopicAdminClient(): Promise { - if (!this.topicAdminClient) { - const options = await this.getClientConfig(); - this.topicAdminClient = removeMethods( - new v1.PublisherClient(options), - topicOmitted - ); - } - - return this.topicAdminClient; - } - - /** - * Gets a subscription admin client, creating one if needed. - * - * @returns {Promise} - */ - async getSubscriptionAdminClient(): Promise { - if (!this.subscriptionAdminClient) { - const options = await this.getClientConfig(); - this.subscriptionAdminClient = removeMethods( - new v1.SubscriberClient(options), - subOmitted - ); - } - - return this.subscriptionAdminClient; - } - /** * Gets a schema client, creating one if needed. This is a shortcut for * `new v1.SchemaServiceClient(await pubsub.getClientConfig())`. From 88bf9e5ecd29eba89189a8b7fd9a554095893846 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:58:49 -0400 Subject: [PATCH 8/9] samples: update for review changes --- samples/createSubscriptionWithCloudStorage.js | 10 +++++----- .../typescript/createSubscriptionWithCloudStorage.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/createSubscriptionWithCloudStorage.js b/samples/createSubscriptionWithCloudStorage.js index ffac5731..bc75416c 100644 --- a/samples/createSubscriptionWithCloudStorage.js +++ b/samples/createSubscriptionWithCloudStorage.js @@ -27,7 +27,7 @@ // sample-metadata: // title: Create a Cloud Storage subscription // description: Demonstrates how to create a subscription with Cloud Storage. -// usage: node createSubscriptionWithCloudStorage.js +// usage: node createSubscriptionWithCloudStorage.js // [START pubsub_create_cloud_storage_subscription] /** @@ -46,7 +46,7 @@ const {PubSub} = require('@google-cloud/pubsub'); // Creates a client; cache this for further use const pubSubClient = new PubSub(); -async function createSubscriptionWithCloudStorage( +async function createCloudStorageSubscription( topicName, subscriptionName, bucket, @@ -65,12 +65,12 @@ async function createSubscriptionWithCloudStorage( }, }; - const [sub] = await pubSubClient + await pubSubClient .topic(topicName) .createSubscription(subscriptionName, options); console.log( - `Created subscription ${sub.name} with a cloud storage configuration.` + `Created subscription ${subscriptionName} with a cloud storage configuration.` ); } // [END pubsub_create_cloud_storage_subscription] @@ -83,7 +83,7 @@ function main( filenameSuffix = 'YOUR_FILENAME_SUFFIX', maxDuration = 60 ) { - createSubscriptionWithCloudStorage( + createCloudStorageSubscription( topicName, subscriptionName, bucket, diff --git a/samples/typescript/createSubscriptionWithCloudStorage.ts b/samples/typescript/createSubscriptionWithCloudStorage.ts index 1fca6986..9f6cafce 100644 --- a/samples/typescript/createSubscriptionWithCloudStorage.ts +++ b/samples/typescript/createSubscriptionWithCloudStorage.ts @@ -23,7 +23,7 @@ // sample-metadata: // title: Create a Cloud Storage subscription // description: Demonstrates how to create a subscription with Cloud Storage. -// usage: node createSubscriptionWithCloudStorage.js +// usage: node createSubscriptionWithCloudStorage.js // [START pubsub_create_cloud_storage_subscription] /** @@ -42,7 +42,7 @@ import {CreateSubscriptionOptions, PubSub} from '@google-cloud/pubsub'; // Creates a client; cache this for further use const pubSubClient = new PubSub(); -async function createSubscriptionWithCloudStorage( +async function createCloudStorageSubscription( topicName: string, subscriptionName: string, bucket: string, @@ -61,12 +61,12 @@ async function createSubscriptionWithCloudStorage( }, }; - const [sub] = await pubSubClient + await pubSubClient .topic(topicName) .createSubscription(subscriptionName, options); console.log( - `Created subscription ${sub.name} with a cloud storage configuration.` + `Created subscription ${subscriptionName} with a cloud storage configuration.` ); } // [END pubsub_create_cloud_storage_subscription] @@ -79,7 +79,7 @@ function main( filenameSuffix = 'YOUR_FILENAME_SUFFIX', maxDuration = 60 ) { - createSubscriptionWithCloudStorage( + createCloudStorageSubscription( topicName, subscriptionName, bucket, From 1f70865c4bdc59a98335a351d7523e032f2d3b66 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 5 Jul 2024 18:07:05 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- samples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/README.md b/samples/README.md index 00a7dc8b..f4f59a37 100644 --- a/samples/README.md +++ b/samples/README.md @@ -265,7 +265,7 @@ View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/sam __Usage:__ -`node createSubscriptionWithCloudStorage.js ` +`node createSubscriptionWithCloudStorage.js ` -----