Implement AutoCloseable

This commit is contained in:
Stefan Kalscheuer 2017-04-13 19:49:47 +02:00
parent e767c07a61
commit ed703f6e53
3 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,7 @@
* [feature] Initialization from environment variables using `fromEnv()` in factory (#8) * [feature] Initialization from environment variables using `fromEnv()` in factory (#8)
* [feature] Automatic authentication with `buildAndAuth()` * [feature] Automatic authentication with `buildAndAuth()`
* [feature] Custom timeout and number of retries (#9) * [feature] Custom timeout and number of retries (#9)
* [feature] Connector implements `AutoCloseable`
* [fix] `SecretResponse` does not throw NPE on `get(key)` and `getData()` * [fix] `SecretResponse` does not throw NPE on `get(key)` and `getData()`
## 0.5.0 [2017-03-18] ## 0.5.0 [2017-03-18]

View File

@ -67,7 +67,7 @@ public class HTTPVaultConnector implements VaultConnector {
private final String baseURL; /* Base URL of Vault */ private final String baseURL; /* Base URL of Vault */
private final SSLContext sslContext; /* Custom SSLSocketFactory */ private final SSLContext sslContext; /* Custom SSLSocketFactory */
private final int retries; /* Number of retries on 5xx errors */ private final int retries; /* Number of retries on 5xx errors */
private final Integer timeout; /* Timeout in milliseconds */ private final Integer timeout; /* Timeout in milliseconds */
private boolean authorized = false; /* authorization status */ private boolean authorized = false; /* authorization status */
private String token; /* current token */ private String token; /* current token */
@ -610,6 +610,13 @@ public class HTTPVaultConnector implements VaultConnector {
return createTokenInternal(token, PATH_TOKEN + PATH_CREATE + "/" + role); return createTokenInternal(token, PATH_TOKEN + PATH_CREATE + "/" + role);
} }
@Override
public void close() {
authorized = false;
token = null;
tokenTTL = 0;
}
/** /**
* Create token. * Create token.
* Centralized method to handle different token creation requests. * Centralized method to handle different token creation requests.

View File

@ -30,7 +30,7 @@ import java.util.*;
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public interface VaultConnector { public interface VaultConnector extends AutoCloseable {
String PATH_SECRET = "secret"; String PATH_SECRET = "secret";
/** /**