Skip to content

Commit

Permalink
Polish BisqCallCredentials style
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeams committed Apr 23, 2020
1 parent bc88080 commit 24c245c
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions cli/src/main/java/bisq/cli/app/BisqCallCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,27 @@ public BisqCallCredentials(Map<String, String> credentials) {
}

@Override
public void applyRequestMetadata(
RequestInfo requestInfo,
Executor appExecutor,
MetadataApplier metadataApplier) {

public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor, MetadataApplier metadataApplier) {
appExecutor.execute(() -> {
try {
Metadata headers = new Metadata();
Key<String> creds = Key.of("bisqd-creds", ASCII_STRING_MARSHALLER);
headers.put(creds, encodeCredentials());
metadataApplier.apply(headers);
} catch (Throwable e) {
metadataApplier.fail(UNAUTHENTICATED.withCause(e));
} catch (Throwable ex) {
metadataApplier.fail(UNAUTHENTICATED.withCause(ex));
}
});
}

@Override
public void thisUsesUnstableApi() {
}

private String encodeCredentials() {
if (!credentials.containsKey(RPC_USER) || !credentials.containsKey(RPC_PASSWORD)) {
if (!credentials.containsKey(RPC_USER) || !credentials.containsKey(RPC_PASSWORD))
throw new ConfigException("Cannot call rpc service without username:password credentials");
} else {
return credentials.get(RPC_USER) + ":" + credentials.get(RPC_PASSWORD);
}

return credentials.get(RPC_USER) + ":" + credentials.get(RPC_PASSWORD);
}

@Override
public void thisUsesUnstableApi() {
}
}

0 comments on commit 24c245c

Please sign in to comment.