dybyte commented on code in PR #9968: URL: https://github.com/apache/seatunnel/pull/9968#discussion_r2495536290
########## seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/RestApiHttpBasicTest.java: ########## @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.rest; + +import org.apache.seatunnel.engine.common.config.SeaTunnelConfig; +import org.apache.seatunnel.engine.common.config.server.HttpConfig; +import org.apache.seatunnel.engine.common.runtime.ExecutionMode; +import org.apache.seatunnel.engine.common.utils.PassiveCompletableFuture; +import org.apache.seatunnel.engine.core.dag.logical.LogicalDag; +import org.apache.seatunnel.engine.core.job.JobImmutableInformation; +import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest; +import org.apache.seatunnel.engine.server.SeaTunnelServer; +import org.apache.seatunnel.engine.server.SeaTunnelServerStarter; +import org.apache.seatunnel.engine.server.TestUtils; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.hazelcast.config.Config; +import com.hazelcast.internal.serialization.Data; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.util.Collections; +import java.util.stream.Collectors; + +/** Test for Rest API with Basic. */ +class RestApiHttpBasicTest extends AbstractSeaTunnelServerTest { + + private static final int HTTP_PORT = 18081; + private static final Long JOB_1 = System.currentTimeMillis() + 1L; + public static final String USER = "admin"; + public static final String PASS = "admin"; + + @BeforeAll + void setUp() { + String name = this.getClass().getName(); + Config hazelcastConfig = Config.loadFromString(getHazelcastConfig()); + hazelcastConfig.setClusterName( + TestUtils.getClusterName("RestApiServletHttpBasicTest_" + name)); + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + seaTunnelConfig.setHazelcastConfig(hazelcastConfig); + seaTunnelConfig.getEngineConfig().setMode(ExecutionMode.LOCAL); + + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnabled(Boolean.TRUE); + httpConfig.setPort(HTTP_PORT); + + httpConfig.setEnableBasicAuth(Boolean.TRUE); + httpConfig.setBasicAuthUsername(USER); + httpConfig.setBasicAuthPassword(PASS); + + instance = SeaTunnelServerStarter.createHazelcastInstance(seaTunnelConfig); + nodeEngine = instance.node.nodeEngine; + server = nodeEngine.getService(SeaTunnelServer.SERVICE_NAME); + LOGGER = nodeEngine.getLogger(AbstractSeaTunnelServerTest.class); + } + + @AfterAll + public void after() { + // Disable basic auth + // Because of the ConfigProvider.locateAndGetSeaTunnelConfig() single-case, + // if you change, other use cases will also change + // managed via org.apache.seatunnel.engine.common.config.YamlSeaTunnelDomConfigProcessor + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnableBasicAuth(Boolean.FALSE); + httpConfig.setBasicAuthUsername(""); + httpConfig.setBasicAuthPassword(""); + } + + @Test + public void testRestApiOverview() throws Exception { + HttpURLConnection conn = null; + try { + java.net.URL url = new java.net.URL("http://localhost:" + HTTP_PORT + "/overview"); + conn = (HttpURLConnection) url.openConnection(); + setBasicAuth(conn); + + Assertions.assertEquals(200, conn.getResponseCode()); + Assertions.assertTrue( + conn.getHeaderFields() + .get("Content-Type") + .toString() + .contains("charset=utf-8")); + } finally { + if (conn != null) { + conn.disconnect(); + } + } + } + + @Test + void testLogRestApiResponseFailure() throws IOException { + startJob(); + HttpURLConnection conn = null; + try { + java.net.URL url = Review Comment: ditto ########## seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/RestApiHttpBasicTest.java: ########## @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.rest; + +import org.apache.seatunnel.engine.common.config.SeaTunnelConfig; +import org.apache.seatunnel.engine.common.config.server.HttpConfig; +import org.apache.seatunnel.engine.common.runtime.ExecutionMode; +import org.apache.seatunnel.engine.common.utils.PassiveCompletableFuture; +import org.apache.seatunnel.engine.core.dag.logical.LogicalDag; +import org.apache.seatunnel.engine.core.job.JobImmutableInformation; +import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest; +import org.apache.seatunnel.engine.server.SeaTunnelServer; +import org.apache.seatunnel.engine.server.SeaTunnelServerStarter; +import org.apache.seatunnel.engine.server.TestUtils; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.hazelcast.config.Config; +import com.hazelcast.internal.serialization.Data; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.util.Collections; +import java.util.stream.Collectors; + +/** Test for Rest API with Basic. */ +class RestApiHttpBasicTest extends AbstractSeaTunnelServerTest { + + private static final int HTTP_PORT = 18081; + private static final Long JOB_1 = System.currentTimeMillis() + 1L; + public static final String USER = "admin"; + public static final String PASS = "admin"; + + @BeforeAll + void setUp() { + String name = this.getClass().getName(); + Config hazelcastConfig = Config.loadFromString(getHazelcastConfig()); + hazelcastConfig.setClusterName( + TestUtils.getClusterName("RestApiServletHttpBasicTest_" + name)); + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + seaTunnelConfig.setHazelcastConfig(hazelcastConfig); + seaTunnelConfig.getEngineConfig().setMode(ExecutionMode.LOCAL); + + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnabled(Boolean.TRUE); + httpConfig.setPort(HTTP_PORT); + + httpConfig.setEnableBasicAuth(Boolean.TRUE); + httpConfig.setBasicAuthUsername(USER); + httpConfig.setBasicAuthPassword(PASS); + + instance = SeaTunnelServerStarter.createHazelcastInstance(seaTunnelConfig); + nodeEngine = instance.node.nodeEngine; + server = nodeEngine.getService(SeaTunnelServer.SERVICE_NAME); + LOGGER = nodeEngine.getLogger(AbstractSeaTunnelServerTest.class); + } + + @AfterAll + public void after() { + // Disable basic auth + // Because of the ConfigProvider.locateAndGetSeaTunnelConfig() single-case, + // if you change, other use cases will also change + // managed via org.apache.seatunnel.engine.common.config.YamlSeaTunnelDomConfigProcessor + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnableBasicAuth(Boolean.FALSE); + httpConfig.setBasicAuthUsername(""); + httpConfig.setBasicAuthPassword(""); + } + + @Test + public void testRestApiOverview() throws Exception { + HttpURLConnection conn = null; + try { + java.net.URL url = new java.net.URL("http://localhost:" + HTTP_PORT + "/overview"); Review Comment: Let's import it. ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java: ########## @@ -47,30 +47,87 @@ public String getLogPath() { } protected String sendGet(String urlString) { + HttpURLConnection connection = null; try { - HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection = (HttpURLConnection) new URL(urlString).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.connect(); + int code = connection.getResponseCode(); if (connection.getResponseCode() == 200) { - try (InputStream is = connection.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; - int len; - while ((len = is.read(buffer)) != -1) { - baos.write(buffer, 0, len); - } - return baos.toString(); - } + return readAll(connection.getInputStream()); } + log.warn("GET {} -> HTTP {}", urlString, code); } catch (IOException e) { - log.error("Send get Fail.{}", ExceptionUtils.getMessage(e)); + log.error("Send GET failed: url={}, err={}", urlString, ExceptionUtils.getMessage(e)); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return null; + } + + /** + * Send GET request with Basic Auth + * + * @param urlString url + * @param user name + * @param pass password + * @return log + */ + protected String sendGet(String urlString, String user, String pass) { + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + + // Basic Auth + if (user != null && pass != null) { + String token = + java.util.Base64.getEncoder() + .encodeToString( + (user + ":" + pass) + .getBytes(java.nio.charset.StandardCharsets.UTF_8)); + connection.setRequestProperty("Authorization", "Basic " + token); Review Comment: Let's reuse https://github.com/apache/seatunnel/blob/5681fe3bb7c7c5a99a275e2139e4d06b2d780b7b/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/filter/BasicAuthFilter.java#L43-L44 ########## seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/rest/RestApiHttpBasicTest.java: ########## @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.engine.server.rest; + +import org.apache.seatunnel.engine.common.config.SeaTunnelConfig; +import org.apache.seatunnel.engine.common.config.server.HttpConfig; +import org.apache.seatunnel.engine.common.runtime.ExecutionMode; +import org.apache.seatunnel.engine.common.utils.PassiveCompletableFuture; +import org.apache.seatunnel.engine.core.dag.logical.LogicalDag; +import org.apache.seatunnel.engine.core.job.JobImmutableInformation; +import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest; +import org.apache.seatunnel.engine.server.SeaTunnelServer; +import org.apache.seatunnel.engine.server.SeaTunnelServerStarter; +import org.apache.seatunnel.engine.server.TestUtils; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.hazelcast.config.Config; +import com.hazelcast.internal.serialization.Data; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.util.Collections; +import java.util.stream.Collectors; + +/** Test for Rest API with Basic. */ +class RestApiHttpBasicTest extends AbstractSeaTunnelServerTest { + + private static final int HTTP_PORT = 18081; + private static final Long JOB_1 = System.currentTimeMillis() + 1L; + public static final String USER = "admin"; + public static final String PASS = "admin"; + + @BeforeAll + void setUp() { + String name = this.getClass().getName(); + Config hazelcastConfig = Config.loadFromString(getHazelcastConfig()); + hazelcastConfig.setClusterName( + TestUtils.getClusterName("RestApiServletHttpBasicTest_" + name)); + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + seaTunnelConfig.setHazelcastConfig(hazelcastConfig); + seaTunnelConfig.getEngineConfig().setMode(ExecutionMode.LOCAL); + + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnabled(Boolean.TRUE); + httpConfig.setPort(HTTP_PORT); + + httpConfig.setEnableBasicAuth(Boolean.TRUE); + httpConfig.setBasicAuthUsername(USER); + httpConfig.setBasicAuthPassword(PASS); + + instance = SeaTunnelServerStarter.createHazelcastInstance(seaTunnelConfig); + nodeEngine = instance.node.nodeEngine; + server = nodeEngine.getService(SeaTunnelServer.SERVICE_NAME); + LOGGER = nodeEngine.getLogger(AbstractSeaTunnelServerTest.class); + } + + @AfterAll + public void after() { + // Disable basic auth + // Because of the ConfigProvider.locateAndGetSeaTunnelConfig() single-case, + // if you change, other use cases will also change + // managed via org.apache.seatunnel.engine.common.config.YamlSeaTunnelDomConfigProcessor + SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); + HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); + httpConfig.setEnableBasicAuth(Boolean.FALSE); + httpConfig.setBasicAuthUsername(""); + httpConfig.setBasicAuthPassword(""); + } + + @Test + public void testRestApiOverview() throws Exception { + HttpURLConnection conn = null; + try { + java.net.URL url = new java.net.URL("http://localhost:" + HTTP_PORT + "/overview"); + conn = (HttpURLConnection) url.openConnection(); + setBasicAuth(conn); + + Assertions.assertEquals(200, conn.getResponseCode()); + Assertions.assertTrue( + conn.getHeaderFields() + .get("Content-Type") + .toString() + .contains("charset=utf-8")); + } finally { + if (conn != null) { + conn.disconnect(); + } + } + } + + @Test + void testLogRestApiResponseFailure() throws IOException { + startJob(); + HttpURLConnection conn = null; + try { + java.net.URL url = + new java.net.URL("http://localhost:" + HTTP_PORT + "/logs?format=JSON"); + conn = (HttpURLConnection) url.openConnection(); + + Assertions.assertEquals(401, conn.getResponseCode()); + } finally { + if (conn != null) { + conn.disconnect(); + } + } + } + + @Test + void testLogRestApiResponseSuccess() throws IOException { + startJob(); + testLogRestApiResponse("JSON"); + } + + public void setBasicAuth(HttpURLConnection connection) { + // Basic Auth + String token = + java.util.Base64.getEncoder() + .encodeToString( + (USER + ":" + PASS) + .getBytes(java.nio.charset.StandardCharsets.UTF_8)); + connection.setRequestProperty("Authorization", "Basic " + token); + } + + public void testLogRestApiResponse(String format) throws IOException { + HttpURLConnection conn = null; + try { + java.net.URL url = Review Comment: ditto ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/LogService.java: ########## @@ -98,6 +108,40 @@ public List<Tuple3<String, String, String>> allLogNameList(String jobId) { return allLogNameList; } + private static HttpBasic getHttpBasicAuth(HttpConfig httpConfig) { + String basicUser = ""; + String basicPass = ""; + try { + if (httpConfig.isEnableBasicAuth()) { + basicUser = httpConfig.getBasicAuthUsername(); + basicPass = httpConfig.getBasicAuthPassword(); + } + } catch (Throwable ignore) { + // Compatible with older versions: If HttpConfig does not have these methods, use system + // properties or environment variables to find out + basicUser = System.getProperty("seatunnel.http.user", System.getenv("BASIC_AUTH_USER")); + basicPass = System.getProperty("seatunnel.http.pass", System.getenv("BASIC_AUTH_PASS")); Review Comment: Does this really provide backward compatibility? As far as I know, older versions didn’t support this feature at all, so this fallback might not actually be effective. ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/LogService.java: ########## @@ -70,15 +73,22 @@ public List<Tuple3<String, String, String>> allLogNameList(String jobId) { systemMonitoringInformation -> { String host = systemMonitoringInformation.asObject().get("host").asString(); String url = "http://" + host + ":" + port + contextPath; - String allName = sendGet(url + REST_URL_GET_ALL_LOG_NAME); - if (StringUtils.isBlank(allName)) { + String logUrl = url + REST_URL_GET_ALL_LOG_NAME; + + String allName = + httpConfig.isEnableBasicAuth() + ? sendGet(logUrl, result.basicUser, result.basicPass) + : sendGet(logUrl); + + if (allName == null || allName.trim().isEmpty()) { Review Comment: Just wondering — was `StringUtils.isBlank()` intentionally replaced? ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java: ########## @@ -47,30 +47,87 @@ public String getLogPath() { } protected String sendGet(String urlString) { + HttpURLConnection connection = null; try { - HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection = (HttpURLConnection) new URL(urlString).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.connect(); + int code = connection.getResponseCode(); if (connection.getResponseCode() == 200) { - try (InputStream is = connection.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; - int len; - while ((len = is.read(buffer)) != -1) { - baos.write(buffer, 0, len); - } - return baos.toString(); - } + return readAll(connection.getInputStream()); } + log.warn("GET {} -> HTTP {}", urlString, code); } catch (IOException e) { - log.error("Send get Fail.{}", ExceptionUtils.getMessage(e)); + log.error("Send GET failed: url={}, err={}", urlString, ExceptionUtils.getMessage(e)); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return null; + } + + /** + * Send GET request with Basic Auth + * + * @param urlString url + * @param user name + * @param pass password + * @return log + */ + protected String sendGet(String urlString, String user, String pass) { + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + + // Basic Auth + if (user != null && pass != null) { + String token = + java.util.Base64.getEncoder() + .encodeToString( + (user + ":" + pass) + .getBytes(java.nio.charset.StandardCharsets.UTF_8)); Review Comment: Let's import it. ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java: ########## @@ -47,30 +47,87 @@ public String getLogPath() { } protected String sendGet(String urlString) { + HttpURLConnection connection = null; try { - HttpURLConnection connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection = (HttpURLConnection) new URL(urlString).openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.connect(); + int code = connection.getResponseCode(); if (connection.getResponseCode() == 200) { - try (InputStream is = connection.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; - int len; - while ((len = is.read(buffer)) != -1) { - baos.write(buffer, 0, len); - } - return baos.toString(); - } + return readAll(connection.getInputStream()); } + log.warn("GET {} -> HTTP {}", urlString, code); } catch (IOException e) { - log.error("Send get Fail.{}", ExceptionUtils.getMessage(e)); + log.error("Send GET failed: url={}, err={}", urlString, ExceptionUtils.getMessage(e)); + } finally { + if (connection != null) { + connection.disconnect(); + } + } + return null; + } + + /** + * Send GET request with Basic Auth + * + * @param urlString url + * @param user name + * @param pass password + * @return log + */ + protected String sendGet(String urlString, String user, String pass) { + HttpURLConnection connection = null; + try { + connection = (HttpURLConnection) new URL(urlString).openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + + // Basic Auth + if (user != null && pass != null) { + String token = + java.util.Base64.getEncoder() + .encodeToString( + (user + ":" + pass) + .getBytes(java.nio.charset.StandardCharsets.UTF_8)); + connection.setRequestProperty("Authorization", "Basic " + token); + } + + connection.connect(); + + int code = connection.getResponseCode(); + if (connection.getResponseCode() == 200) { + return readAll(connection.getInputStream()); + } + log.warn("GET {} -> HTTP {}", urlString, code); + } catch (IOException e) { + log.error("Send GET failed: url={}, err={}", urlString, ExceptionUtils.getMessage(e)); + } finally { + if (connection != null) { + connection.disconnect(); + } } return null; } + private String readAll(InputStream is) throws IOException { + if (is == null) { + return null; + } + try (InputStream in = is; + ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + byte[] buf = new byte[4096]; + int len; + while ((len = in.read(buf)) != -1) { + baos.write(buf, 0, len); + } + return baos.toString(java.nio.charset.StandardCharsets.UTF_8.name()); Review Comment: ditto ########## seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/LogService.java: ########## @@ -98,6 +108,40 @@ public List<Tuple3<String, String, String>> allLogNameList(String jobId) { return allLogNameList; } + private static HttpBasic getHttpBasicAuth(HttpConfig httpConfig) { + String basicUser = ""; + String basicPass = ""; + try { + if (httpConfig.isEnableBasicAuth()) { + basicUser = httpConfig.getBasicAuthUsername(); + basicPass = httpConfig.getBasicAuthPassword(); + } + } catch (Throwable ignore) { + // Compatible with older versions: If HttpConfig does not have these methods, use system + // properties or environment variables to find out + basicUser = System.getProperty("seatunnel.http.user", System.getenv("BASIC_AUTH_USER")); + basicPass = System.getProperty("seatunnel.http.pass", System.getenv("BASIC_AUTH_PASS")); + log.warn("Use system property or environment variable to set basic auth."); + } + + if (StringUtils.isNotBlank(basicUser) && StringUtils.isNotBlank(basicPass)) { + httpConfig.setBasicAuthUsername(basicUser); + httpConfig.setBasicAuthPassword(basicPass); + } Review Comment: Could you explain why this is needed? -- 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]
