Skip to content

Commit

Permalink
Merge pull request #38680 from sberyozkin/keycloak_devservice_mapping…
Browse files Browse the repository at this point in the history
…_log

Log how Keycloak devservice maps resources
  • Loading branch information
sberyozkin authored Feb 8, 2024
2 parents dd6d8df + 0a08d9d commit 9769711
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
capturedDevServicesConfiguration.port,
useSharedNetwork,
capturedDevServicesConfiguration.realmPath.orElse(List.of()),
resourcesMap(),
resourcesMap(errors),
capturedDevServicesConfiguration.serviceName,
capturedDevServicesConfiguration.shared,
capturedDevServicesConfiguration.javaOpts,
Expand Down Expand Up @@ -401,12 +401,17 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
.orElseGet(defaultKeycloakContainerSupplier);
}

private Map<String, String> resourcesMap() {
private Map<String, String> resourcesMap(List<String> errors) {
Map<String, String> resources = new HashMap<>();
for (Map.Entry<String, String> aliasEntry : capturedDevServicesConfiguration.resourceAliases.entrySet()) {
if (capturedDevServicesConfiguration.resourceMappings.containsKey(aliasEntry.getKey())) {
resources.put(aliasEntry.getValue(),
capturedDevServicesConfiguration.resourceMappings.get(aliasEntry.getKey()));
} else {
errors.add(String.format("%s alias for the %s resource does not have a mapping", aliasEntry.getKey(),
aliasEntry.getValue()));
LOG.errorf("%s alias for the %s resource does not have a mapping", aliasEntry.getKey(),
aliasEntry.getValue());
}
}
return resources;
Expand Down Expand Up @@ -540,12 +545,18 @@ protected void configure() {

private void mapResource(String resourcePath, String mappedResource) {
if (Thread.currentThread().getContextClassLoader().getResource(resourcePath) != null) {
LOG.debugf("Mapping the classpath %s resource to %s", resourcePath, mappedResource);
withClasspathResourceMapping(resourcePath, mappedResource, BindMode.READ_ONLY);
} else if (Files.exists(Paths.get(resourcePath))) {
LOG.debugf("Mapping the file system %s resource to %s", resourcePath, mappedResource);
withFileSystemBind(resourcePath, mappedResource, BindMode.READ_ONLY);
} else {
errors.add(String.format("%s resource is not available", resourcePath));
LOG.errorf("Realm %s resource is not available", resourcePath);
errors.add(
String.format(
"%s resource can not be mapped to %s because it is not available on the classpath and file system",
resourcePath, mappedResource));
LOG.errorf("%s resource can not be mapped to %s because it is not available on the classpath and file system",
resourcePath, mappedResource);
}
}

Expand Down

0 comments on commit 9769711

Please sign in to comment.