Skip to content

Commit

Permalink
Expose an example config.yaml over the registry's REST api
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Jun 14, 2023
1 parent 9d7d6ef commit 934b766
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<quarkus.registry.expose.client.config.yaml>true</quarkus.registry.expose.client.config.yaml>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.quarkus.registry.app;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.registry.app.maven.MavenConfig;
import io.quarkus.registry.config.*;
import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
* Exposes the Quarkus Registry Client configuration file on `/config.yaml`. This is only enabled if
* {@code quarkus.registry.expose.client.config.yaml} is set to {@code true}.
*/
@ApplicationScoped
@Path("/client")
@Tag(name = "Client", description = "Client related services")
@EndpointDisabled(name = "quarkus.registry.expose.client.config.yaml", stringValue = "false", disableIfMissing = true)
public class ClientConfigYamlEndpoint {

@Inject
MavenConfig mavenConfig;

@GET
@Path("/config.yaml")
@Produces(MediaType.TEXT_PLAIN)
@Operation(summary = "Example Quarkus Registry Client configuration file")
public String clientConfigYaml() throws IOException {
ArtifactCoords coords = ArtifactCoords
.fromString(mavenConfig.getRegistryGroupId() + ":quarkus-registry-descriptor::json:1.0-SNAPSHOT");
RegistryMavenRepoConfig mavenRepoConfig = RegistryMavenRepoConfig.builder().setUrl(mavenConfig.getRegistryUrl())
.build();
RegistryConfig registry = RegistryConfig.builder()
.setId(mavenConfig.getRegistryId())
.setUpdatePolicy("always")
.setDescriptor(
RegistryDescriptorConfig.builder().setArtifact(coords))
.setMaven(
RegistryMavenConfig.builder()
.setRepository(mavenRepoConfig)
.build())
.build();
RegistriesConfig registries = RegistriesConfig.builder().setRegistry(registry).build();
Writer resultWriter = new StringWriter();
RegistriesConfigMapperHelper.toYaml(registries, resultWriter);
return resultWriter.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.registry.app.services;

import static io.restassured.RestAssured.given;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import io.quarkus.registry.app.BaseTest;
import io.quarkus.registry.app.maven.MavenConfig;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;

@QuarkusTest
public class ClientConfigurationFileTest extends BaseTest {

@Inject
MavenConfig mavenConfig;

@Test
void getClientConfigurationYaml() {
given()
.get("/client/config.yaml")
.prettyPeek()
.then()
.contentType("text/plain")
.body(Matchers.containsString(
"""
maven:
repository:
url: "%1s"
""".formatted(mavenConfig.getRegistryUrl())))
.statusCode(200);
}
}

0 comments on commit 934b766

Please sign in to comment.