Skip to content

Commit

Permalink
[core] Add basic implementation to support REST Catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Nov 20, 2024
1 parent 312d238 commit 63a8f41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public RESTCatalog(Options options) {
this.catalogAuth =
AuthSession.fromAccessToken(
client,
null,
token,
tokenRefreshExecutor(),
new HashMap<>(),
new AuthConfig(token, keepTokenRefreshed, null),
null);
Expand Down Expand Up @@ -181,11 +180,10 @@ public boolean allowUpperCase() {
public void close() throws Exception {}

private Map<String, String> headers() {
catalogAuth.refresh(client);
return catalogAuth.getHeaders();
}

private ScheduledExecutorService tokenRefreshExecutor(String catalogName) {
private ScheduledExecutorService tokenRefreshExecutor() {
if (!keepTokenRefreshed) {
return null;
}
Expand All @@ -198,7 +196,7 @@ private ScheduledExecutorService tokenRefreshExecutor(String catalogName) {
1,
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat(catalogName + "-token-refresh" + "-%d")
.setNameFormat("rest-token-refresh-%d")
.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public AuthSession(Map<String, String> headers, AuthConfig config) {
public static AuthSession fromAccessToken(
RESTClient client,
ScheduledExecutorService executor,
String token,
Map<String, String> headers,
AuthConfig config,
Long defaultExpiresAtMillis) {
Expand Down Expand Up @@ -102,6 +101,7 @@ private static void scheduleTokenRefresh(
() -> {
long refreshStartTime = System.currentTimeMillis();
Pair<Integer, TimeUnit> expiration = session.refresh(client);
// todo: need define retry times
if (expiration != null) {
scheduleTokenRefresh(
client,
Expand All @@ -115,7 +115,7 @@ private static void scheduleTokenRefresh(
TimeUnit.MILLISECONDS);
}

public Pair<Integer, TimeUnit> refresh(RESTClient client) {
private Pair<Integer, TimeUnit> refresh(RESTClient client) {
if (config.getToken() != null && config.getKeepRefreshed()) {
long startTimeMillis = System.currentTimeMillis();
OAuthTokenResponse response = refreshExpiredToken(client);
Expand All @@ -140,7 +140,7 @@ public Pair<Integer, TimeUnit> refresh(RESTClient client) {
}

private OAuthTokenResponse refreshExpiredToken(RESTClient client) {
// todo: update the token
// todo: get token from server
OAuthTokenResponse response = new OAuthTokenResponse("mock", 3600);
return response;
}
Expand Down

0 comments on commit 63a8f41

Please sign in to comment.