Skip to content

Conversation

kl177
Copy link

@kl177 kl177 commented May 15, 2020

Fixes #189

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Thanks @slirx for the PR. We do not want to introduce an env variable for this purpose. Ideally we should be able to use the endpoint set via options.WithEndpoint(). This is already returned by the call to transport.NewHTTPClient(), and is currently ignored.

@kl177
Copy link
Author

kl177 commented May 18, 2020

I've updated it to be able to use the endpoint set via options.WithEndpoint().
I've used internaloption.WithDefaultEndpoint() in order to apply the default endpoint.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Suggested one change. Also require some tests.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Thanks @slirx. LGTM with some minor nits. I'll merge this when those points are addressed.

nil,
option.WithCredentialsFile("testdata/service_account.json"),
option.WithTokenSource(tokenSource),
option.WithEndpoint(ts.URL),
Copy link
Contributor

Choose a reason for hiding this comment

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

Only WithEndpoint() should be sufficient here.

Copy link
Author

Choose a reason for hiding this comment

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

It gives an error only with WithEndpoint():

app, err := NewApp(ctx, nil, option.WithEndpoint(ts.URL))
if err != nil {
    t.Fatal(err)
}

c, err := app.Messaging(ctx)
if c == nil || err != nil {
    t.Fatalf("Messaging() = (%v, %v); want (iid, nil)", c, err)
}
--- FAIL: TestMessagingSendWithCustomEndpoint (0.59s)
    firebase_test.go:390: Messaging() = (<nil>, project ID is required to access Firebase Cloud Messaging client); want (iid, nil)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I suppose the transport still requires some sort of a credential. In that case let's keep option.WithTokenSource(). You definitely don't need WithCredentialsFile() when a TokenSource is explicitly provided.

Copy link
Author

Choose a reason for hiding this comment

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

It seems WithCredentialsFile() is required to provide project id. It gives an error without WithCredentialsFile():

tokenSource := &testTokenSource{AccessToken: "mock-token-from-custom"}
app, err := NewApp(
    ctx,
    nil,
    //option.WithCredentialsFile("testdata/service_account.json"),
    option.WithTokenSource(tokenSource),
    option.WithEndpoint(ts.URL),
)
if err != nil {
    t.Fatal(err)
}

c, err := app.Messaging(ctx)
if c == nil || err != nil {
    t.Fatalf("Messaging() = (%v, %v); want (iid, nil)", c, err)
}
--- FAIL: TestMessagingSendWithCustomEndpoint (0.00s)
    firebase_test.go:390: Messaging() = (<nil>, project ID is required to access Firebase Cloud Messaging client); want (iid, nil)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! :(

@hiranya911 hiranya911 changed the title Add environment variable to override default FCM endpoint fix(fcm): Add environment variable to override default FCM endpoint May 27, 2020
@hiranya911 hiranya911 changed the title fix(fcm): Add environment variable to override default FCM endpoint fix(fcm): Add ability to override default FCM endpoint via ClientOptions May 27, 2020
@hiranya911 hiranya911 changed the base branch from master to dev May 28, 2020 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to set endpoint for messaging
2 participants