oscerd commented on code in PR #28217:
URL: https://github.com/apache/camel/pull/28217#discussion_r4335262975
##########
components/camel-google/camel-google-mail/src/main/java/org/apache/camel/component/google/mail/stream/GoogleMailStreamComponent.java:
##########
@@ -49,20 +51,35 @@ public GoogleMailStreamComponent(CamelContext context) {
this.configuration = new GoogleMailStreamConfiguration();
}
- public Gmail getClient(GoogleMailStreamConfiguration
googleMailConfiguration) {
- if (client == null) {
- if (googleMailConfiguration.getClientSecret() != null) {
- client =
getClientFactory().makeClient(googleMailConfiguration.getClientId(),
- googleMailConfiguration.getClientSecret(),
googleMailConfiguration.getScopesAsList(),
- googleMailConfiguration.getApplicationName(),
googleMailConfiguration.getRefreshToken(),
- googleMailConfiguration.getAccessToken());
- } else if (googleMailConfiguration.getServiceAccountKey() != null)
{
- client = getClientFactory().makeClient(getCamelContext(),
googleMailConfiguration.getServiceAccountKey(),
- googleMailConfiguration.getScopesAsList(),
googleMailConfiguration.getApplicationName(),
- googleMailConfiguration.getDelegate());
- }
+ /**
+ * Gets the client for the given configuration. One client is kept per
distinct set of the options the client is
+ * created from, so endpoints with the same options share a client and
endpoints with different options get their
+ * own.
+ */
+ public Gmail getClient(GoogleMailStreamConfiguration config) {
+ return clients.computeIfAbsent(clientKey(config), key ->
createClient(config));
+ }
+
+ private Gmail createClient(GoogleMailStreamConfiguration config) {
+ if (config.getClientSecret() != null) {
+ return getClientFactory().makeClient(config.getClientId(),
+ config.getClientSecret(), config.getScopesAsList(),
+ config.getApplicationName(), config.getRefreshToken(),
+ config.getAccessToken());
+ } else if (config.getServiceAccountKey() != null) {
+ return getClientFactory().makeClient(getCamelContext(),
config.getServiceAccountKey(),
+ config.getScopesAsList(), config.getApplicationName(),
Review Comment:
Added in f9d7e3270dc9: `shouldFailWithoutCredentials` in
`GoogleMailStreamClientPerEndpointOptionsTest` resolves an endpoint without
`clientSecret` or `serviceAccountKey` and asserts that `getClient()` throws
`IllegalArgumentException` naming `serviceAccountKey`.
_Claude Code on behalf of oscerd_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]