Polishing.

Introduce convenience factory method to convert a VaultToken into LoginToken.

See gh-159.
This commit is contained in:
Mark Paluch
2018-01-17 12:41:24 +01:00
parent 0710ae838a
commit b757ff04dc
2 changed files with 16 additions and 1 deletions

View File

@@ -163,6 +163,21 @@ public class LoginToken extends VaultToken {
return new LoginToken(token, Duration.ofSeconds(leaseDurationSeconds), true);
}
/**
* Create a new renewable {@link LoginToken} with a {@code leaseDurationSeconds}.
*
* @param token must not be {@literal null}.
* @param leaseDuration the lease duration, must not be {@literal null} or negative.
* @return the created {@link VaultToken}
* @since 2.0
*/
public static LoginToken renewable(VaultToken token, Duration leaseDuration) {
Assert.notNull(token, "Token must not be null");
return renewable(token.toCharArray(), leaseDuration);
}
/**
* Create a new renewable {@link LoginToken} with a {@code leaseDurationSeconds}.
*

View File

@@ -108,7 +108,7 @@ public class LoginTokenAdapter implements ClientAuthentication {
}
}
private static Duration getLeaseDuration(@Nullable Number ttl) {
static Duration getLeaseDuration(@Nullable Number ttl) {
return ttl == null ? Duration.ZERO : Duration.ofSeconds(ttl.longValue());
}
}