mirror of
https://github.com/keycloak/keycloak.git
synced 2025-12-20 14:00:09 -06:00
Add support to use kcw with remote test server
Closes #44312 Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
@@ -31,6 +31,10 @@ while [ "$1" != "" ]; do
|
|||||||
echo " rel install latest release"
|
echo " rel install latest release"
|
||||||
echo " rel[=version] install specific version"
|
echo " rel[=version] install specific version"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Environment variables:"
|
||||||
|
echo " KCW_PROVIDERS comma separated list of providers to install"
|
||||||
|
echo " KCW_CONFIGS comma separated list of config files to install"
|
||||||
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " Start existing install: kcw start-dev"
|
echo " Start existing install: kcw start-dev"
|
||||||
echo " Install nightly and start: kcw nightly start-dev --cluster=none"
|
echo " Install nightly and start: kcw nightly start-dev --cluster=none"
|
||||||
@@ -125,6 +129,20 @@ if [ "$INSTALL" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$KCW_PROVIDERS" != "" ]; then
|
||||||
|
for PROVIDER in $(echo "$KCW_PROVIDERS" | tr "," "\n"); do
|
||||||
|
cp "$PROVIDER" $KC_DIR/providers/
|
||||||
|
echo "Installed provider: $PROVIDER"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$KCW_CONFIGS" != "" ]; then
|
||||||
|
for CONFIG in $(echo "$KCW_CONFIGS" | tr "," "\n"); do
|
||||||
|
cp "$CONFIG" $KC_DIR/conf/
|
||||||
|
echo "Installed config file: $CONFIG"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$ARGS" != "" ]; then
|
if [ "$ARGS" != "" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "-------------------------------------------------------------------------------------------"
|
echo "-------------------------------------------------------------------------------------------"
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ Valid values:
|
|||||||
Configuration:
|
Configuration:
|
||||||
|
|
||||||
| Value | Description |
|
| Value | Description |
|
||||||
|---------------------------------------------------|------------------------------------------------------------------------|
|
|---------------------------------------------------|----------------------------------------------------------------------------------------|
|
||||||
| `kc.test.server.config` / `KC_TEST_SERVER_CONFIG` | The name of a KeycloakServerConfig class to use when running the tests |
|
| `kc.test.server.config` / `KC_TEST_SERVER_CONFIG` | The name of a KeycloakServerConfig class to use when running the tests |
|
||||||
|
| `kc.test.server.kcw` / `KC_TEST_SERVER_KCW` | Set to a kcw command to use kcw with remote server (see `kcw help` for valid commands) |
|
||||||
|
|
||||||
|
|
||||||
### Database
|
### Database
|
||||||
|
|||||||
@@ -5,19 +5,32 @@ import java.net.URL;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
|
import org.keycloak.it.utils.Maven;
|
||||||
|
import org.keycloak.testframework.config.Config;
|
||||||
|
|
||||||
import io.quarkus.maven.dependency.Dependency;
|
import io.quarkus.maven.dependency.Dependency;
|
||||||
|
|
||||||
|
import static java.lang.System.out;
|
||||||
|
|
||||||
public class RemoteKeycloakServer implements KeycloakServer {
|
public class RemoteKeycloakServer implements KeycloakServer {
|
||||||
|
|
||||||
private boolean enableTls = false;
|
private boolean enableTls = false;
|
||||||
|
|
||||||
|
private String kcwCommand;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(KeycloakServerConfigBuilder keycloakServerConfigBuilder) {
|
public void start(KeycloakServerConfigBuilder keycloakServerConfigBuilder) {
|
||||||
enableTls = keycloakServerConfigBuilder.tlsEnabled();
|
enableTls = keycloakServerConfigBuilder.tlsEnabled();
|
||||||
|
kcwCommand = Config.getValueTypeConfig(KeycloakServer.class, "kcw", null, String.class);
|
||||||
if (!verifyRunningKeycloak()) {
|
if (!verifyRunningKeycloak()) {
|
||||||
printStartupInstructions(keycloakServerConfigBuilder);
|
if (kcwCommand != null) {
|
||||||
|
printStartupInstructionsKcw(keycloakServerConfigBuilder);
|
||||||
|
} else {
|
||||||
|
printStartupInstructionsManual(keycloakServerConfigBuilder);
|
||||||
|
}
|
||||||
waitForStartup();
|
waitForStartup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,36 +62,49 @@ public class RemoteKeycloakServer implements KeycloakServer {
|
|||||||
return enableTls;
|
return enableTls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printStartupInstructions(KeycloakServerConfigBuilder keycloakServerConfigBuilder) {
|
private void printStartupInstructionsManual(KeycloakServerConfigBuilder config) {
|
||||||
StringBuilder sb = new StringBuilder();
|
out.println("Remote Keycloak server is not running on " + getBaseUrl() + ", please start Keycloak with:");
|
||||||
|
out.println();
|
||||||
|
out.println(String.join(" \\\n", config.toArgs()));
|
||||||
|
out.println();
|
||||||
|
|
||||||
sb.append("Remote Keycloak server is not running on ")
|
Set<Dependency> dependencies = config.toDependencies();
|
||||||
.append(getBaseUrl())
|
|
||||||
.append(", please start Keycloak with:\n\n");
|
|
||||||
|
|
||||||
sb.append(String.join(" \\\n", keycloakServerConfigBuilder.toArgs()));
|
|
||||||
sb.append("\n\n");
|
|
||||||
|
|
||||||
Set<Dependency> dependencies = keycloakServerConfigBuilder.toDependencies();
|
|
||||||
if (!dependencies.isEmpty()) {
|
if (!dependencies.isEmpty()) {
|
||||||
sb.append("Requested providers:\n");
|
out.println("Requested providers:");
|
||||||
for (Dependency d : dependencies) {
|
for (Dependency d : dependencies) {
|
||||||
sb.append("- ");
|
out.println("* " + d.getGroupId() + ":" + d.getArtifactId());
|
||||||
sb.append(d.getGroupId());
|
|
||||||
sb.append(":");
|
|
||||||
sb.append(d.getArtifactId());
|
|
||||||
sb.append("\n");
|
|
||||||
}
|
}
|
||||||
|
out.println();
|
||||||
}
|
}
|
||||||
Set<Path> configFiles = keycloakServerConfigBuilder.toConfigFiles();
|
|
||||||
|
Set<Path> configFiles = config.toConfigFiles();
|
||||||
if (!configFiles.isEmpty()) {
|
if (!configFiles.isEmpty()) {
|
||||||
sb.append("Copy following config files to your conf directory:\n");
|
out.println("Config files:");
|
||||||
for (Path c : configFiles) {
|
for (Path c : configFiles) {
|
||||||
sb.append(c.toAbsolutePath());
|
out.print("* " + c.toAbsolutePath());
|
||||||
sb.append("\n");
|
}
|
||||||
|
out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(sb);
|
|
||||||
|
private void printStartupInstructionsKcw(KeycloakServerConfigBuilder config) {
|
||||||
|
out.println("Remote Keycloak server is not running on " + getBaseUrl() + ", please start Keycloak with:");
|
||||||
|
out.println();
|
||||||
|
|
||||||
|
Set<Dependency> dependencies = config.toDependencies();
|
||||||
|
if (!dependencies.isEmpty()) {
|
||||||
|
String dependencyPaths = dependencies.stream().map(d -> Maven.resolveArtifact(d.getGroupId(), d.getArtifactId()).toString()).collect(Collectors.joining(","));
|
||||||
|
out.println("KCW_PROVIDERS=" + dependencyPaths + " \\");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Path> configFiles = config.toConfigFiles();
|
||||||
|
if (!configFiles.isEmpty()) {
|
||||||
|
String configPaths = configFiles.stream().map(p -> p.toAbsolutePath().toString()).collect(Collectors.joining(","));
|
||||||
|
out.println("KCW_CONFIGS=" + configPaths + " \\");
|
||||||
|
}
|
||||||
|
|
||||||
|
out.println("kcw " + kcwCommand + " " + String.join(" \\\n", config.toArgs()));
|
||||||
|
out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean verifyRunningKeycloak() {
|
private boolean verifyRunningKeycloak() {
|
||||||
|
|||||||
Reference in New Issue
Block a user