Skip to content

Commit

Permalink
Ability to configure the registry URL from an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky authored and gsmet committed Aug 18, 2021
1 parent 550fedd commit 90a3703
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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 90a3703

Please sign in to comment.