Merge branch 'feature/delConnFile' into 'main'
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Feature/del conn file See merge request org/jdrupes/vm-operator!3
This commit is contained in:
commit
525696ffe9
3 changed files with 34 additions and 8 deletions
|
|
@ -55,7 +55,11 @@ import org.jgrapes.util.events.ConfigurationUpdate;
|
|||
import org.jose4j.base64url.Base64;
|
||||
|
||||
/**
|
||||
* Watches for changes of display secrets.
|
||||
* Watches for changes of display secrets. The component supports the
|
||||
* following configuration properties:
|
||||
*
|
||||
* * `passwordValidity`: the validity of the random password in seconds.
|
||||
* Used to calculate the password expiry time in the generated secret.
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.TooManyStaticImports" })
|
||||
public class DisplaySecretMonitor
|
||||
|
|
|
|||
|
|
@ -20,17 +20,14 @@ package org.jdrupes.vmoperator.manager;
|
|||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import freemarker.core.ParseException;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapperBuilder;
|
||||
import freemarker.template.MalformedTemplateNameException;
|
||||
import freemarker.template.SimpleNumber;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateExceptionHandler;
|
||||
import freemarker.template.TemplateHashModel;
|
||||
import freemarker.template.TemplateMethodModelEx;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.TemplateNotFoundException;
|
||||
import io.kubernetes.client.custom.Quantity;
|
||||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.net.UnknownHostException;
|
|||
import java.time.Duration;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -92,7 +93,21 @@ import org.jgrapes.webconsole.base.events.UpdateConletType;
|
|||
import org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet;
|
||||
|
||||
/**
|
||||
* The Class VmViewer.
|
||||
* The Class VmViewer. The component supports the following
|
||||
* configuration properties:
|
||||
*
|
||||
* * `displayResource`: a map with the following entries:
|
||||
* - `preferredIpVersion`: `ipv4` or `ipv6` (default: `ipv4`).
|
||||
* Determines the IP addresses uses in the generated
|
||||
* connection file.
|
||||
* * `deleteConnectionFile`: `true` or `false` (default: `true`).
|
||||
* If `true`, the downloaded connection file will be deleted by
|
||||
* the remote viewer when opened.
|
||||
* * `syncPreviewsFor`: a list objects with either property `user` or
|
||||
* `role` and the associated name (default: `[]`).
|
||||
* The remote viewer will synchronize the previews for the specified
|
||||
* users and roles.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.ExcessiveImports",
|
||||
"PMD.CouplingBetweenObjects", "PMD.GodClass", "PMD.TooManyMethods" })
|
||||
|
|
@ -114,6 +129,7 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
|||
private Class<?> preferredIpVersion = Inet4Address.class;
|
||||
private final Set<String> syncUsers = new HashSet<>();
|
||||
private final Set<String> syncRoles = new HashSet<>();
|
||||
private boolean deleteConnectionFile = true;
|
||||
|
||||
/**
|
||||
* The periodically generated update event.
|
||||
|
|
@ -133,8 +149,8 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Configure the component.
|
||||
*
|
||||
* Configure the component.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -155,6 +171,12 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
|||
break;
|
||||
}
|
||||
|
||||
// Delete connection file
|
||||
deleteConnectionFile
|
||||
= Optional.ofNullable(c.get("deleteConnectionFile"))
|
||||
.filter(v -> v instanceof String).map(v -> (String) v)
|
||||
.map(Boolean::parseBoolean).orElse(true);
|
||||
|
||||
// Sync
|
||||
for (var entry : (List<Map<String, String>>) c.getOrDefault(
|
||||
"syncPreviewsFor", Collections.emptyList())) {
|
||||
|
|
@ -317,7 +339,7 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
|||
ConsoleConnection channel, String conletId, ViewerModel model)
|
||||
throws Exception {
|
||||
ResourceBundle resourceBundle = resourceBundle(channel.locale());
|
||||
Set<RenderMode> renderedAs = new HashSet<>();
|
||||
Set<RenderMode> renderedAs = EnumSet.noneOf(RenderMode.class);
|
||||
if (event.renderAs().contains(RenderMode.Preview)) {
|
||||
channel.associated(PENDING, Event.class)
|
||||
.ifPresent(e -> {
|
||||
|
|
@ -564,6 +586,9 @@ public class VmViewer extends FreeMarkerConlet<VmViewer.ViewerModel> {
|
|||
data.append("proxy=").append(u).append('\n');
|
||||
}
|
||||
});
|
||||
if (deleteConnectionFile) {
|
||||
data.append("delete-this-file=1\n");
|
||||
}
|
||||
connection.respond(new NotifyConletView(type(),
|
||||
model.getConletId(), "openConsole", "application/x-virt-viewer",
|
||||
Base64.getEncoder().encodeToString(data.toString().getBytes())));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue