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