Skip to content

Commit

Permalink
Merge pull request #59 from orkes-io/get_token_only_if_secure
Browse files Browse the repository at this point in the history
Refresh token only if needed
  • Loading branch information
v1r3n authored Dec 20, 2022
2 parents b6ebaf6 + 1586938 commit 9720f2a
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/main/java/io/orkes/conductor/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public class ApiClient {
private String keyId;
private String keySecret;

private SecretsManager secretsManager;
private String ssmKeyPath;
private String ssmSecretPath;

private String grpcHost = "localhost";
private int grpcPort = 8090;

Expand Down Expand Up @@ -118,10 +114,9 @@ public ApiClient(String basePath) {

public ApiClient(String basePath, SecretsManager secretsManager, String keyPath, String secretPath) {
this(basePath);
this.secretsManager = secretsManager;
this.ssmKeyPath = keyPath;
this.ssmSecretPath = secretPath;
try {
keyId = secretsManager.getSecret(keyPath);
keySecret = secretsManager.getSecret(secretPath);
getToken();
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
Expand Down Expand Up @@ -462,14 +457,6 @@ public ApiClient setWriteTimeout(int writeTimeout) {
return this;
}

public SecretsManager getSecretsManager() {
return secretsManager;
}

public void setSecretsManager(SecretsManager secretsManager) {
this.secretsManager = secretsManager;
}

/**
* Format the given parameter object into string.
*
Expand Down Expand Up @@ -1263,17 +1250,16 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti

public String getToken() {
try {
if (!useSecurity()) {
return null;
}
return tokenCache.get(TOKEN_CACHE_KEY, () -> refreshToken());
} catch (ExecutionException e) {
return null;
}
}

private String refreshToken() {
if (secretsManager != null) {
keyId = secretsManager.getSecret(this.ssmKeyPath);
keySecret = secretsManager.getSecret(this.ssmSecretPath);
}
if (this.keyId == null || this.keySecret == null) {
throw new RuntimeException("KeyId and KeySecret must be set in order to get an authentication token");
}
Expand Down

0 comments on commit 9720f2a

Please sign in to comment.