|
38 | 38 | import java.util.Set;
|
39 | 39 | import java.util.function.Function;
|
40 | 40 | import org.apache.iceberg.MetadataUpdate;
|
| 41 | +import org.apache.iceberg.aws.AwsClientProperties; |
41 | 42 | import org.apache.iceberg.catalog.Namespace;
|
42 | 43 | import org.apache.iceberg.catalog.TableIdentifier;
|
43 | 44 | import org.apache.iceberg.exceptions.BadRequestException;
|
|
70 | 71 | import org.apache.polaris.core.persistence.resolver.Resolver;
|
71 | 72 | import org.apache.polaris.core.persistence.resolver.ResolverStatus;
|
72 | 73 | import org.apache.polaris.core.rest.PolarisEndpoints;
|
| 74 | +import org.apache.polaris.core.rest.PolarisResourcePaths; |
73 | 75 | import org.apache.polaris.core.secrets.UserSecretsManager;
|
| 76 | +import org.apache.polaris.core.storage.StorageAccessProperty; |
74 | 77 | import org.apache.polaris.service.catalog.AccessDelegationMode;
|
75 | 78 | import org.apache.polaris.service.catalog.CatalogPrefixParser;
|
76 | 79 | import org.apache.polaris.service.catalog.api.IcebergRestCatalogApiService;
|
@@ -419,16 +422,45 @@ public Response loadTable(
|
419 | 422 | .loadTableIfStale(tableIdentifier, ifNoneMatch, snapshots)
|
420 | 423 | .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_MODIFIED));
|
421 | 424 | } else {
|
422 |
| - response = |
| 425 | + LoadTableResponse originalResponse = |
423 | 426 | catalog
|
424 | 427 | .loadTableWithAccessDelegationIfStale(tableIdentifier, ifNoneMatch, snapshots)
|
425 | 428 | .orElseThrow(() -> new WebApplicationException(Response.Status.NOT_MODIFIED));
|
| 429 | + |
| 430 | + if (delegationModes.contains(VENDED_CREDENTIALS)) { |
| 431 | + response = |
| 432 | + injectRefreshVendedCredentialProperties( |
| 433 | + originalResponse, |
| 434 | + new PolarisResourcePaths(prefix).credentialsPath(tableIdentifier)); |
| 435 | + } else { |
| 436 | + response = originalResponse; |
| 437 | + } |
426 | 438 | }
|
427 | 439 |
|
428 | 440 | return tryInsertETagHeader(Response.ok(response), response, namespace, table).build();
|
429 | 441 | });
|
430 | 442 | }
|
431 | 443 |
|
| 444 | + private LoadTableResponse injectRefreshVendedCredentialProperties( |
| 445 | + LoadTableResponse originalResponse, String credentialsEndpoint) { |
| 446 | + LoadTableResponse.Builder loadResponseBuilder = |
| 447 | + LoadTableResponse.builder().withTableMetadata(originalResponse.tableMetadata()); |
| 448 | + loadResponseBuilder.addAllConfig(originalResponse.config()); |
| 449 | + loadResponseBuilder.addAllCredentials(originalResponse.credentials()); |
| 450 | + loadResponseBuilder.addConfig( |
| 451 | + AwsClientProperties.REFRESH_CREDENTIALS_ENDPOINT, credentialsEndpoint); |
| 452 | + // Only enable credential refresh for currently supported credential types |
| 453 | + if (originalResponse.credentials().stream() |
| 454 | + .anyMatch( |
| 455 | + credential -> |
| 456 | + credential |
| 457 | + .config() |
| 458 | + .containsKey(StorageAccessProperty.AWS_SECRET_KEY.getPropertyName()))) { |
| 459 | + loadResponseBuilder.addConfig(AwsClientProperties.REFRESH_CREDENTIALS_ENABLED, "true"); |
| 460 | + } |
| 461 | + return loadResponseBuilder.build(); |
| 462 | + } |
| 463 | + |
432 | 464 | @Override
|
433 | 465 | public Response tableExists(
|
434 | 466 | String prefix,
|
|
0 commit comments