Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions databricks-sdk-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,18 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Google Auto Value -->
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.10.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>1.10.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,44 +18,19 @@ public class DataPlaneTokenSource {
private final TokenSource cpTokenSource;
private final String host;
private final ConcurrentHashMap<TokenSourceKey, EndpointTokenSource> 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);
}
}

Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
<configuration>
<source>8</source>
<target>8</target>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.10.4</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
Loading