jhsb25 commented on a change in pull request #3097: URL: https://github.com/apache/hudi/pull/3097#discussion_r660544635
########## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/schema/SchemaRegistryProvider.java ########## @@ -48,19 +54,40 @@ "hoodie.deltastreamer.schemaprovider.registry.targetUrl"; } - private static String fetchSchemaFromRegistry(String registryUrl) throws IOException { - URL registry = new URL(registryUrl); + public String fetchSchemaFromRegistry(String registryUrl) throws IOException { + URL registry; + HttpURLConnection connection; + Matcher matcher = Pattern.compile("://(.*?)@").matcher(registryUrl); + if (matcher.find()) { + String creds = matcher.group(1); + String urlWithoutCreds = registryUrl.replace(creds + "@", ""); + registry = new URL(urlWithoutCreds); + connection = (HttpURLConnection) registry.openConnection(); + setAuthorizationHeader(matcher.group(1), connection); + } else { + registry = new URL(registryUrl); + connection = (HttpURLConnection) registry.openConnection(); + } ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(registry.openStream()); + JsonNode node = mapper.readTree(getStream(connection)); return node.get("schema").asText(); } + public void setAuthorizationHeader(String creds, HttpURLConnection connection) { + String encodedAuth = Base64.getEncoder().encodeToString(creds.getBytes(StandardCharsets.UTF_8)); + connection.setRequestProperty("Authorization", "Basic " + encodedAuth); + } + + public InputStream getStream(HttpURLConnection connection) throws IOException { + return connection.getInputStream(); Review comment: this is implemented like this for testing purposes, in order to allow for mocking/spying of the InputStream. I've made the method protected. -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org