use of com.coreos.jetcd.exception.AuthFailedException in project jetcd by coreos.
the class Client method getToken.
/**
* get token with ClientBuilder.
*
* @return the auth token
* @throws ConnectException This may be caused as network reason, wrong address
* @throws AuthFailedException This may be caused as wrong username or password
*/
private static Optional<String> getToken(ManagedChannel channel, ClientBuilder builder) throws ConnectException, AuthFailedException {
if (builder.getName() != null || builder.getPassword() != null) {
checkNotNull(builder.getName(), "username can not be null.");
checkNotNull(builder.getPassword(), "password can not be null.");
checkArgument(builder.getName().toStringUtf8().trim().length() != 0, "username can not be null.");
checkArgument(builder.getPassword().toStringUtf8().trim().length() != 0, "password can not be null.");
try {
return Optional.of(authenticate(channel, builder.getName(), builder.getPassword()).get().getToken());
} catch (InterruptedException ite) {
throw new ConnectException("connect to etcd failed", ite);
} catch (ExecutionException exee) {
throw new AuthFailedException("auth failed as wrong username or password", exee);
}
}
return Optional.empty();
}
Aggregations