Skip to content

Commit 9b44682

Browse files
committed
Remove usage of Handler/AsyncResult idiom.
1 parent 9afefd2 commit 9b44682

File tree

9 files changed

+140
-124
lines changed

9 files changed

+140
-124
lines changed

vertx-config-vault/src/main/java/io/vertx/config/vault/VaultConfigStore.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,8 @@ private Future<Void> renew() {
136136
}
137137

138138
private Future<Void> renewToken() {
139-
Promise<Void> promise = vertx.promise();
140-
client.renewSelf(config.getLong("lease-duration", 3600L), auth -> {
141-
manageAuthenticationResult(promise, auth);
142-
});
143-
return promise.future();
139+
return client.renewSelf(config.getLong("lease-duration", 3600L))
140+
.compose(this::manageAuthenticationResult);
144141
}
145142

146143

@@ -168,7 +165,6 @@ private Future<Void> authenticate(boolean renew) {
168165
}
169166

170167
private Future<Void> loginWithUserName() {
171-
Promise<Void> promise = vertx.promise();
172168
JsonObject req = config.getJsonObject("user-credentials");
173169
Objects.requireNonNull(req, "When using username, the `user-credentials` must be set in the " +
174170
"configuration");
@@ -182,21 +178,16 @@ private Future<Void> loginWithUserName() {
182178
"configuration");
183179

184180

185-
client
186-
.loginWithUserCredentials(username, password, auth -> manageAuthenticationResult(promise, auth));
187-
return promise.future();
181+
return client.loginWithUserCredentials(username, password).compose(auth -> manageAuthenticationResult(auth));
188182
}
189183

190184
private Future<Void> loginWithCert() {
191-
Promise<Void> promise = vertx.promise();
192185
// No validation, certs are configured on the client itself
193-
client.loginWithCert(auth -> manageAuthenticationResult(promise, auth));
194-
return promise.future();
186+
return client.loginWithCert().compose(auth -> manageAuthenticationResult(auth));
195187
}
196188

197189

198190
private Future<Void> loginWithAppRole() {
199-
Promise<Void> promise = vertx.promise();
200191
JsonObject req = config.getJsonObject("approle");
201192
Objects.requireNonNull(req, "When using approle, the `app-role` must be set in the " +
202193
"configuration");
@@ -206,38 +197,30 @@ private Future<Void> loginWithAppRole() {
206197
Objects.requireNonNull(roleId, "When using approle, the role-id must be set in the `approle` configuration");
207198
Objects.requireNonNull(secretId, "When using approle, the secret-id must be set in the `approle` configuration");
208199

209-
client.loginWithAppRole(roleId, secretId, auth -> manageAuthenticationResult(promise, auth));
210-
return promise.future();
200+
return client.loginWithAppRole(roleId, secretId).compose(auth -> manageAuthenticationResult(auth));
211201
}
212202

213203
private Future<Void> loginWithToken() {
214-
Promise<Void> promise = vertx.promise();
215204
JsonObject req = config.getJsonObject("token-request");
216205
Objects.requireNonNull(req, "When using a token creation policy, the `token-request` must be set in the " +
217206
"configuration");
218207

219208
String token = req.getString("token");
220209
Objects.requireNonNull(req, "When using a token creation policy, the `token-request` must be set in the " +
221210
"configuration and contains the `token` entry with the original token");
222-
client
211+
return client
223212
.setToken(token)
224-
.createToken(new TokenRequest(req), auth -> manageAuthenticationResult(promise, auth));
225-
return promise.future();
213+
.createToken(new TokenRequest(req)).compose(auth -> manageAuthenticationResult(auth));
226214
}
227215

228-
private void manageAuthenticationResult(Promise<Void> future, AsyncResult<Auth> auth) {
229-
if (auth.failed()) {
230-
future.fail(auth.cause());
216+
private Future<Void> manageAuthenticationResult(Auth authentication) {
217+
if (authentication.getClientToken() == null) {
218+
return Future.failedFuture("Authentication failed, the token is null");
231219
} else {
232-
Auth authentication = auth.result();
233-
if (authentication.getClientToken() == null) {
234-
future.fail("Authentication failed, the token is null");
235-
} else {
236-
client.setToken(authentication.getClientToken());
237-
this.renewable = authentication.isRenewable();
238-
this.validity = System.currentTimeMillis() + (authentication.getLeaseDuration() * 1000);
239-
future.complete();
240-
}
220+
client.setToken(authentication.getClientToken());
221+
this.renewable = authentication.isRenewable();
222+
this.validity = System.currentTimeMillis() + (authentication.getLeaseDuration() * 1000);
223+
return Future.succeededFuture();
241224
}
242225
}
243226

0 commit comments

Comments
 (0)