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
8 checks passed
@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.

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
3 participants