diff --git a/databricks-sdk-java/pom.xml b/databricks-sdk-java/pom.xml index c5a2e8c32..120370887 100644 --- a/databricks-sdk-java/pom.xml +++ b/databricks-sdk-java/pom.xml @@ -103,5 +103,18 @@ jackson-datatype-jsr310 ${jackson.version} + + + com.google.auto.value + auto-value + 1.10.4 + provided + + + com.google.auto.value + auto-value-annotations + 1.10.4 + provided + diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java index 8d48c2dff..01bd05d2c 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DataPlaneTokenSource.java @@ -1,6 +1,7 @@ package com.databricks.sdk.core.oauth; import com.databricks.sdk.core.http.HttpClient; +import com.google.auto.value.AutoValue; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -17,44 +18,19 @@ public class DataPlaneTokenSource { private final TokenSource cpTokenSource; private final String host; private final ConcurrentHashMap sourcesCache; + /** * Caching key for {@link EndpointTokenSource}, based on endpoint and authorization details. This * is a value object that uniquely identifies a token source configuration. */ - private static final class TokenSourceKey { - /** The target service endpoint URL. */ - private final String endpoint; - - /** Specific authorization details for the endpoint. */ - private final String authDetails; + @AutoValue + abstract static class TokenSourceKey { + abstract String endpoint(); - /** - * Constructs a TokenSourceKey. - * - * @param endpoint The target service endpoint URL. - * @param authDetails Specific authorization details. - */ - public TokenSourceKey(String endpoint, String authDetails) { - this.endpoint = endpoint; - this.authDetails = authDetails; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TokenSourceKey that = (TokenSourceKey) o; - return Objects.equals(endpoint, that.endpoint) - && Objects.equals(authDetails, that.authDetails); - } + abstract String authDetails(); - @Override - public int hashCode() { - return Objects.hash(endpoint, authDetails); + static TokenSourceKey create(String endpoint, String authDetails) { + return new AutoValue_DataPlaneTokenSource_TokenSourceKey(endpoint, authDetails); } } @@ -101,14 +77,14 @@ public Token getToken(String endpoint, String authDetails) { throw new IllegalArgumentException("Authorization details cannot be empty"); } - TokenSourceKey key = new TokenSourceKey(endpoint, authDetails); + TokenSourceKey key = TokenSourceKey.create(endpoint, authDetails); EndpointTokenSource specificSource = sourcesCache.computeIfAbsent( key, k -> new EndpointTokenSource( - this.cpTokenSource, k.authDetails, this.httpClient, this.host)); + this.cpTokenSource, k.authDetails(), this.httpClient, this.host)); return specificSource.getToken(); } diff --git a/pom.xml b/pom.xml index afba640fb..d8f65b585 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,13 @@ 8 8 + + + com.google.auto.value + auto-value + 1.10.4 + +