Skip to content

Commit

Permalink
Use OAuth2 credential in Iceberg Polaris test
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Aug 14, 2024
1 parent e0a509d commit 386b8ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public static void main(String[] args)
.addIcebergProperty("iceberg.rest-catalog.uri", polarisCatalog.restUri() + "/api/catalog")
.addIcebergProperty("iceberg.rest-catalog.warehouse", TestingPolarisCatalog.WAREHOUSE)
.addIcebergProperty("iceberg.rest-catalog.security", "OAUTH2")
.addIcebergProperty("iceberg.rest-catalog.oauth2.token", polarisCatalog.oauth2Token())
.addIcebergProperty("iceberg.rest-catalog.oauth2.credential", polarisCatalog.oauth2Credentials())
.addIcebergProperty("iceberg.rest-catalog.oauth2.scope", "PRINCIPAL_ROLE:ALL")
.setInitialTables(TpchTable.getTables())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected QueryRunner createQueryRunner()
.addIcebergProperty("iceberg.rest-catalog.uri", polarisCatalog.restUri() + "/api/catalog")
.addIcebergProperty("iceberg.rest-catalog.warehouse", TestingPolarisCatalog.WAREHOUSE)
.addIcebergProperty("iceberg.rest-catalog.security", "OAUTH2")
.addIcebergProperty("iceberg.rest-catalog.oauth2.token", polarisCatalog.oauth2Token())
.addIcebergProperty("iceberg.rest-catalog.oauth2.credential", polarisCatalog.oauth2Credentials())
.addIcebergProperty("iceberg.rest-catalog.oauth2.scope", "PRINCIPAL_ROLE:ALL")
.setInitialTables(REQUIRED_TPCH_TABLES)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public final class TestingPolarisCatalog
{
public static final String WAREHOUSE = "polaris";
private static final int POLARIS_PORT = 8181;
private static final Pattern PATTERN = Pattern.compile("realm: default-realm root principal credentials: [a-f0-9]+:(?<secret>[a-f0-9]+)");
private static final Pattern PATTERN = Pattern.compile("realm: default-realm root principal credentials: (?<id>[a-f0-9]+):(?<secret>[a-f0-9]+)");

private static final HttpClient HTTP_CLIENT = new JettyHttpClient();

private final GenericContainer<?> polarisCatalog;
private final String clientId;
private final String clientSecret;
private final String warehouseLocation;

Expand All @@ -58,11 +59,21 @@ public TestingPolarisCatalog(String warehouseLocation)
polarisCatalog.waitingFor(new LogMessageWaitStrategy().withRegEx(".*o.eclipse.jetty.server.Server: Started.*"));
polarisCatalog.start();

clientId = findClientId();
clientSecret = findClientSecret();
createCatalog();
grantPrivilege();
}

private String findClientId()
{
return Stream.of(polarisCatalog.getLogs().split("\n"))
.map(PATTERN::matcher)
.filter(Matcher::find)
.map(matcher -> matcher.group("id"))
.collect(onlyElement());
}

private String findClientSecret()
{
return Stream.of(polarisCatalog.getLogs().split("\n"))
Expand Down Expand Up @@ -124,6 +135,11 @@ public String oauth2Token()
return "principal:root;password:%s;realm:default-realm;role:ALL".formatted(clientSecret);
}

public String oauth2Credentials()
{
return "%s:%s".formatted(clientId, clientSecret);
}

@Override
public void close()
{
Expand Down

0 comments on commit 386b8ed

Please sign in to comment.