Skip to content

Commit 266ccec

Browse files
Add Iceberg REST auth server configuration property
Add comment and source Add test
1 parent 83cb0f6 commit 266ccec

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

presto-docs/src/main/sphinx/connector/iceberg.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ Property Name Description
210210
Available values are ``NONE`` or ``OAUTH2`` (default: ``NONE``).
211211
``OAUTH2`` requires either a credential or token.
212212

213+
``iceberg.rest.auth.oauth2.uri`` OAUTH2 server endpoint URI.
214+
Example: ``https://localhost:9191``
215+
213216
``iceberg.rest.auth.oauth2.credential`` The credential to use for OAUTH2 authentication.
214217
Example: ``key:secret``
215218

presto-iceberg/src/main/java/com/facebook/presto/iceberg/rest/IcebergRestCatalogFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static java.util.Objects.requireNonNull;
3636
import static org.apache.iceberg.CatalogProperties.URI;
3737
import static org.apache.iceberg.rest.auth.OAuth2Properties.CREDENTIAL;
38+
import static org.apache.iceberg.rest.auth.OAuth2Properties.OAUTH2_SERVER_URI;
3839
import static org.apache.iceberg.rest.auth.OAuth2Properties.TOKEN;
3940

4041
public class IcebergRestCatalogFactory
@@ -67,6 +68,11 @@ protected Map<String, String> getCatalogProperties(ConnectorSession session)
6768

