add log to secretsmanager
import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import com.amazonaws.services.secretsmanager.model.DecryptionFailureException;
*/
public final class SecretCredentialsManager {
+ /** The Constant FALSE. */
+ private static final String FALSE = "false";
+
+ /** The Constant LOGGER. */
+ private static final Logger LOGGER = LoggerFactory.getLogger(SecretCredentialsManager.class);
+
/** The secret name. */
private final String secretName;
@@ -68,7 +77,7 @@ public SecretCredentialsManager(String secretName, String secretEnabled,String u
* @throws Exception the exception
*/
public String getPassword() {
- if ("false".equalsIgnoreCase(secretEnabled)) {
+ if (FALSE.equalsIgnoreCase(secretEnabled)) {
return password;
}
try {
@@ -78,7 +87,8 @@ public String getPassword() {
final ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(client.getSecretValue(new GetSecretValueRequest().withSecretId(secretName)).getSecretString(), UsernamePassword.class).password;
} catch (DecryptionFailureException | InternalServiceErrorException | InvalidParameterException | IOException e) {
- return password;
+ LOGGER.error("Problem getting password from secretsmanager using secret:" + secretName, e);
+ throw new RuntimeException(e);
}
}
@@ -89,7 +99,7 @@ public String getPassword() {
* @throws Exception the exception
*/
public String getUsername() {
- if ("false".equalsIgnoreCase(secretEnabled)) {
+ if (FALSE.equalsIgnoreCase(secretEnabled)) {
return username;
}
@@ -100,7 +110,8 @@ public String getUsername() {
final ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(client.getSecretValue(new GetSecretValueRequest().withSecretId(secretName)).getSecretString(), UsernamePassword.class).username;
} catch (DecryptionFailureException | InternalServiceErrorException | InvalidParameterException | IOException e) {
- return username;
+ LOGGER.error("Problem getting username from secretsmanager using secret:" + secretName, e);
+ throw new RuntimeException(e);
}
}
