Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed renew and revoke used path style lease ids #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/java/com/bettercloud/vault/api/Leases.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,17 +54,19 @@ 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
* path (/v1/sys/revoke) in favor of a new leases mount point (/v1/sys/leases/revoke)
* 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())
Expand Down Expand Up @@ -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())
Expand Down