Consider Vault base path in VaultClients

VaultClients.toBaseUri(…) now properly renders endpoints considering the path segment from VaultEndpoint.

Resolves: gh-413.
This commit is contained in:
Mark Paluch
2019-04-11 14:28:58 +02:00
parent 85f8d8ece7
commit 320fe6404e
2 changed files with 16 additions and 2 deletions

View File

@@ -207,8 +207,9 @@ public class VaultClients {
}
private static String toBaseUri(VaultEndpoint endpoint) {
return endpoint.getScheme() + "://" + endpoint.getHost() + ":"
+ endpoint.getPort() + "/v1";
return String.format("%s://%s:%s/%s", endpoint.getScheme(), endpoint.getHost(),
endpoint.getPort(), endpoint.getPath());
}
/**

View File

@@ -81,4 +81,17 @@ public class VaultClientsUnitTests {
assertThat(uri).hasScheme("https").hasHost("foo").hasPort(-1)
.hasPath("/path/bar");
}
@Test
public void shouldApplyBasepath() {
VaultEndpoint localhost = VaultEndpoint.create("localhost", 8200);
localhost.setPath("foo/v1");
PrefixAwareUriTemplateHandler handler = new PrefixAwareUriTemplateHandler(
() -> localhost);
URI uri = handler.expand("/path/{bar}", "bar");
assertThat(uri).hasHost("localhost").hasPort(8200).hasPath("/foo/v1/path/bar");
}
}