Skip to content

Commit

Permalink
Merge pull request #19483 from gsmet/2.1.3-backports-2
Browse files Browse the repository at this point in the history
2.1.3 backports 2
  • Loading branch information
gsmet authored Aug 19, 2021
2 parents 90a64f5 + 90a3703 commit 3b78cdb
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/config-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ It is also possible to generate an example `application.properties` with all kno

This creates a `src/main/resources/application.properties.example` file that contains all the config options
exposed via the extensions currently present in the application. These options are commented out, and have their value
set to default swhen applicable. For example this HTTP port config entry will appear as:
set to defaults when applicable. For example this HTTP port config entry will appear as:

.application.properties
[source,properties]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DevServicesConfig {

/**
* If DevServices has been explicitly enabled or disabled..
* If DevServices has been explicitly enabled or disabled.
* <p>
* When DevServices is enabled Quarkus will attempt to automatically configure and start
* Keycloak when running in Dev or Test mode and when Docker is running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -44,6 +45,7 @@
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpHeaders;
import io.vertx.mutiny.core.buffer.Buffer;
import io.vertx.mutiny.ext.web.client.HttpResponse;
import io.vertx.mutiny.ext.web.client.WebClient;

public class KeycloakDevServicesProcessor {
Expand Down Expand Up @@ -342,11 +344,16 @@ private void createRealm(String keycloakUrl, Map<String, String> users, String o
keycloakUrl + "/realms/master/protocol/openid-connect/token",
"admin-cli", null, "admin", "admin", capturedDevServicesConfiguration.webClienTimeout);

client.postAbs(keycloakUrl + "/admin/realms")
HttpResponse<Buffer> response = client.postAbs(keycloakUrl + "/admin/realms")
.putHeader(HttpHeaders.CONTENT_TYPE.toString(), "application/json")
.putHeader(HttpHeaders.AUTHORIZATION.toString(), "Bearer " + token)
.sendBuffer(Buffer.buffer().appendString(JsonSerialization.writeValueAsString(realm)))
.await().atMost(capturedDevServicesConfiguration.webClienTimeout);

if (response.statusCode() > 299) {
LOG.errorf("Realm %s can not be created %d - %s ", realm.getRealm(), response.statusCode(),
response.statusMessage());
}
} catch (Throwable t) {
LOG.errorf("Realm %s can not be created: %s", realm.getRealm(), t.getMessage());
} finally {
Expand Down Expand Up @@ -389,7 +396,9 @@ private RealmRepresentation createRealmRep() {
realm.getRoles().getRealm().add(new RoleRepresentation("user", null, false));
realm.getRoles().getRealm().add(new RoleRepresentation("admin", null, false));
} else {
for (String role : capturedDevServicesConfiguration.roles.values()) {
List<String> distinctRoles = capturedDevServicesConfiguration.roles.values().stream().distinct()
.collect(Collectors.toList());
for (String role : distinctRoles) {
realm.getRoles().getRealm().add(new RoleRepresentation(role, null, false));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,18 @@ static RegistriesConfig initFromEnvironmentOrNull(Map<String, String> map) {

if (isEnvVarOption(var.getKey(), envvarPrefix, "UPDATE_POLICY")) {
registry.setUpdatePolicy(var.getValue());
break;
} else if (isEnvVarOption(var.getKey(), envvarPrefix, "REPO_URL")) {
JsonRegistryMavenConfig maven = (JsonRegistryMavenConfig) registry.getMaven();
if (maven == null) {
maven = new JsonRegistryMavenConfig();
registry.setMaven(maven);
}
JsonRegistryMavenRepoConfig repository = (JsonRegistryMavenRepoConfig) maven.getRepository();
if (repository == null) {
repository = new JsonRegistryMavenRepoConfig();
maven.setRepository(repository);
}
repository.setUrl(var.getValue());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.quarkus.registry.config.json.JsonRegistriesConfig;
import io.quarkus.registry.config.json.JsonRegistryConfig;
import io.quarkus.registry.config.json.JsonRegistryDescriptorConfig;
import io.quarkus.registry.config.json.JsonRegistryMavenConfig;
import io.quarkus.registry.config.json.JsonRegistryMavenRepoConfig;
import io.quarkus.registry.config.json.RegistriesConfigMapperHelper;
import java.io.StringReader;
import java.io.StringWriter;
Expand Down Expand Up @@ -85,6 +87,40 @@ void testRegistryUpdatePolicyFromEnvironment() {
assertThat(actualConfig).isEqualTo(expectedConfig);
}

@Test
void testRegistryRepositoryURLFromEnvironment() {
final Map<String, String> env = new HashMap<>();
env.put(RegistriesConfigLocator.QUARKUS_REGISTRIES, "registry.acme.org,registry.other.io");
env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_ACME_ORG_UPDATE_POLICY", "always");
env.put(RegistriesConfigLocator.QUARKUS_REGISTRY_ENV_VAR_PREFIX + "REGISTRY_OTHER_IO_REPO_URL",
"https://custom.registry.net/mvn");
final RegistriesConfig actualConfig = initFromEnvironment(env);

final JsonRegistriesConfig expectedConfig = new JsonRegistriesConfig();

JsonRegistryConfig registry = new JsonRegistryConfig();
registry.setId("registry.acme.org");
JsonRegistryDescriptorConfig descriptor = new JsonRegistryDescriptorConfig();
descriptor.setArtifact(ArtifactCoords.fromString("org.acme.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT"));
registry.setDescriptor(descriptor);
registry.setUpdatePolicy("always");
expectedConfig.addRegistry(registry);

registry = new JsonRegistryConfig();
registry.setId("registry.other.io");
descriptor = new JsonRegistryDescriptorConfig();
descriptor.setArtifact(ArtifactCoords.fromString("io.other.registry:quarkus-registry-descriptor::json:1.0-SNAPSHOT"));
registry.setDescriptor(descriptor);
JsonRegistryMavenConfig maven = new JsonRegistryMavenConfig();
registry.setMaven(maven);
JsonRegistryMavenRepoConfig repo = new JsonRegistryMavenRepoConfig();
maven.setRepository(repo);
repo.setUrl("https://custom.registry.net/mvn");
expectedConfig.addRegistry(registry);

assertThat(actualConfig).isEqualTo(expectedConfig);
}

private static RegistriesConfig initFromEnvironment(Map<String, String> env) {
return RegistriesConfigLocator.initFromEnvironmentOrNull(env);
}
Expand Down

0 comments on commit 3b78cdb

Please sign in to comment.