mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-01 19:18:05 +00:00
[Fix-19900] Proxy Url Issue (#20574)
* Fix Proxy Url Issue * Fix Failing Tests
This commit is contained in:
parent
fdf081f28c
commit
27cf2e0354
@ -220,6 +220,17 @@ public class SettingsCache {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getSettingOrDefault(
|
||||
SettingsType settingName, T defaultValue, Class<T> clazz) {
|
||||
try {
|
||||
String json = JsonUtils.pojoToJson(CACHE.get(settingName.toString()).getConfigValue());
|
||||
return JsonUtils.readValue(json, clazz);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Failed to fetch Settings . Setting {}", settingName, ex);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanUp() {
|
||||
CACHE.invalidateAll();
|
||||
initialized = false;
|
||||
|
||||
@ -26,6 +26,7 @@ import io.dropwizard.db.DataSourceFactory;
|
||||
import io.dropwizard.jackson.Jackson;
|
||||
import io.dropwizard.jersey.validation.Validators;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -200,12 +201,13 @@ public class OpenMetadataOperations implements Callable<Integer> {
|
||||
required = true)
|
||||
String openMetadataUrl) {
|
||||
try {
|
||||
URI uri = URI.create(openMetadataUrl);
|
||||
parseConfig();
|
||||
Settings updatedSettings =
|
||||
new Settings()
|
||||
.withConfigType(SettingsType.OPEN_METADATA_BASE_URL_CONFIGURATION)
|
||||
.withConfigValue(
|
||||
new OpenMetadataBaseUrlConfiguration().withOpenMetadataUrl(openMetadataUrl));
|
||||
new OpenMetadataBaseUrlConfiguration().withOpenMetadataUrl(uri.toString()));
|
||||
|
||||
Entity.getSystemRepository().createOrUpdate(updatedSettings);
|
||||
LOG.info("Updated OpenMetadata URL to: {}", openMetadataUrl);
|
||||
|
||||
@ -38,8 +38,11 @@ import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.Getter;
|
||||
import org.openmetadata.common.utils.CommonUtil;
|
||||
import org.openmetadata.schema.api.configuration.OpenMetadataBaseUrlConfiguration;
|
||||
import org.openmetadata.schema.settings.SettingsType;
|
||||
import org.openmetadata.schema.type.ChangeEvent;
|
||||
import org.openmetadata.schema.type.EventType;
|
||||
import org.openmetadata.service.resources.settings.SettingsCache;
|
||||
|
||||
public final class RestUtil {
|
||||
public static final String CHANGE_CUSTOM_HEADER = "X-OpenMetadata-Change";
|
||||
@ -66,8 +69,13 @@ public final class RestUtil {
|
||||
|
||||
public static URI getHref(UriInfo uriInfo, String collectionPath) {
|
||||
collectionPath = removeSlashes(collectionPath);
|
||||
String uriPath = uriInfo.getBaseUri() + collectionPath;
|
||||
return URI.create(uriPath);
|
||||
OpenMetadataBaseUrlConfiguration urlConfiguration =
|
||||
SettingsCache.getSettingOrDefault(
|
||||
SettingsType.OPEN_METADATA_BASE_URL_CONFIGURATION,
|
||||
new OpenMetadataBaseUrlConfiguration()
|
||||
.withOpenMetadataUrl(uriInfo.getBaseUri().toString()),
|
||||
OpenMetadataBaseUrlConfiguration.class);
|
||||
return URI.create(urlConfiguration.getOpenMetadataUrl() + "/" + collectionPath);
|
||||
}
|
||||
|
||||
public static URI getHref(URI parent, String child) {
|
||||
|
||||
@ -22,11 +22,20 @@ import javax.ws.rs.core.UriInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.openmetadata.schema.api.configuration.OpenMetadataBaseUrlConfiguration;
|
||||
import org.openmetadata.schema.settings.SettingsType;
|
||||
import org.openmetadata.service.OpenMetadataApplicationTest;
|
||||
import org.openmetadata.service.resources.settings.SettingsCache;
|
||||
|
||||
@Slf4j
|
||||
class RestUtilTest {
|
||||
class RestUtilTest extends OpenMetadataApplicationTest {
|
||||
@Test
|
||||
void hrefTests() throws URISyntaxException {
|
||||
OpenMetadataBaseUrlConfiguration urlConfiguration =
|
||||
SettingsCache.getSetting(
|
||||
SettingsType.OPEN_METADATA_BASE_URL_CONFIGURATION,
|
||||
OpenMetadataBaseUrlConfiguration.class);
|
||||
|
||||
URI baseUri = URI.create("http://base");
|
||||
assertEquals(URI.create("http://base/path"), RestUtil.getHref(baseUri, "path"));
|
||||
assertEquals(
|
||||
@ -37,45 +46,74 @@ class RestUtilTest {
|
||||
assertEquals(
|
||||
URI.create("http://base/path"), RestUtil.getHref(baseUri, "/path/")); // Remove both slashes
|
||||
|
||||
UriInfo uriInfo = mockUriInfo("http://base/");
|
||||
assertEquals(URI.create("http://base/collection"), RestUtil.getHref(uriInfo, "collection"));
|
||||
assertEquals(URI.create("http://base/collection"), RestUtil.getHref(uriInfo, "/collection"));
|
||||
assertEquals(URI.create("http://base/collection"), RestUtil.getHref(uriInfo, "collection/"));
|
||||
assertEquals(URI.create("http://base/collection"), RestUtil.getHref(uriInfo, "/collection/"));
|
||||
UriInfo uriInfo = mockUriInfo(urlConfiguration.getOpenMetadataUrl());
|
||||
assertEquals(
|
||||
URI.create(String.format("%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection")),
|
||||
RestUtil.getHref(uriInfo, "collection"));
|
||||
assertEquals(
|
||||
URI.create(String.format("%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection")),
|
||||
RestUtil.getHref(uriInfo, "/collection"));
|
||||
assertEquals(
|
||||
URI.create(String.format("%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection")),
|
||||
RestUtil.getHref(uriInfo, "collection/"));
|
||||
assertEquals(
|
||||
URI.create(String.format("%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection")),
|
||||
RestUtil.getHref(uriInfo, "/collection/"));
|
||||
|
||||
UUID id = UUID.randomUUID();
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/" + id), RestUtil.getHref(uriInfo, "collection", id));
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", id)),
|
||||
RestUtil.getHref(uriInfo, "collection", id));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/" + id), RestUtil.getHref(uriInfo, "/collection", id));
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", id)),
|
||||
RestUtil.getHref(uriInfo, "/collection", id));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/" + id), RestUtil.getHref(uriInfo, "collection/", id));
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", id)),
|
||||
RestUtil.getHref(uriInfo, "collection/", id));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/" + id), RestUtil.getHref(uriInfo, "/collection/", id));
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", id)),
|
||||
RestUtil.getHref(uriInfo, "/collection/", id));
|
||||
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path"), RestUtil.getHref(uriInfo, "collection", "path"));
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path")),
|
||||
RestUtil.getHref(uriInfo, "collection", "path"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path"),
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path")),
|
||||
RestUtil.getHref(uriInfo, "/collection", "/path"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path"),
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path")),
|
||||
RestUtil.getHref(uriInfo, "collection/", "path/"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path"),
|
||||
URI.create(
|
||||
String.format("%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path")),
|
||||
RestUtil.getHref(uriInfo, "/collection/", "/path/"));
|
||||
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path%201"),
|
||||
URI.create(
|
||||
String.format(
|
||||
"%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path%201")),
|
||||
RestUtil.getHref(uriInfo, "collection", "path 1"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path%201"),
|
||||
URI.create(
|
||||
String.format(
|
||||
"%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path%201")),
|
||||
RestUtil.getHref(uriInfo, "/collection", "/path 1"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path%201"),
|
||||
URI.create(
|
||||
String.format(
|
||||
"%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path%201")),
|
||||
RestUtil.getHref(uriInfo, "collection/", "path 1/"));
|
||||
assertEquals(
|
||||
URI.create("http://base/collection/path%201"),
|
||||
URI.create(
|
||||
String.format(
|
||||
"%s/%s/%s", urlConfiguration.getOpenMetadataUrl(), "collection", "path%201")),
|
||||
RestUtil.getHref(uriInfo, "/collection/", "/path 1/"));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user