Polishing.
Normalize paths in Vault requests to relative paths and leave slash prefixing to UriTemplateHandler.
This commit is contained in:
@@ -76,7 +76,7 @@ public class AppIdAuthentication implements ClientAuthentication {
|
||||
.getUserIdMechanism().createUserId());
|
||||
|
||||
try {
|
||||
VaultResponse response = restOperations.postForObject("/auth/{mount}/login",
|
||||
VaultResponse response = restOperations.postForObject("auth/{mount}/login",
|
||||
login, VaultResponse.class, options.getPath());
|
||||
|
||||
logger.debug("Login successful using AppId authentication");
|
||||
|
||||
@@ -78,7 +78,7 @@ public class AppRoleAuthentication implements ClientAuthentication {
|
||||
options.getSecretId());
|
||||
|
||||
try {
|
||||
VaultResponse response = restOperations.postForObject("/auth/{mount}/login",
|
||||
VaultResponse response = restOperations.postForObject("auth/{mount}/login",
|
||||
login, VaultResponse.class, options.getPath());
|
||||
|
||||
logger.debug("Login successful using AppRole authentication");
|
||||
|
||||
@@ -102,7 +102,7 @@ public class AwsEc2Authentication implements ClientAuthentication {
|
||||
try {
|
||||
|
||||
VaultResponse response = this.vaultRestOperations.postForObject(
|
||||
"/auth/{mount}/login", login, VaultResponse.class, options.getPath());
|
||||
"auth/{mount}/login", login, VaultResponse.class, options.getPath());
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ClientCertificateAuthentication implements ClientAuthentication {
|
||||
private VaultToken createTokenUsingTlsCertAuthentication(String path) {
|
||||
|
||||
try {
|
||||
VaultResponse response = restOperations.postForObject("/auth/{mount}/login",
|
||||
VaultResponse response = restOperations.postForObject("auth/{mount}/login",
|
||||
Collections.emptyMap(), VaultResponse.class, path);
|
||||
|
||||
logger.debug("Login successful using TLS certificates");
|
||||
|
||||
@@ -137,7 +137,7 @@ public class LifecycleAwareSessionManager implements SessionManager, DisposableB
|
||||
private void revoke(VaultToken token) {
|
||||
|
||||
try {
|
||||
restOperations.postForObject("/auth/token/revoke-self",
|
||||
restOperations.postForObject("auth/token/revoke-self",
|
||||
new HttpEntity<Object>(VaultHttpHeaders.from(token)), Map.class);
|
||||
}
|
||||
catch (HttpStatusCodeException e) {
|
||||
@@ -165,7 +165,7 @@ public class LifecycleAwareSessionManager implements SessionManager, DisposableB
|
||||
}
|
||||
|
||||
try {
|
||||
restOperations.postForObject("/auth/token/renew-self",
|
||||
restOperations.postForObject("auth/token/renew-self",
|
||||
new HttpEntity<Object>(VaultHttpHeaders.from(token)), Map.class);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class LoginTokenAdapter implements ClientAuthentication {
|
||||
|
||||
try {
|
||||
ResponseEntity<VaultResponse> entity = restOperations.exchange(
|
||||
"/auth/token/lookup-self", HttpMethod.GET, new HttpEntity<Object>(
|
||||
"auth/token/lookup-self", HttpMethod.GET, new HttpEntity<Object>(
|
||||
VaultHttpHeaders.from(token)), VaultResponse.class);
|
||||
|
||||
return entity.getBody().getData();
|
||||
|
||||
@@ -56,9 +56,9 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
private static final Seal SEAL = new Seal();
|
||||
|
||||
private static final GetMounts GET_MOUNTS = new GetMounts("/sys/mounts");
|
||||
private static final GetMounts GET_MOUNTS = new GetMounts("sys/mounts");
|
||||
|
||||
private static final GetMounts GET_AUTH_MOUNTS = new GetMounts("/sys/auth");
|
||||
private static final GetMounts GET_AUTH_MOUNTS = new GetMounts("sys/auth");
|
||||
|
||||
private static final Health HEALTH = new Health();
|
||||
|
||||
@@ -82,10 +82,11 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
return vaultOperations.doWithVault(new RestOperationsCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Boolean doWithRestOperations(RestOperations restOperations) {
|
||||
|
||||
try {
|
||||
Map<String, Boolean> body = restOperations.getForObject("/sys/init",
|
||||
Map<String, Boolean> body = restOperations.getForObject("sys/init",
|
||||
Map.class);
|
||||
|
||||
return body.get("initialized");
|
||||
@@ -112,7 +113,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
try {
|
||||
ResponseEntity<VaultInitializationResponseImpl> exchange = restOperations
|
||||
.exchange("/sys/init", HttpMethod.PUT,
|
||||
.exchange("sys/init", HttpMethod.PUT,
|
||||
new HttpEntity<Object>(
|
||||
vaultInitializationRequest),
|
||||
VaultInitializationResponseImpl.class);
|
||||
@@ -142,7 +143,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
ResponseEntity<VaultUnsealStatusImpl> response = restOperations
|
||||
.exchange(
|
||||
"/sys/unseal",
|
||||
"sys/unseal",
|
||||
HttpMethod.PUT,
|
||||
new HttpEntity<Object>(Collections.singletonMap(
|
||||
"key", keyShare)),
|
||||
@@ -164,7 +165,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
Assert.notNull(vaultMount, "VaultMount must not be null");
|
||||
|
||||
vaultOperations.write(String.format("/sys/mounts/%s", path), vaultMount);
|
||||
vaultOperations.write(String.format("sys/mounts/%s", path), vaultMount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,7 +178,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
|
||||
vaultOperations.delete(String.format("/sys/mounts/%s", path));
|
||||
vaultOperations.delete(String.format("sys/mounts/%s", path));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,7 +188,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
Assert.notNull(vaultMount, "VaultMount must not be null");
|
||||
|
||||
vaultOperations.write(String.format("/sys/auth/%s", path), vaultMount);
|
||||
vaultOperations.write(String.format("sys/auth/%s", path), vaultMount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,7 +201,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
Assert.hasText(path, "Path must not be empty");
|
||||
|
||||
vaultOperations.delete(String.format("/sys/auth/%s", path));
|
||||
vaultOperations.delete(String.format("sys/auth/%s", path));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,7 +214,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
@Override
|
||||
public VaultUnsealStatus doWithRestOperations(RestOperations restOperations) {
|
||||
return restOperations.getForObject("/sys/seal-status",
|
||||
return restOperations.getForObject("sys/seal-status",
|
||||
VaultUnsealStatusImpl.class);
|
||||
}
|
||||
}
|
||||
@@ -222,7 +223,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
@Override
|
||||
public Void doWithRestOperations(RestOperations restOperations) {
|
||||
restOperations.put("/sys/seal", null);
|
||||
restOperations.put("sys/seal", null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -296,7 +297,7 @@ public class VaultSysTemplate implements VaultSysOperations {
|
||||
|
||||
try {
|
||||
ResponseEntity<VaultHealthImpl> healthResponse = restOperations.exchange(
|
||||
"/sys/health", HttpMethod.GET, null, VaultHealthImpl.class);
|
||||
"sys/health", HttpMethod.GET, null, VaultHealthImpl.class);
|
||||
return healthResponse.getBody();
|
||||
}
|
||||
catch (HttpStatusCodeException responseError) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(request, "VaultTokenRequest must not be null");
|
||||
|
||||
return write("/auth/token/create", request, VaultTokenResponse.class);
|
||||
return write("auth/token/create", request, VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +71,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(request, "VaultTokenRequest must not be null");
|
||||
|
||||
return write("/auth/token/create-orphan", request, VaultTokenResponse.class);
|
||||
return write("auth/token/create-orphan", request, VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +79,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
return write(String.format("/auth/token/renew/%s", vaultToken.getToken()), null,
|
||||
return write(String.format("auth/token/renew/%s", vaultToken.getToken()), null,
|
||||
VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
write(String.format("/auth/token/revoke/%s", vaultToken.getToken()), null,
|
||||
write(String.format("auth/token/revoke/%s", vaultToken.getToken()), null,
|
||||
VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class VaultTokenTemplate implements VaultTokenOperations {
|
||||
|
||||
Assert.notNull(vaultToken, "VaultToken must not be null");
|
||||
|
||||
write(String.format("/auth/token/revoke-orphan/%s", vaultToken.getToken()), null,
|
||||
write(String.format("auth/token/revoke-orphan/%s", vaultToken.getToken()), null,
|
||||
VaultTokenResponse.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ public class SecretLeaseContainer extends SecretLeaseEventPublisher implements
|
||||
public ResponseEntity<Map<String, Object>> doWithRestOperations(
|
||||
RestOperations restOperations) {
|
||||
return (ResponseEntity) restOperations.exchange(
|
||||
"/sys/renew/{leaseId}", HttpMethod.PUT, null, Map.class,
|
||||
"sys/renew/{leaseId}", HttpMethod.PUT, null, Map.class,
|
||||
lease.getLeaseId());
|
||||
}
|
||||
});
|
||||
@@ -574,7 +574,7 @@ public class SecretLeaseContainer extends SecretLeaseEventPublisher implements
|
||||
public ResponseEntity<Map<String, Object>> doWithRestOperations(
|
||||
RestOperations restOperations) {
|
||||
return (ResponseEntity) restOperations.exchange(
|
||||
"/sys/revoke/{leaseId}", HttpMethod.PUT, null,
|
||||
"sys/revoke/{leaseId}", HttpMethod.PUT, null,
|
||||
Map.class, lease.getLeaseId());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ public class LifecycleAwareSessionManagerUnitTests {
|
||||
|
||||
verify(restOperations)
|
||||
.postForObject(
|
||||
eq("/auth/token/revoke-self"),
|
||||
eq("auth/token/revoke-self"),
|
||||
eq(new HttpEntity<Object>(VaultHttpHeaders.from(LoginToken
|
||||
.of("login")))), any(Class.class));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class LifecycleAwareSessionManagerUnitTests {
|
||||
|
||||
verify(restOperations)
|
||||
.postForObject(
|
||||
eq("/auth/token/revoke-self"),
|
||||
eq("auth/token/revoke-self"),
|
||||
eq(new HttpEntity<Object>(VaultHttpHeaders.from(LoginToken
|
||||
.of("login")))), any(Class.class));
|
||||
}
|
||||
@@ -147,7 +147,7 @@ public class LifecycleAwareSessionManagerUnitTests {
|
||||
runnableCaptor.getValue().run();
|
||||
|
||||
verify(restOperations).postForObject(
|
||||
eq("/auth/token/renew-self"),
|
||||
eq("auth/token/renew-self"),
|
||||
eq(new HttpEntity<Object>(VaultHttpHeaders.from(LoginToken.renewable(
|
||||
"login", 5)))), any(Class.class));
|
||||
verify(clientAuthentication, times(1)).login();
|
||||
|
||||
Reference in New Issue
Block a user