Skip to content

Commit

Permalink
minor refactor - reduce unnecessary visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
namtruong committed Dec 7, 2018
1 parent b366713 commit 97690f6
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.quorum.tessera.key.vault.azure;

public class AzureCredentialNotSetException extends IllegalStateException {
class AzureCredentialNotSetException extends IllegalStateException {

public AzureCredentialNotSetException(String message) {
AzureCredentialNotSetException(String message) {
super(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class AzureKeyVaultClientCredentials extends KeyVaultCredentials {

private final ExecutorService executorService;

public AzureKeyVaultClientCredentials(String clientId, String clientSecret, ExecutorService executorService) {
AzureKeyVaultClientCredentials(String clientId, String clientSecret, ExecutorService executorService) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.executorService = Objects.requireNonNull(executorService);
}

protected void setAuthenticationContext(AuthenticationContext authenticationContext) {
void setAuthenticationContext(AuthenticationContext authenticationContext) {
this.authenticationContext = authenticationContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

import java.util.Objects;

public class AzureKeyVaultClientDelegate {
class AzureKeyVaultClientDelegate {
private final KeyVaultClient keyVaultClient;

public AzureKeyVaultClientDelegate(KeyVaultClient keyVaultClient) {
AzureKeyVaultClientDelegate(KeyVaultClient keyVaultClient) {
this.keyVaultClient = Objects.requireNonNull(keyVaultClient);
}

public SecretBundle getSecret(String vaultBaseUrl, String secretName) {
SecretBundle getSecret(String vaultBaseUrl, String secretName) {
return keyVaultClient.getSecret(vaultBaseUrl, secretName);
}

public SecretBundle setSecret(SetSecretRequest setSecretRequest) {
SecretBundle setSecret(SetSecretRequest setSecretRequest) {
return keyVaultClient.setSecret(setSecretRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import com.microsoft.azure.keyvault.KeyVaultClient;
import com.microsoft.rest.credentials.ServiceClientCredentials;

public class AzureKeyVaultClientFactory {
class AzureKeyVaultClientFactory {

private final ServiceClientCredentials clientCredentials;

public AzureKeyVaultClientFactory(ServiceClientCredentials clientCredentials) {
AzureKeyVaultClientFactory(ServiceClientCredentials clientCredentials) {
this.clientCredentials = clientCredentials;
}

public KeyVaultClient getAuthenticatedClient() {
KeyVaultClient getAuthenticatedClient() {
return new KeyVaultClient(clientCredentials);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AzureKeyVaultService implements KeyVaultService {
private String vaultUrl;
private AzureKeyVaultClientDelegate azureKeyVaultClientDelegate;

public AzureKeyVaultService(AzureKeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate) {
AzureKeyVaultService(AzureKeyVaultConfig keyVaultConfig, AzureKeyVaultClientDelegate azureKeyVaultClientDelegate) {
if(Objects.nonNull(keyVaultConfig)) {
this.vaultUrl = keyVaultConfig.getUrl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

public class AzureKeyVaultServiceFactory implements KeyVaultServiceFactory {

private final String clientIdEnvVar = "AZURE_CLIENT_ID";
private final String clientSecretEnvVar = "AZURE_CLIENT_SECRET";
private static final String clientIdEnvVar = "AZURE_CLIENT_ID";
private static final String clientSecretEnvVar = "AZURE_CLIENT_SECRET";

@Override
public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider, KeyVaultClientFactory keyVaultClientFactory) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.quorum.tessera.key.vault.hashicorp;

public class HashicorpCredentialNotSetException extends IllegalStateException {
class HashicorpCredentialNotSetException extends IllegalStateException {

public HashicorpCredentialNotSetException(String message) {
HashicorpCredentialNotSetException(String message) {
super(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

public class HashicorpKeyVaultClientFactory implements KeyVaultClientFactory {

public Vault createUnauthenticatedClient(HashicorpKeyVaultConfig keyVaultConfig, VaultConfigFactory vaultConfigFactory, SslConfigFactory sslConfigFactory) {
Vault createUnauthenticatedClient(HashicorpKeyVaultConfig keyVaultConfig,
VaultConfigFactory vaultConfigFactory,
SslConfigFactory sslConfigFactory) {
VaultConfig vaultConfig = createBaseVaultConfig(keyVaultConfig, vaultConfigFactory, sslConfigFactory);

VaultCallback.execute(vaultConfig::build);

return new Vault(vaultConfig);
}

public Vault createAuthenticatedClient(HashicorpKeyVaultConfig keyVaultConfig, VaultConfigFactory vaultConfigFactory, SslConfigFactory sslConfigFactory, String authToken) {
Vault createAuthenticatedClient(HashicorpKeyVaultConfig keyVaultConfig,
VaultConfigFactory vaultConfigFactory,
SslConfigFactory sslConfigFactory,
String authToken) {
VaultConfig vaultConfig = createBaseVaultConfig(keyVaultConfig, vaultConfigFactory, sslConfigFactory);

vaultConfig.token(authToken);
Expand Down Expand Up @@ -45,9 +50,7 @@ private VaultConfig createBaseVaultConfig(HashicorpKeyVaultConfig keyVaultConfig
);
}

VaultCallback.execute(
() -> sslConfig.build()
);
VaultCallback.execute(sslConfig::build);

vaultConfig.sslConfig(sslConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HashicorpKeyVaultService implements KeyVaultService {

private final Vault vault;

public HashicorpKeyVaultService(Vault vault) {
HashicorpKeyVaultService(Vault vault) {
this.vault = vault;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

public class HashicorpKeyVaultServiceFactory implements KeyVaultServiceFactory {

private final String roleIdEnvVar = "HASHICORP_ROLE_ID";
private final String secretIdEnvVar = "HASHICORP_SECRET_ID";
private final String authTokenEnvVar = "HASHICORP_TOKEN";
private static final String roleIdEnvVar = "HASHICORP_ROLE_ID";
private static final String secretIdEnvVar = "HASHICORP_SECRET_ID";
private static final String authTokenEnvVar = "HASHICORP_TOKEN";

@Override
public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider, KeyVaultClientFactory keyVaultClientFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.quorum.tessera.key.vault.KeyVaultException;

public class HashicorpVaultException extends KeyVaultException {
class HashicorpVaultException extends KeyVaultException {

public HashicorpVaultException(Throwable cause) {
HashicorpVaultException(Throwable cause) {
super(cause);
}

public HashicorpVaultException(String message) {
HashicorpVaultException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.bettercloud.vault.SslConfig;

//Ensures a newly instantiated SslConfig object is used in the HashicorpKeyVaultClientFactory
public class SslConfigFactory {
class SslConfigFactory {

public SslConfig create() {
return new SslConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.bettercloud.vault.VaultConfig;

//Ensures a newly instantiated VaultConfig object is used in the HashicorpKeyVaultClientFactory
public class VaultConfigFactory {
class VaultConfigFactory {

VaultConfig create() {
return new VaultConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public void exceptionThrownIfErrorEncounteredDuringAppRoleAuthentication() throw

Auth auth = mock(Auth.class);
when(unauthenticatedVault.auth()).thenReturn(auth);
AuthResponse loginResponse = mock(AuthResponse.class);
when(auth.loginByAppRole(anyString(), anyString(), anyString())).thenThrow(VaultException.class);

Throwable ex = catchThrowable(() -> keyVaultServiceFactory.create(config, envProvider, keyVaultClientFactory));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.quorum.tessera.key.vault;

public class NoKeyVaultServiceFactoryException extends RuntimeException {
class NoKeyVaultServiceFactoryException extends RuntimeException {

public NoKeyVaultServiceFactoryException(String message) {
NoKeyVaultServiceFactoryException(String message) {
super(message);
}

Expand Down

0 comments on commit 97690f6

Please sign in to comment.