diff --git a/src/main/java/com/bettercloud/vault/api/Leases.java b/src/main/java/com/bettercloud/vault/api/Leases.java index bf1c8cae..725c2fbc 100644 --- a/src/main/java/com/bettercloud/vault/api/Leases.java +++ b/src/main/java/com/bettercloud/vault/api/Leases.java @@ -3,6 +3,7 @@ import com.bettercloud.vault.VaultConfig; import com.bettercloud.vault.VaultException; import com.bettercloud.vault.json.Json; +import com.bettercloud.vault.json.JsonObject; import com.bettercloud.vault.response.VaultResponse; import com.bettercloud.vault.rest.Rest; import com.bettercloud.vault.rest.RestResponse; @@ -53,6 +54,7 @@ public VaultResponse revoke(final String leaseId) throws VaultException { int retryCount = 0; while (true) { try { + JsonObject body = Json.object() .add("lease_id", leaseId); /** * 2019-03-21 * Changed the Lease revoke url due to invalid path. Vault deprecated the original @@ -60,10 +62,11 @@ public VaultResponse revoke(final String leaseId) throws VaultException { * https://github.com/hashicorp/vault/blob/master/CHANGELOG.md#080-august-9th-2017 */ final RestResponse restResponse = new Rest()//NOPMD - .url(config.getAddress() + "/v1/sys/leases/revoke/" + leaseId) + .url(config.getAddress() + "/v1/sys/leases/revoke") .header("X-Vault-Token", config.getToken()) .header("X-Vault-Namespace", this.nameSpace) .connectTimeoutSeconds(config.getOpenTimeout()) + .body(body.toString().getBytes(StandardCharsets.UTF_8)) .readTimeoutSeconds(config.getReadTimeout()) .sslVerification(config.getSslConfig().isVerify()) .sslContext(config.getSslConfig().getSslContext()) @@ -234,12 +237,17 @@ public VaultResponse renew(final String leaseId, final long increment) throws Va int retryCount = 0; while (true) { try { - final String requestJson = Json.object().add("increment", increment).toString(); - final RestResponse restResponse = new Rest()//NOPMD - .url(config.getAddress() + "/v1/sys/renew/" + leaseId) + JsonObject body = Json.object().add("lease_id", leaseId); + + if (increment > 0) { + body.add("increment", increment); + } + + final RestResponse restResponse = new Rest() + .url(config.getAddress() + "/v1/sys/leases/renew") .header("X-Vault-Token", config.getToken()) .header("X-Vault-Namespace", this.nameSpace) - .body(increment < 0 ? null : requestJson.getBytes(StandardCharsets.UTF_8)) + .body(body.toString().getBytes(StandardCharsets.UTF_8)) .connectTimeoutSeconds(config.getOpenTimeout()) .readTimeoutSeconds(config.getReadTimeout()) .sslVerification(config.getSslConfig().isVerify())