From 4061d298fd040d6d1640ff1b827679e7fdcbc49a Mon Sep 17 00:00:00 2001 From: Jean Francois Denise Date: Thu, 4 Apr 2024 15:26:36 +0200 Subject: [PATCH] Introduce env resolver that make it clear that env variables are automatically set --- .../glow/cli/commands/ScanCommand.java | 19 ++++-- .../wildfly/glow/ConfigurationResolver.java | 49 +++++++++++++++ .../java/org/wildfly/glow/ScanResults.java | 12 +++- .../org/wildfly/glow/ScanResultsPrinter.java | 27 ++++++-- .../deployment/openshift/amq/AMQDeployer.java | 33 ++++++++-- .../api/AbstractDatabaseDeployer.java | 19 +++++- .../deployment/openshift/api/Deployer.java | 3 + .../openshift/api/OpenShiftSupport.java | 61 +++++++++++++------ .../openshift/keycloak/KeycloakDeployer.java | 30 +++++++-- 9 files changed, 216 insertions(+), 37 deletions(-) create mode 100644 core/src/main/java/org/wildfly/glow/ConfigurationResolver.java diff --git a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java index 4840a106..90e58be7 100644 --- a/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java +++ b/cli/src/main/java/org/wildfly/glow/cli/commands/ScanCommand.java @@ -49,7 +49,9 @@ import static org.wildfly.glow.Arguments.CLOUD_EXECUTION_CONTEXT; import static org.wildfly.glow.Arguments.COMPACT_PROPERTY; +import org.wildfly.glow.ConfigurationResolver; import org.wildfly.glow.Env; +import org.wildfly.glow.Layer; import static org.wildfly.glow.OutputFormat.BOOTABLE_JAR; import static org.wildfly.glow.OutputFormat.DOCKER_IMAGE; import static org.wildfly.glow.OutputFormat.OPENSHIFT; @@ -311,7 +313,16 @@ public Integer call() throws Exception { builder.setIsCli(true); MavenRepoManager directMavenResolver = MavenResolver.newMavenResolver(); ScanResults scanResults = GlowSession.scan(repoManager == null ? directMavenResolver : repoManager, builder.build(), GlowMessageWriter.DEFAULT); - scanResults.outputInformation(); + ConfigurationResolver configurationResolver = new ConfigurationResolver() { + @Override + public ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exception { + if(provision.get().equals(OPENSHIFT)) { + return OpenShiftSupport.getResolvedEnvs(layer, input, disableDeployers); + } + return null; + } + }; + scanResults.outputInformation(configurationResolver); if (provision.isEmpty()) { if (!compact) { if (suggest.orElse(false)) { @@ -431,13 +442,13 @@ public Integer call() throws Exception { } } if (OutputFormat.OPENSHIFT.equals(provision.get())) { - String name = null; + String name = ""; Path deploymentsDir = target.resolve("deployments"); Files.createDirectories(deploymentsDir); for (Path p : deployments) { Files.copy(p, deploymentsDir.resolve(p.getFileName())); int ext = p.getFileName().toString().indexOf("."); - name = p.getFileName().toString().substring(0, ext); + name += p.getFileName().toString().substring(0, ext); } Map envMap = new HashMap<>(); for (Set envs : scanResults.getSuggestions().getStronglySuggestedConfigurations().values()) { @@ -446,7 +457,7 @@ public Integer call() throws Exception { } } OpenShiftSupport.deploy(GlowMessageWriter.DEFAULT, - target, name == null ? "app-from-glow" : name.toLowerCase(), + target, name.isEmpty() ? "app-from-glow" : name.toLowerCase(), envMap, scanResults.getDiscoveredLayers(), scanResults.getMetadataOnlyLayers(), diff --git a/core/src/main/java/org/wildfly/glow/ConfigurationResolver.java b/core/src/main/java/org/wildfly/glow/ConfigurationResolver.java new file mode 100644 index 00000000..5eb7b544 --- /dev/null +++ b/core/src/main/java/org/wildfly/glow/ConfigurationResolver.java @@ -0,0 +1,49 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 Red Hat, Inc., and individual contributors + * as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wildfly.glow; + +import java.util.Set; + +/** + * + * @author jdenise + */ +public interface ConfigurationResolver { + public class ResolvedEnvs { + private final String name; + private final Set envs; + public ResolvedEnvs(String name, Set envs) { + this.name = name; + this.envs = envs; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the envs + */ + public Set getEnvs() { + return envs; + } + } + ResolvedEnvs getResolvedEnvs(Layer layer, Set input) throws Exception; +} diff --git a/core/src/main/java/org/wildfly/glow/ScanResults.java b/core/src/main/java/org/wildfly/glow/ScanResults.java index 79dc4696..bae79fcf 100644 --- a/core/src/main/java/org/wildfly/glow/ScanResults.java +++ b/core/src/main/java/org/wildfly/glow/ScanResults.java @@ -123,15 +123,23 @@ public OutputContent outputConfig(Path target, String dockerImageName) throws Ex } public void outputInformation() throws Exception { - outputInformation(GlowMessageWriter.DEFAULT); + outputInformation(GlowMessageWriter.DEFAULT, null); } public void outputCompactInformation() throws Exception { outputCompactInformation(GlowMessageWriter.DEFAULT); } + public void outputInformation(ConfigurationResolver resolver) throws Exception { + outputInformation(GlowMessageWriter.DEFAULT, resolver); + } + public void outputInformation(GlowMessageWriter writer) throws Exception { - ScanResultsPrinter printer = new ScanResultsPrinter(writer); + outputInformation(writer, null); + } + + public void outputInformation(GlowMessageWriter writer, ConfigurationResolver resolver) throws Exception { + ScanResultsPrinter printer = new ScanResultsPrinter(writer, resolver); glowSession.outputInformation(printer, this); } diff --git a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java index e5fe96e1..b3c46340 100644 --- a/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java +++ b/core/src/main/java/org/wildfly/glow/ScanResultsPrinter.java @@ -20,8 +20,6 @@ import org.wildfly.glow.error.ErrorLevel; import org.wildfly.glow.error.IdentifiedError; -import java.io.IOException; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -31,14 +29,20 @@ import java.util.TreeSet; import org.jboss.galleon.api.config.GalleonFeaturePackConfig; import org.jboss.galleon.universe.FeaturePackLocation.FPID; +import org.wildfly.glow.ConfigurationResolver.ResolvedEnvs; public class ScanResultsPrinter { private final GlowMessageWriter writer; + private final ConfigurationResolver configResolver; public ScanResultsPrinter(GlowMessageWriter writer) { + this(writer, null); + } + public ScanResultsPrinter(GlowMessageWriter writer, ConfigurationResolver configResolver) { this.writer = writer; + this.configResolver = configResolver; } void print(ScanArguments arguments, ScanResults scanResults) throws Exception { @@ -284,7 +288,7 @@ private void detailed(ScanArguments arguments, ScanResults scanResults) throws E } } - private static String buildSuggestions(Map> map) throws URISyntaxException, IOException { + private String buildSuggestions(Map> map) throws Exception { StringBuilder suggestedConfigsBuilder = new StringBuilder(); for (Layer l : map.keySet()) { suggestedConfigsBuilder.append(buildSuggestions(l, map.get(l))); @@ -292,7 +296,7 @@ private static String buildSuggestions(Map> map) throws URISynta return suggestedConfigsBuilder.toString(); } - private static String buildSuggestions(Layer layer, Set envs) throws URISyntaxException, IOException { + private String buildSuggestions(Layer layer, Set envs) throws Exception { StringBuilder suggestedConfigsBuilder = new StringBuilder(); Set envVars = new TreeSet<>(); Set properties = new TreeSet<>(); @@ -307,6 +311,21 @@ private static String buildSuggestions(Layer layer, Set envs) throws URISyn } if (!envVars.isEmpty()) { suggestedConfigsBuilder.append("\n").append(layer.getName()).append(" environment variables:\n"); + if (configResolver != null) { + ResolvedEnvs resolvedEnvs = configResolver.getResolvedEnvs(layer, envVars); + if (resolvedEnvs != null) { + envVars.removeAll(resolvedEnvs.getEnvs()); + if (envVars.isEmpty()) { + suggestedConfigsBuilder.append(" - ").append("Resolver " + resolvedEnvs.getName()).append(" resolved all env variables."); + } else { + suggestedConfigsBuilder.append(" - ").append("Resolver " + resolvedEnvs.getName()).append(" resolved the following env variables:\n"); + for (Env env : resolvedEnvs.getEnvs()) { + suggestedConfigsBuilder.append(" - ").append(env.getName() + "\n"); + + } + } + } + } Iterator it2 = envVars.iterator(); while (it2.hasNext()) { Env e = it2.next(); diff --git a/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java index 271d250c..2bc78209 100644 --- a/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java +++ b/openshift-deployment/amq-broker/src/main/java/org/wildfly/glow/deployment/openshift/amq/AMQDeployer.java @@ -35,6 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.wildfly.glow.Env; import org.wildfly.glow.GlowMessageWriter; import org.wildfly.glow.deployment.openshift.api.Deployer; import org.wildfly.glow.deployment.openshift.api.Utils; @@ -56,14 +57,26 @@ public class AMQDeployer implements Deployer { private static final String AMQ_PASSWORD_ENV = "AMQ_PASSWORD"; private static final String BROKER_AMQ_USERNAME_ENV = "BROKER_AMQ_USERNAME"; private static final String BROKER_AMQ_PASSWORD_ENV = "BROKER_AMQ_PASSWORD"; + private static final String MQ_SERVICE_PREFIX_MAPPING_ENV = "MQ_SERVICE_PREFIX_MAPPING"; + private static final String TEMPLATE_PASSWORD_ENV = "{PREFIX}_PASSWORD"; + private static final String TEMPLATE_USERNAME_ENV = "{PREFIX}_USERNAME"; + private static final String TEMPLATE_SERVICE_HOST="{SERVICE-NAME}_AMQ7_TCP_SERVICE_HOST"; + private static final String TEMPLATE_SERVICE_PORT="{SERVICE-NAME}_AMQ7_TCP_SERVICE_PORT"; + + private static final Set RESOLVED_ENVS = new HashSet<>(); static { + RESOLVED_ENVS.add(MQ_SERVICE_PREFIX_MAPPING_ENV); + RESOLVED_ENVS.add(TEMPLATE_PASSWORD_ENV); + RESOLVED_ENVS.add(TEMPLATE_USERNAME_ENV); + RESOLVED_ENVS.add(TEMPLATE_SERVICE_HOST); + RESOLVED_ENVS.add(TEMPLATE_SERVICE_PORT); + REMOTE_BROKER_CONNECTION_MAP.put(AMQ_USER_ENV, REMOTE_BROKER_USER); REMOTE_BROKER_CONNECTION_MAP.put(AMQ_PASSWORD_ENV, REMOTE_BROKER_PASSWORD); REMOTE_BROKER_CONNECTION_MAP.put("AMQ_DATA_DIR", "/home/jboss/data"); - REMOTE_BROKER_APP_MAP.put("MQ_SERVICE_PREFIX_MAPPING", "broker-amq7=BROKER_AMQ"); - REMOTE_BROKER_APP_MAP.put("MQ_SERVICE_PREFIX_MAPPING", "broker-amq7=BROKER_AMQ"); + REMOTE_BROKER_APP_MAP.put(MQ_SERVICE_PREFIX_MAPPING_ENV, "broker-amq7=BROKER_AMQ"); REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_TCP_SERVICE_HOST", REMOTE_BROKER_NAME); REMOTE_BROKER_APP_MAP.put("BROKER_AMQ_TCP_SERVICE_PORT", "61616"); REMOTE_BROKER_APP_MAP.put(BROKER_AMQ_PASSWORD_ENV, REMOTE_BROKER_PASSWORD); @@ -73,7 +86,7 @@ public class AMQDeployer implements Deployer { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception { - writer.info("\nDeploying AMQ Messaging Broker"); + writer.info("Deploying AMQ Messaging Broker"); Map labels = new HashMap<>(); labels.put(LABEL, REMOTE_BROKER_NAME); ContainerPort port = new ContainerPort(); @@ -117,8 +130,7 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi withTargetPort(v).build()).withType("ClusterIP").withSessionAffinity("None").withSelector(labels).endSpec().build(); osClient.services().resource(service).createOr(NonDeletingOperation::update); Utils.persistResource(target, service, REMOTE_BROKER_NAME + "-service.yaml"); - Map ret = new HashMap<>(); - ret.putAll(REMOTE_BROKER_APP_MAP); + writer.info("AMQ Messaging Broker has been deployed"); return REMOTE_BROKER_APP_MAP; } @@ -146,6 +158,17 @@ public Map disabledDeploy(String appHost, String appName, String return ret; } + @Override + public Set getResolvedEnvs(Set input) { + Set envs = new HashSet<>(); + for (Env env : input) { + if (RESOLVED_ENVS.contains(env.getName())) { + envs.add(env); + } + } + return envs; + } + @Override public Set getSupportedLayers() { Set ret = new HashSet<>(); diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java index 96d3a2ed..9a0ef269 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/AbstractDatabaseDeployer.java @@ -38,6 +38,7 @@ import java.util.Set; import java.util.TreeMap; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.wildfly.glow.Env; import org.wildfly.glow.GlowMessageWriter; /** @@ -103,6 +104,7 @@ private Map getExistingEnv(Map env) { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception { + writer.info("Deploying " + dbName); Map labels = new HashMap<>(); labels.put(LABEL, dbName); ContainerPort port = new ContainerPort(); @@ -142,7 +144,7 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi Map ret = new HashMap<>(); ret.putAll(getExistingEnv(env)); ret.putAll(APP_MAP); - writer.info("\n" + dbName + " server has been deployed"); + writer.info(dbName + " server has been deployed"); return ret; } @@ -174,4 +176,19 @@ public Map handleBuildTimeDefault(Set buildEnv, MavenRep protected String computeBuildTimeValue(String name, MavenRepoManager mvnResolver) throws Exception { return null; } + + @Override + public Set getResolvedEnvs(Set input) { + Set envs = new HashSet<>(); + for(Env env : input) { + if(APP_MAP.containsKey(env.getName())) { + envs.add(env); + } else { + if (env.getName().startsWith(envRadical + "_")) { + envs.add(env); + } + } + } + return envs; + } } diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java index 5305f136..6348054d 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/Deployer.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; +import org.wildfly.glow.Env; import org.wildfly.glow.GlowMessageWriter; /** @@ -47,4 +48,6 @@ default Set getSupportedLayers() { default Map handleBuildTimeDefault(Set buildEnv, MavenRepoManager mvnResolver) throws Exception { return Collections.emptyMap(); } + + public Set getResolvedEnvs(Set input); } diff --git a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java index def5b75f..d7de7f4e 100644 --- a/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java +++ b/openshift-deployment/api/src/main/java/org/wildfly/glow/deployment/openshift/api/OpenShiftSupport.java @@ -75,6 +75,7 @@ import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.jboss.galleon.util.IoUtils; import org.jboss.galleon.util.ZipUtils; +import org.wildfly.glow.ConfigurationResolver; import org.wildfly.glow.Env; import org.wildfly.glow.GlowMessageWriter; import org.wildfly.glow.Layer; @@ -217,6 +218,44 @@ private static void createAppDeployment(GlowMessageWriter writer, Path target, O osClient.resources(Deployment.class).resource(deployment).waitUntilReady(5, TimeUnit.MINUTES); } + public static ConfigurationResolver.ResolvedEnvs getResolvedEnvs(Layer layer, Set input, Set disabledDeployers) throws Exception { + ConfigurationResolver.ResolvedEnvs resolved = null; + List deployers = getEnabledDeployers(disabledDeployers); + for (Deployer d : deployers) { + if (d.getSupportedLayers().contains(layer.getName())) { + Set envs = d.getResolvedEnvs(input); + if (envs != null && !envs.isEmpty()) { + resolved = new ConfigurationResolver.ResolvedEnvs("openshift/"+d.getName(), envs); + break; + } + } + } + return resolved; + } + + private static List getEnabledDeployers(Set disabledDeployers) throws Exception { + Map existingDeployers = new HashMap<>(); + + for (Deployer d : ServiceLoader.load(Deployer.class)) { + existingDeployers.put(d.getName(), d); + } + for (String disabled : disabledDeployers) { + if (!"ALL".equals(disabled)) { + if (!existingDeployers.containsKey(disabled)) { + throw new Exception("Invalid deployer to disable: " + disabled); + } + } + } + List deployers = new ArrayList<>(); + for (Deployer d : existingDeployers.values()) { + boolean isDisabled = isDisabled(d.getName(), disabledDeployers); + if(!isDisabled) { + deployers.add(d); + } + } + return deployers; + } + public static void deploy(GlowMessageWriter writer, Path target, String appName, @@ -249,19 +288,8 @@ public static void deploy(GlowMessageWriter writer, Utils.persistResource(target, route, appName + "-route.yaml"); String host = osClient.routes().resource(route).get().getSpec().getHost(); // Done route creation - Map existingDeployers = new HashMap<>(); - - for (Deployer d : ServiceLoader.load(Deployer.class)) { - existingDeployers.put(d.getName(), d); - } - for (String disabled : disabledDeployers) { - if (!"ALL".equals(disabled)) { - if (!existingDeployers.containsKey(disabled)) { - throw new Exception("Invalid deployer to disable: " + disabled); - } - } - } - for (Deployer d : existingDeployers.values()) { + List deployers = getEnabledDeployers(disabledDeployers); + for (Deployer d : deployers) { boolean isDisabled = isDisabled(d.getName(), disabledDeployers); for (Layer l : allLayers) { if (d.getSupportedLayers().contains(l.getName())) { @@ -285,13 +313,12 @@ public static void deploy(GlowMessageWriter writer, } } } - writer.info("\nThe active deployers have resolved the environment variables required at build time and deployment time."); actualEnv.put("APPLICATION_ROUTE_HOST", host); actualEnv.putAll(extraEnv); if (!disabledDeployers.isEmpty()) { - writer.warn("\nThe following environment variables will be set in the " + appName + " deployment. Make sure that the required env variables for the disabled deployer(s) have been set:\n"); + writer.warn("The following environment variables will be set in the " + appName + " deployment. Make sure that the required env variables for the disabled deployer(s) have been set:\n"); } else { - writer.warn("\nThe following environment variables will be set in the " + appName + " deployment:\n"); + writer.warn("The following environment variables will be set in the " + appName + " deployment:\n"); } for (Entry entry : actualEnv.entrySet()) { writer.warn(entry.getKey() + "=" + entry.getValue()); @@ -301,7 +328,7 @@ public static void deploy(GlowMessageWriter writer, createBuild(writer, target, osClient, appName, initScript, cliScript, actualBuildEnv, config); writer.info("Deploying application image on OpenShift"); createAppDeployment(writer, target, osClient, appName, actualEnv, ha); - writer.info("\nApplication route: https://" + host + ("ROOT.war".equals(appName) ? "" : "/" + appName)); + writer.info("Application route: https://" + host + ("ROOT.war".equals(appName) ? "" : "/" + appName)); } private static void createBuild(GlowMessageWriter writer, diff --git a/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java b/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java index 20241956..7c7dd4fb 100644 --- a/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java +++ b/openshift-deployment/keycloak/src/main/java/org/wildfly/glow/deployment/openshift/keycloak/KeycloakDeployer.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.wildfly.glow.Env; import org.wildfly.glow.GlowMessageWriter; import org.wildfly.glow.deployment.openshift.api.Deployer; import org.wildfly.glow.deployment.openshift.api.Utils; @@ -60,6 +61,15 @@ public class KeycloakDeployer implements Deployer { private static final String MYSECRET = "mysecret"; private static final String NAMESPACE_ENV = "NAMESPACE"; + private static final Set RESOLVED_ENVS = new HashSet<>(); + static { + RESOLVED_ENVS.add(OIDC_PROVIDER_URL_ENV); + RESOLVED_ENVS.add(OIDC_SECURE_DEPLOYMENT_SECRET_ENV); + RESOLVED_ENVS.add(OIDC_USER_NAME_ENV); + RESOLVED_ENVS.add(OIDC_USER_PASSWORD_ENV); + RESOLVED_ENVS.add(OIDC_PROVIDER_NAME_ENV); + RESOLVED_ENVS.add(OIDC_HOSTNAME_HTTPS_ENV); + } @Override public Map disabledDeploy(String appHost, String appName, String matching, Map env) { Map ret = new HashMap<>(); @@ -81,7 +91,7 @@ private Map getExistingEnv(Map env) { @Override public Map deploy(GlowMessageWriter writer, Path target, OpenShiftClient osClient, Map env, String appHost, String appName, String matching, Map extraEnv) throws Exception { - writer.info("\nDeploying Keycloak server"); + writer.info("Deploying Keycloak server"); Map parameters = new HashMap<>(); String adminVal = extraEnv.get(KEYCLOAK_ADMIN_ENV); parameters.put(KEYCLOAK_ADMIN_ENV, adminVal == null ? KEYCLOAK_ADMIN : adminVal); @@ -103,17 +113,17 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi endMetadata().build(); String host = osClient.routes().resource(route).get().getSpec().getHost(); String url = "https://" + host; - writer.info("\nKeycloak route: " + url); + writer.info("Keycloak route: " + url); Map retEnv = new HashMap<>(); String realmUrl = url + WILDFLY_REALM_PATH; - writer.warn("\nNOTE: Some actions must be taken from the keycloack console."); + writer.warn("NOTE: Some actions must be taken from the keycloack console."); writer.warn("1- Use admin/admin to log to the console " + url); writer.warn("2- Create a realm named WildFly"); writer.warn("3- Create a user named demo, password demo"); writer.warn("4- Create a role needed by your application and assign it to the demo user"); if (env.containsKey(OIDC_PROVIDER_URL_ENV)) { writer.warn("5- Assign the role 'realm-management create-client' to the demo user"); - writer.warn("\nNOTE: In case your application is deployed prior you completed the keycloak admin tasks, make sure to re-deploy your application."); + writer.warn("NOTE: In case your application is deployed prior you completed the keycloak admin tasks, make sure to re-deploy your application."); } else { writer.warn("5 - Create an OIDC Client named the way your OIDC configuration expects it. " + "Set its Root URL to 'https://" + appHost + ("ROOT.war".equals(appName) ? "" : "/" + appName) + "'"); @@ -126,9 +136,21 @@ public Map deploy(GlowMessageWriter writer, Path target, OpenShi retEnv.put(OIDC_USER_PASSWORD_ENV, KEYCLOAK_DEMO_PASSWORD); retEnv.put(OIDC_HOSTNAME_HTTPS_ENV, appHost); } + writer.info("Keycloak server has been deployed"); return retEnv; } + @Override + public Set getResolvedEnvs(Set input) { + Set envs = new HashSet<>(); + for (Env env : input) { + if (RESOLVED_ENVS.contains(env.getName())) { + envs.add(env); + } + } + return envs; + } + @Override public Set getSupportedLayers() { Set ret = new HashSet<>();