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