kbendick commented on code in PR #4495:
URL: https://github.com/apache/iceberg/pull/4495#discussion_r842278150


##########
core/src/main/java/org/apache/iceberg/rest/RESTCatalog.java:
##########
@@ -69,18 +75,66 @@
   private Object conf = null;
   private FileIO io = null;
 
+  public RESTCatalog() {
+    this(new HTTPClientFactory());
+  }
+
   RESTCatalog(Function<Map<String, String>, RESTClient> clientBuilder) {
     this.clientBuilder = clientBuilder;
   }
 
   @Override
   public void initialize(String name, Map<String, String> props) {
+    Map<String, String> mergedProps = fetchAndMergeWithServerConfig(props);
+    initializeInternal(name, mergedProps);
+  }
+
+  /**
+   * Performs the normal initialization steps after calling the config route 
and merging the initial
+   * configuration with any configuration provided by the server.
+   * <p>
+   * See {@link RESTCatalogConfigResponse} for details on merging the initial 
client and server configuration.
+   *
+   * @param name  Name of this RESTCatalog
+   * @param props Properties to use, merged with any server-provided 
configuration.
+   */
+  @VisibleForTesting
+  void initializeInternal(String name, Map<String, String> props) {
     this.client = clientBuilder.apply(props);
-    this.catalogName = name;
     this.properties = ImmutableMap.copyOf(props);
-    this.paths = ResourcePaths.forCatalogProperties(props);
-    String ioImpl = props.get(CatalogProperties.FILE_IO_IMPL);
-    this.io = CatalogUtil.loadFileIO(ioImpl != null ? ioImpl : 
ResolvingFileIO.class.getName(), props, conf);
+    this.catalogName = name;
+    this.paths = ResourcePaths.forCatalogProperties(properties);
+    String ioImpl = properties.get(CatalogProperties.FILE_IO_IMPL);
+    this.io = CatalogUtil.loadFileIO(ioImpl != null ? ioImpl : 
ResolvingFileIO.class.getName(), properties, conf);
+  }
+
+  @VisibleForTesting
+  Map<String, String> fetchAndMergeWithServerConfig(Map<String, String> 
initialProps) {
+    Preconditions.checkArgument(initialProps != null, "Invalid initial 
configuration: null");
+    
Preconditions.checkArgument(initialProps.containsKey(CatalogProperties.URI), 
"REST Catalog server URI is required");
+    
Preconditions.checkArgument(initialProps.containsKey(RESTCatalogProperties.AUTH_TOKEN),
+        "Invalid http client configuration. Missing authentication token");
+
+    String baseURI = initialProps.get(CatalogProperties.URI).trim();
+
+    HTTPClient singleUseClient = HTTPClient.builder()
+        .uri(baseURI)
+        .mapper(RESTObjectMapper.mapper())
+        
.withBearerAuth(initialProps.get(RESTCatalogProperties.AUTH_TOKEN).trim())
+        .build();

Review Comment:
   Yeah. I noticed that after posting it. Originally what I was working with 
for the `HTTPClientFactory` had some stuff that made it not possible to share 
the code. But that's been fixed so things have been deduplicated!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to