Handle configuration value properly.

This commit is contained in:
Michael Lipp 2025-07-14 17:34:09 +02:00
parent 76b579c404
commit fa84110e1d

View file

@ -66,7 +66,6 @@ import org.jose4j.base64url.Base64;
* * `passwordValidity`: the validity of the random password in seconds. * * `passwordValidity`: the validity of the random password in seconds.
* Used to calculate the password expiry time in the generated secret. * Used to calculate the password expiry time in the generated secret.
*/ */
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyStaticImports" })
public class DisplaySecretReconciler extends Component { public class DisplaySecretReconciler extends Component {
protected final Logger logger = Logger.getLogger(getClass().getName()); protected final Logger logger = Logger.getLogger(getClass().getName());
@ -104,12 +103,15 @@ public class DisplaySecretReconciler extends Component {
return oldConfig; return oldConfig;
}).ifPresent(c -> { }).ifPresent(c -> {
try { try {
if (c.containsKey("passwordValidity")) { Optional.ofNullable(c.get("passwordValidity"))
passwordValidity = Integer .map(p -> p instanceof Integer ? (Integer) p
.parseInt((String) c.get("passwordValidity")); : Integer.valueOf((String) p))
} .ifPresent(p -> {
} catch (ClassCastException e) { passwordValidity = p;
logger.config("Malformed configuration: " + e.getMessage()); });
} catch (NumberFormatException e) {
logger.warning(
() -> "Malformed configuration: " + e.getMessage());
} }
}); });
} }
@ -190,7 +192,6 @@ public class DisplaySecretReconciler extends Component {
* @throws ApiException the api exception * @throws ApiException the api exception
*/ */
@Handler @Handler
@SuppressWarnings("PMD.StringInstantiation")
public void onGetDisplaySecret(GetDisplaySecret event, VmChannel channel) public void onGetDisplaySecret(GetDisplaySecret event, VmChannel channel)
throws ApiException { throws ApiException {
// Get VM definition and check if running // Get VM definition and check if running
@ -319,7 +320,6 @@ public class DisplaySecretReconciler extends Component {
/** /**
* The Class PendingGet. * The Class PendingGet.
*/ */
@SuppressWarnings("PMD.DataClass")
private static class PendingRequest { private static class PendingRequest {
public final GetDisplaySecret event; public final GetDisplaySecret event;
public final long expectedSerial; public final long expectedSerial;