Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pubsub): enable project autodetection and detect empty project #8168

Merged
merged 4 commits into from
Jun 27, 2023

Conversation

hongalex
Copy link
Member

Allows autodetection of project ID when the sentinel value (DetectProjectID) is passed in to pubsub.NewClient. This uses the detect, similar to BigQuery in #4312. Similar to Firestore in #4299, empty project IDs will now return an error.

Also exposes a new method in pubsub client client.Project() which returns the project ID.

Retrieving information about the topic's (and subscription) project ID can be done by topic.Config, followed by calling config.String().

Addresses pubsub portion in #1294

Fixes #3828

@hongalex hongalex requested review from a team and shollyman as code owners June 23, 2023 01:41
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: pubsub Issues related to the Pub/Sub API. labels Jun 23, 2023
@hongalex hongalex enabled auto-merge (squash) June 27, 2023 16:28
@hongalex hongalex merged commit c7e05d8 into googleapis:main Jun 27, 2023
@hongalex hongalex deleted the feat-pubsub-autodetect branch June 27, 2023 17:25
// NewClient creates a new PubSub client. It uses a default configuration.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (c *Client, err error) {
return NewClientWithConfig(ctx, projectID, nil, opts...)
}

// NewClientWithConfig creates a new PubSub client.
func NewClientWithConfig(ctx context.Context, projectID string, config *ClientConfig, opts ...option.ClientOption) (c *Client, err error) {
if projectID == "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hongalex doesn't having this check early on break the opts.WithoutAuthentication case since it now requires you to pass a dummy projectID to instantiate the clients.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change that warrants a major version bump instead of a minor bump?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this may be backwards incompatible, but falls under the realm of a bug fix and doesn't warrant a major version bump. Passing in an empty string to the client is unsupported behavior and should have resulted in an error, even when using unauthenticated. The project string is used to construct paths like "projects/my-project/topics/my-topic" and creating resources like "projects//topics/my-topic" is undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubsub: consider returning non-nil error from NewClient when projectID is invalid
4 participants