-
Notifications
You must be signed in to change notification settings - Fork 51
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: Introduce API Key support into ClientBuilderBase #732
Conversation
googleapis/google-cloud-dotnet#11217 shows how this would be used. |
/// <remarks> | ||
/// This is protected as not all APIs support API keys. APIs which support API keys | ||
/// should declare a new public property (also called ApiKey) in the concrete client builder class, | ||
/// and ensure they call <see cref="GetEffectiveSettings{T}(T)"/> to potentially specify the API key header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, why can't we add a default implementation for Build and BuildAsync in here (ClientBuilderBase), instead of generating them. If we do that, then we can call GetEffectiveSettings here in the way we need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be able to call a concrete constructor in the client type, and use a settings type which is concrete (and which we're non-generic in).
But we may be able to reduce it further (in the next major version of GAX, of course).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, we'd need a new majot version for that, and not really much we can do otherwise. Looks good.
2adacca
to
f1b9b25
Compare
A different alternative to consider:
Generating actual implementation feels nasty, but so does the |
/// <c>GetEffectiveSettings(Settings?.Clone())</c>.</remarks> | ||
/// <typeparam name="T">The concrete settings type, derived from <see cref="ServiceSettingsBase"/>, with a | ||
/// parameterless constructor that can be used to construct a new default instance.</typeparam> | ||
/// <param name="settings">A clone of the existing settings specified in the concrete builder type. May be null.</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about this from the perspective of creating clones unnecessarily... and I'm now not that bothered. It's only once per client creation and it's only if the user has specified settings explicitly (which will be pretty rare).
I've continued thinking about this, and while the whole "clone the settings" part is a bit annoying, I think it's okay for now. Maybe in the next GAX major version we should make the builder generic in the settings type as well, which would allow us to generate less per-API code, I suspect. Will note that, but for now I'm happy to go with this, and change the generator to unconditionally generate the call to Thoughts? |
I've been thinking about this as well and I haven't come up with anything that's clean. A tweak to your alternative solution might be to:
It's still generating implementation but in a place where we are already generating related implementation, for instance XYZClientImpl's constructor calculates effective settings in case the passed settings are null, so, it's just a little bit more of that. Otherwise, this is fine as well. I do +1 strongly making the client builder base generic on the settings type on the next major version. |
I've been wanting to avoid adding a new Create overload - otherwise I completely agree that would be a good call. No huge urgency for this, so I'll keep pondering options. |
It's been a couple of months now, and I haven't figured out anything better than this. Shall we just go with this? I can't remember offhand how easy it is to write tests for this sort of thing, but I can definitely look into it. |
Yep, I'm fine with this approach, I don't think we can do much better. |
f1b9b25
to
065359e
Compare
The intention is to make it easy for APIs which *do* support API keys to expose that, without providing misleading properties to other client builders.
065359e
to
5ccab74
Compare
This is now ready for review and merging. There are tests for GetEffectiveSettings - a lot of the rest is hard to test due to ADC. |
This will allow API key support to be introduced through partial classes. Requires googleapis/gax-dotnet#732 to be merged and released.
This will allow API key support to be introduced through partial classes. Requires googleapis/gax-dotnet#732 to be merged and released.
This will allow API key support to be introduced through partial classes. Requires googleapis/gax-dotnet#732 to be merged and released.
This will allow API key support to be introduced through partial classes. Requires googleapis/gax-dotnet#732 to be merged and released.
The intention is to make it easy for APIs which do support API keys to expose that, without providing misleading properties to other client builders.