Always update console user.

This commit is contained in:
Michael Lipp 2024-11-15 09:53:34 +01:00
parent e864f677c3
commit dc7382dc86

View file

@ -180,19 +180,7 @@ public class DisplaySecretMonitor
@SuppressWarnings("PMD.StringInstantiation") @SuppressWarnings("PMD.StringInstantiation")
public void onGetDisplaySecrets(GetDisplayPassword event, VmChannel channel) public void onGetDisplaySecrets(GetDisplayPassword event, VmChannel channel)
throws ApiException { throws ApiException {
ListOptions options = new ListOptions(); // Update console user in status
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET + ","
+ "app.kubernetes.io/instance="
+ event.vmDefinition().metadata().getName());
var stubs = K8sV1SecretStub.list(client(),
event.vmDefinition().namespace(), options);
if (stubs.isEmpty()) {
return;
}
var stub = stubs.iterator().next();
// Valid request, update console user in status
var vmStub = VmDefinitionStub.get(client(), var vmStub = VmDefinitionStub.get(client(),
new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM), new GroupVersionKind(VM_OP_GROUP, "", VM_OP_KIND_VM),
event.vmDefinition().namespace(), event.vmDefinition().name()); event.vmDefinition().namespace(), event.vmDefinition().name());
@ -202,6 +190,20 @@ public class DisplaySecretMonitor
return status; return status;
}); });
// Look for secret
ListOptions options = new ListOptions();
options.setLabelSelector("app.kubernetes.io/name=" + APP_NAME + ","
+ "app.kubernetes.io/component=" + COMP_DISPLAY_SECRET + ","
+ "app.kubernetes.io/instance="
+ event.vmDefinition().metadata().getName());
var stubs = K8sV1SecretStub.list(client(),
event.vmDefinition().namespace(), options);
if (stubs.isEmpty()) {
// No secret means no password for this VM wanted
return;
}
var stub = stubs.iterator().next();
// Check validity // Check validity
var model = stub.model().get(); var model = stub.model().get();
@SuppressWarnings("PMD.StringInstantiation") @SuppressWarnings("PMD.StringInstantiation")
@ -209,6 +211,7 @@ public class DisplaySecretMonitor
.get(DATA_PASSWORD_EXPIRY)).map(b -> new String(b)).orElse(null); .get(DATA_PASSWORD_EXPIRY)).map(b -> new String(b)).orElse(null);
if (model.getData().get(DATA_DISPLAY_PASSWORD) != null if (model.getData().get(DATA_DISPLAY_PASSWORD) != null
&& stillValid(expiry)) { && stillValid(expiry)) {
// Fixed secret, don't touch
event.setResult( event.setResult(
new String(model.getData().get(DATA_DISPLAY_PASSWORD))); new String(model.getData().get(DATA_DISPLAY_PASSWORD)));
return; return;