Skip to content

Commit

Permalink
SET-559 codacy findings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
john-sobrepena-partior committed Aug 23, 2024
1 parent 6293a2f commit 781fa5b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class HashicorpVaultDbCredentialsConfig extends ConfigItem {
@Valid @XmlElement private String delayBeforeNextRunFactor;
@Valid @XmlElement private String maxDurationBeforeTtlExpireInSeconds;

public HashicorpVaultDbCredentialsConfig(HashicorpVaultDbCredentialsConfig config){
public HashicorpVaultDbCredentialsConfig(HashicorpVaultDbCredentialsConfig config) {
this.url = config.url;
this.namespace = config.namespace;
this.approlePath = config.approlePath;
Expand Down Expand Up @@ -190,7 +190,8 @@ public DefaultKeyVaultConfig toKeyVaultConfig() {
config.setProperty("maxRetryDelayInSeconds", this.getMaxRetryDelayInSeconds());
config.setProperty("minDelayBeforeNextRunInSeconds", this.getMinDelayBeforeNextRunInSeconds());
config.setProperty("delayBeforeNextRunFactor", this.getDelayBeforeNextRunFactor());
config.setProperty("maxDurationBeforeTtlExpireInSeconds", this.getMaxDurationBeforeTtlExpireInSeconds());
config.setProperty(
"maxDurationBeforeTtlExpireInSeconds", this.getMaxDurationBeforeTtlExpireInSeconds());

Optional.ofNullable(this.getTlsKeyStorePath())
.map(Objects::toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public HashicorpDbCredentials getDbCredentials() {
vaultOperations.read(
String.format("%s/%s/%s", dbSecretEngineName, credentialPath, vaultDbRole));
} catch (Exception ex) {
throw new RuntimeException(
"Unexpected error reading db credentials from hashicorp vault", ex);
throw new ConfigException(
new RuntimeException("Unexpected error reading db credentials from hashicorp vault", ex));
}

if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.quorum.tessera.key.vault.hashicorp;

import com.quorum.tessera.config.Config;
import com.quorum.tessera.config.ConfigException;
import com.quorum.tessera.config.KeyVaultConfig;
import com.quorum.tessera.config.KeyVaultType;
import com.quorum.tessera.config.util.EnvironmentVariableProvider;
Expand Down Expand Up @@ -51,10 +52,11 @@ void validateRequiredConfigurationPropertiesArePresent(KeyVaultConfig keyVaultCo
|| keyVaultConfig.getProperty(propName).isEmpty())
.toList();
if (!missingProperties.isEmpty()) {
throw new HashicorpVaultException(
String.format(
"[%s] missing in the configuration. This/these properties should be defined in configuration section: jdbc.hashicorpVaultDbCredentialsConfig",
String.join(", ", missingProperties)));
throw new ConfigException(
new RuntimeException(
String.format(
"[%s] missing in the configuration. This/these properties should be defined in configuration section: jdbc.hashicorpVaultDbCredentialsConfig",
String.join(", ", missingProperties))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,20 @@ private <R> R validateAndConvertValue(
return defaultValue;
}

private void logStartupConfiguration(){
private void logStartupConfiguration() {
StringBuilder sb = new StringBuilder();
sb.append("retryDelayInSeconds=").append(this.retryDelayInSeconds).append("; ");
sb.append("maxRetryDelayInSeconds=").append(this.maxRetryDelayInSeconds).append("; ");
sb.append("minDelayBeforeNextRunInSeconds=").append(this.minDelayBeforeNextRunInSeconds).append("; ");
sb.append("minDelayBeforeNextRunInSeconds=")
.append(this.minDelayBeforeNextRunInSeconds)
.append("; ");
sb.append("delayBeforeNextRunFactor=").append(this.delayBeforeNextRunFactor).append("; ");
sb.append("maxDurationBeforeTtlExpireInSeconds=").append(this.maxDurationBeforeTtlExpireInSeconds).append("; ");
LOGGER.info("Component for managing life-cycle of db credentials in vault started with configurations: {}", sb.toString());
sb.append("maxDurationBeforeTtlExpireInSeconds=")
.append(this.maxDurationBeforeTtlExpireInSeconds)
.append("; ");
LOGGER.info(
"Component for managing life-cycle of db credentials in vault started with configurations: {}",
sb.toString());
}

public void start(final long initialDelayInSeconds) {
Expand Down

0 comments on commit 781fa5b

Please sign in to comment.