-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose an example config.yaml over the registry's REST api
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/io/quarkus/registry/app/ClientConfigYamlEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/io/quarkus/registry/app/services/ClientConfigurationFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |