|
27 | 27 | import org.apache.iceberg.rest.ErrorHandlers; |
28 | 28 | import org.apache.iceberg.rest.HTTPClient; |
29 | 29 | import org.apache.iceberg.rest.RESTClient; |
| 30 | +import org.apache.iceberg.rest.RESTUtil; |
| 31 | +import org.apache.iceberg.rest.ResourcePaths; |
30 | 32 | import org.apache.iceberg.rest.auth.OAuth2Properties; |
31 | 33 | import org.apache.iceberg.rest.auth.OAuth2Util; |
32 | 34 | import org.apache.iceberg.rest.credentials.Credential; |
33 | 35 | import org.apache.iceberg.rest.responses.LoadCredentialsResponse; |
| 36 | +import org.apache.iceberg.rest.responses.OAuthTokenResponse; |
34 | 37 | import software.amazon.awssdk.auth.credentials.AwsCredentials; |
35 | 38 | import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; |
36 | 39 | import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; |
@@ -83,12 +86,27 @@ private RESTClient httpClient() { |
83 | 86 | } |
84 | 87 |
|
85 | 88 | private LoadCredentialsResponse fetchCredentials() { |
| 89 | + String initToken = properties.get(OAuth2Properties.TOKEN); |
| 90 | + String credential = properties.get(OAuth2Properties.CREDENTIAL); |
| 91 | + Map<String, String> authHeaders = RESTUtil.merge(properties, OAuth2Util.authHeaders(initToken)); |
| 92 | + if (credential != null && !credential.isEmpty()) { |
| 93 | + OAuthTokenResponse authResponse = |
| 94 | + OAuth2Util.fetchToken( |
| 95 | + httpClient(), |
| 96 | + authHeaders, |
| 97 | + credential, |
| 98 | + properties.getOrDefault(OAuth2Properties.SCOPE, OAuth2Properties.CATALOG_SCOPE), |
| 99 | + properties.getOrDefault(OAuth2Properties.OAUTH2_SERVER_URI, ResourcePaths.tokens()), |
| 100 | + OAuth2Util.buildOptionalParam(properties)); |
| 101 | + authHeaders = RESTUtil.merge(authHeaders, OAuth2Util.authHeaders(authResponse.token())); |
| 102 | + } |
| 103 | + |
86 | 104 | return httpClient() |
87 | 105 | .get( |
88 | 106 | properties.get(URI), |
89 | 107 | null, |
90 | 108 | LoadCredentialsResponse.class, |
91 | | - OAuth2Util.authHeaders(properties.get(OAuth2Properties.TOKEN)), |
| 109 | + authHeaders, |
92 | 110 | ErrorHandlers.defaultErrorHandler()); |
93 | 111 | } |
94 | 112 |
|
|
0 commit comments