6869
catalogConfig.getAuthenticationType().ifPresent(type -> {
6970
if (type == OAUTH2) {
71+
// The oauth2/tokens endpoint of the REST catalog spec has been deprecated and will
72+
// be removed in Iceberg 2.0 (https://github.com/apache/iceberg/pull/10603)
73+
// TODO auth server URI will eventually need to be made a required property
74+
catalogConfig.getAuthenticationServerUri().ifPresent(authServerUri -> properties.put(OAUTH2_SERVER_URI, authServerUri));
75+
7076
if (!catalogConfig.credentialOrTokenExists()) {
7177
throw new IllegalStateException("iceberg.rest.auth.oauth2 requires either a credential or a token");
7278
}

presto-iceberg/src/main/java/com/facebook/presto/iceberg/rest/IcebergRestConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class IcebergRestConfig
2525
private String serverUri;
2626
private SessionType sessionType;
2727
private AuthenticationType authenticationType;
28+
private String authenticationServerUri;
2829
private String credential;
2930
private String token;
3031

@@ -68,6 +69,19 @@ public IcebergRestConfig setAuthenticationType(AuthenticationType authentication
6869
return this;
6970
}
7071

72+
public Optional<String> getAuthenticationServerUri()
73+
{
74+
return Optional.ofNullable(authenticationServerUri);
75+
}
76+
77+
@Config("iceberg.rest.auth.oauth2.uri")
78+
@ConfigDescription("The URI to connect to the OAUTH2 server")
79+
public IcebergRestConfig setAuthenticationServerUri(String authServerUri)
80+
{
81+
this.authenticationServerUri = authServerUri;
82+
return this;
83+
}
84+
7185
public Optional<String> getCredential()
7286
{
7387
return Optional.ofNullable(credential);

presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/TestIcebergRestConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void testDefaults()
3232
assertRecordedDefaults(ConfigAssertions.recordDefaults(IcebergRestConfig.class)
3333
.setServerUri(null)
3434
.setAuthenticationType(null)
35+
.setAuthenticationServerUri(null)
3536
.setCredential(null)
3637
.setToken(null)
3738
.setSessionType(null));
@@ -43,6 +44,7 @@ public void testExplicitPropertyMappings()
4344
Map<String, String> properties = ImmutableMap.<String, String>builder()
4445
.put("iceberg.rest.uri", "http://localhost:xxx")
4546
.put("iceberg.rest.auth.type", "OAUTH2")
47+
.put("iceberg.rest.auth.oauth2.uri", "http://localhost:yyy")
4648
.put("iceberg.rest.auth.oauth2.credential", "key:secret")
4749
.put("iceberg.rest.auth.oauth2.token", "SXVLUXUhIExFQ0tFUiEK")
4850
.put("iceberg.rest.session.type", "USER")
@@ -51,6 +53,7 @@ public void testExplicitPropertyMappings()
5153
IcebergRestConfig expected = new IcebergRestConfig()
5254
.setServerUri("http://localhost:xxx")
5355
.setAuthenticationType(OAUTH2)
56+
.setAuthenticationServerUri("http://localhost:yyy")
5457
.setCredential("key:secret")
5558
.setToken("SXVLUXUhIExFQ0tFUiEK")
5659
.setSessionType(USER);

presto-iceberg/src/test/java/com/facebook/presto/iceberg/rest/TestIcebergSmokeRest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.facebook.presto.testing.QueryRunner;
3030
import com.google.common.collect.ImmutableMap;
3131
import org.apache.iceberg.Table;
32+
import org.apache.iceberg.rest.RESTCatalog;
3233
import org.assertj.core.util.Files;
3334
import org.testng.annotations.AfterClass;
3435
import org.testng.annotations.BeforeClass;
@@ -42,12 +43,15 @@
4243
import static com.facebook.presto.iceberg.FileFormat.PARQUET;
4344
import static com.facebook.presto.iceberg.IcebergQueryRunner.ICEBERG_CATALOG;
4445
import static com.facebook.presto.iceberg.IcebergUtil.getNativeIcebergTable;
46+
import static com.facebook.presto.iceberg.rest.AuthenticationType.OAUTH2;
4547
import static com.facebook.presto.iceberg.rest.IcebergRestTestUtil.getRestServer;
4648
import static com.facebook.presto.iceberg.rest.IcebergRestTestUtil.restConnectorProperties;
4749
import static com.google.common.io.MoreFiles.deleteRecursively;
4850
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
4951
import static java.lang.String.format;
52+
import static org.apache.iceberg.rest.auth.OAuth2Properties.OAUTH2_SERVER_URI;
5053
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54+
import static org.testng.Assert.assertEquals;
5155

5256
@Test
5357
public class TestIcebergSmokeRest
@@ -106,12 +110,11 @@ protected QueryRunner createQueryRunner()
106110
Optional.of(warehouseLocation.toPath()));
107111
}
108112

109-
protected IcebergNativeCatalogFactory getCatalogFactory()
113+
protected IcebergNativeCatalogFactory getCatalogFactory(IcebergRestConfig restConfig)
110114
{
111115
IcebergConfig icebergConfig = new IcebergConfig()
112116
.setCatalogType(REST)
113-
.setCatalogWarehouse(warehouseLocation.getAbsolutePath().toString());
114-
IcebergRestConfig restConfig = new IcebergRestConfig().setServerUri(serverUri);
117+
.setCatalogWarehouse(warehouseLocation.getAbsolutePath());
115118

116119
return new IcebergRestCatalogFactory(
117120
icebergConfig,
@@ -125,7 +128,8 @@ protected IcebergNativeCatalogFactory getCatalogFactory()
125128
@Override
126129
protected Table getIcebergTable(ConnectorSession session, String schema, String tableName)
127130
{
128-
return getNativeIcebergTable(getCatalogFactory(),
131+
IcebergRestConfig restConfig = new IcebergRestConfig().setServerUri(serverUri);
132+
return getNativeIcebergTable(getCatalogFactory(restConfig),
129133
session,
130134
SchemaTableName.valueOf(schema + "." + tableName));
131135
}
@@ -192,4 +196,20 @@ public void testMetadataDeleteOnTableWithUnsupportedSpecsWhoseDataAllDeleted(Str
192196
super.testMetadataDeleteOnTableWithUnsupportedSpecsWhoseDataAllDeleted(version, mode);
193197
}
194198
}
199+
200+
@Test
201+
public void testSetOauth2ServerUriPropertyI()
202+
{
203+
String authEndpoint = "http://localhost:8888";
204+
IcebergRestConfig restConfig = new IcebergRestConfig()
205+
.setServerUri(serverUri)
206+
.setAuthenticationType(OAUTH2)
207+
.setToken("SXVLUXUhIExFQ0tFUiEK")
208+
.setAuthenticationServerUri(authEndpoint);
209+
210+
IcebergRestCatalogFactory catalogFactory = (IcebergRestCatalogFactory) getCatalogFactory(restConfig);
211+
RESTCatalog catalog = (RESTCatalog) catalogFactory.getCatalog(getSession().toConnectorSession());
212+
213+
assertEquals(catalog.properties().get(OAUTH2_SERVER_URI), authEndpoint);
214+
}
195215
}

0 commit comments

Comments
 (0)