diff --git a/app/pom.xml b/app/pom.xml index f38f9b22f1..136cdb42af 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -251,6 +251,11 @@ apicurio-registry-avro-serde-kafka test + + io.apicurio + apicurio-registry-java-sdk + test + io.apicurio apicurio-registry-protobuf-serde-kafka diff --git a/app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java b/app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java index 8fbec308ce..55177eed4b 100644 --- a/app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java +++ b/app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java @@ -2,7 +2,6 @@ import com.microsoft.kiota.ApiException; import com.microsoft.kiota.RequestAdapter; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -26,6 +25,7 @@ import io.restassured.RestAssured; import io.restassured.parsing.Parser; import io.restassured.response.ValidatableResponse; +import io.vertx.core.Vertx; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -60,26 +60,29 @@ public abstract class AbstractResourceTestBase extends AbstractRegistryTestBase protected RegistryClient clientV3; protected RestService confluentClient; + protected Vertx vertx; + @BeforeAll protected void beforeAll() throws Exception { + vertx = Vertx.vertx(); String serverUrl = "http://localhost:%s/apis"; registryApiBaseUrl = String.format(serverUrl, testPort); registryV3ApiUrl = registryApiBaseUrl + "/registry/v3"; - clientV3 = createRestClientV3(); + clientV3 = createRestClientV3(vertx); confluentClient = buildConfluentClient(); } @AfterAll protected void afterAll() { + vertx.close(); } protected RestService buildConfluentClient() { return new RestService("http://localhost:" + testPort + "/apis/ccompat/v7"); } - protected final RequestAdapter anonymousAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); - - protected RegistryClient createRestClientV3() { + protected RegistryClient createRestClientV3(Vertx vertx) { + RequestAdapter anonymousAdapter = new VertXRequestAdapter(vertx); anonymousAdapter.setBaseUrl(registryV3ApiUrl); var client = new RegistryClient(anonymousAdapter); return client; diff --git a/app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java b/app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java index b864039e7d..7a4db92952 100644 --- a/app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java +++ b/app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java @@ -3,7 +3,6 @@ import com.microsoft.kiota.ApiException; import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.types.ArtifactType; @@ -37,7 +36,7 @@ public class AuthTestAnonymousCredentials extends AbstractResourceTestBase { @Test public void testWrongCreds() throws Exception { var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); + buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); @@ -50,7 +49,7 @@ public void testWrongCreds() throws Exception { @Test public void testNoCredentials() throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); // Read-only operation should work without any credentials. diff --git a/app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java b/app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java index f30bd18cb0..ca6d52e50e 100644 --- a/app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java +++ b/app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java @@ -2,6 +2,7 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.types.ArtifactType; @@ -13,13 +14,12 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; - @QuarkusTest @TestProfile(AuthTestProfileAuthenticatedReadAccess.class) @Tag(ApicurioTestTags.SLOW) @@ -32,9 +32,9 @@ public class AuthTestAuthenticatedReadAccess extends AbstractResourceTestBase { final String groupId = getClass().getSimpleName() + "Group"; @Override - protected RegistryClient createRestClientV3() { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + protected RegistryClient createRestClientV3(Vertx vertx) { + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl, + JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -42,8 +42,8 @@ protected RegistryClient createRestClientV3() { @Test public void testReadOperationWithNoRole() throws Exception { // Read-only operation should work with credentials but no role. - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrl, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl, + JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var results = client.search().artifacts().get(config -> config.queryParameters.groupId = groupId); diff --git a/app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java b/app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java index fe5d2b5460..1bc323dace 100644 --- a/app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java +++ b/app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java @@ -2,6 +2,7 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -20,6 +21,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; @@ -46,9 +48,9 @@ public class AuthTestLocalRoles extends AbstractResourceTestBase { String authServerUrlConfigured; @Override - protected RegistryClient createRestClientV3() { + protected RegistryClient createRestClientV3(Vertx vertx) { var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -65,13 +67,13 @@ protected RegistryClient createRestClientV3() { @Test public void testLocalRoles() throws Exception { - var adapterAdmin = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + var adapterAdmin = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapterAdmin.setBaseUrl(registryV3ApiUrl); RegistryClient clientAdmin = new RegistryClient(adapterAdmin); - var adapterAuth = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); + var adapterAuth = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); adapterAuth.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapterAuth); diff --git a/app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java b/app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java index 030075584d..c37702ba02 100644 --- a/app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java +++ b/app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java @@ -2,6 +2,7 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -19,12 +20,12 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,17 +41,17 @@ public class AuthTestNoRoles extends AbstractResourceTestBase { final String groupId = "authTestGroupId"; @Override - protected RegistryClient createRestClientV3() { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + protected RegistryClient createRestClientV3(Vertx vertx) { + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @Test public void testWrongCreds() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var exception = Assertions.assertThrows(Exception.class, () -> { @@ -61,8 +62,8 @@ public void testWrongCreds() throws Exception { @Test public void testAdminRole() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); diff --git a/app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java b/app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java index 2392ed8e09..f035caf0cf 100644 --- a/app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java +++ b/app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java @@ -2,7 +2,6 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -20,6 +19,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; @@ -41,9 +41,9 @@ public class AuthTestProfileBasicClientCredentials extends AbstractResourceTestB final String groupId = "authTestGroupId"; @Override - protected RegistryClient createRestClientV3() { + protected RegistryClient createRestClientV3(Vertx vertx) { var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -51,7 +51,7 @@ protected RegistryClient createRestClientV3() { @Test public void testWrongCreds() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); + buildSimpleAuthWebClient(vertx, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var exception = Assertions.assertThrows(Exception.class, () -> { @@ -63,7 +63,7 @@ public void testWrongCreds() throws Exception { @Test public void testBasicAuthClientCredentials() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + buildSimpleAuthWebClient(vertx, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -99,7 +99,7 @@ public void testBasicAuthClientCredentials() throws Exception { @Test public void testNoCredentials() throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var exception = Assertions.assertThrows(Exception.class, () -> { diff --git a/app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java b/app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java index e71a25d452..6d4009e931 100644 --- a/app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java +++ b/app/src/test/java/io/apicurio/registry/auth/BasicAuthWithPropertiesTest.java @@ -20,6 +20,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -51,8 +52,9 @@ public class BasicAuthWithPropertiesTest extends AbstractResourceTestBase { public static final String READONLY_PASSWORD = "duncan"; @Override - protected RegistryClient createRestClientV3() { - var adapter = new VertXRequestAdapter(buildSimpleAuthWebClient(ADMIN_USERNAME, ADMIN_PASSWORD)); + protected RegistryClient createRestClientV3(Vertx vertx) { + var adapter = new VertXRequestAdapter( + buildSimpleAuthWebClient(vertx, ADMIN_USERNAME, ADMIN_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -75,7 +77,7 @@ protected void assertArtifactNotFound(Exception exception) { @Test public void testWrongCreds() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(UUID.randomUUID().toString(), UUID.randomUUID().toString())); + buildSimpleAuthWebClient(vertx, UUID.randomUUID().toString(), UUID.randomUUID().toString())); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var exception = Assertions.assertThrows(ApiException.class, () -> { @@ -86,7 +88,8 @@ public void testWrongCreds() throws Exception { @Test public void testReadOnly() throws Exception { - var adapter = new VertXRequestAdapter(buildSimpleAuthWebClient(READONLY_USERNAME, READONLY_PASSWORD)); + var adapter = new VertXRequestAdapter( + buildSimpleAuthWebClient(vertx, READONLY_USERNAME, READONLY_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -107,7 +110,7 @@ public void testReadOnly() throws Exception { assertForbidden(exception3); var devAdapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); devAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient devClient = new RegistryClient(devAdapter); @@ -130,7 +133,7 @@ public void testReadOnly() throws Exception { @Test public void testDevRole() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -168,7 +171,8 @@ public void testDevRole() throws Exception { @Test public void testAdminRole() throws Exception { - var adapter = new VertXRequestAdapter(buildSimpleAuthWebClient(ADMIN_USERNAME, ADMIN_PASSWORD)); + var adapter = new VertXRequestAdapter( + buildSimpleAuthWebClient(vertx, ADMIN_USERNAME, ADMIN_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -204,11 +208,12 @@ public void testAdminRole() throws Exception { @Test public void testOwnerOnlyAuthorization() throws Exception { var devAdapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); devAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient clientDev = new RegistryClient(devAdapter); - var adminAdapter = new VertXRequestAdapter(buildSimpleAuthWebClient(ADMIN_USERNAME, ADMIN_PASSWORD)); + var adminAdapter = new VertXRequestAdapter( + buildSimpleAuthWebClient(vertx, ADMIN_USERNAME, ADMIN_PASSWORD)); adminAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient clientAdmin = new RegistryClient(adminAdapter); @@ -244,7 +249,7 @@ public void testOwnerOnlyAuthorization() throws Exception { @Test public void testGetArtifactOwner() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); @@ -273,7 +278,7 @@ public void testGetArtifactOwner() throws Exception { @Test public void testUpdateArtifactOwner() throws Exception { var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); @@ -319,11 +324,11 @@ public void testUpdateArtifactOwner() throws Exception { @Test public void testUpdateArtifactOwnerOnlyByOwner() throws Exception { var adapter_dev1 = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_USERNAME, DEVELOPER_PASSWORD)); adapter_dev1.setBaseUrl(registryV3ApiUrl); RegistryClient client_dev1 = new RegistryClient(adapter_dev1); var adapter_dev2 = new VertXRequestAdapter( - buildSimpleAuthWebClient(DEVELOPER_2_USERNAME, DEVELOPER_2_PASSWORD)); + buildSimpleAuthWebClient(vertx, DEVELOPER_2_USERNAME, DEVELOPER_2_PASSWORD)); adapter_dev2.setBaseUrl(registryV3ApiUrl); RegistryClient client_dev2 = new RegistryClient(adapter_dev2); diff --git a/app/src/test/java/io/apicurio/registry/auth/HeaderRoleSourceTest.java b/app/src/test/java/io/apicurio/registry/auth/HeaderRoleSourceTest.java index 3c65b93f71..37b35dc2d3 100644 --- a/app/src/test/java/io/apicurio/registry/auth/HeaderRoleSourceTest.java +++ b/app/src/test/java/io/apicurio/registry/auth/HeaderRoleSourceTest.java @@ -2,6 +2,7 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -15,6 +16,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; @@ -38,9 +40,9 @@ public class HeaderRoleSourceTest extends AbstractResourceTestBase { String authServerUrlConfigured; @Override - protected RegistryClient createRestClientV3() { + protected RegistryClient createRestClientV3(Vertx vertx) { var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -54,23 +56,23 @@ public void testLocalRoles() throws Exception { rule.setConfig(ValidityLevel.FULL.name()); rule.setRuleType(io.apicurio.registry.rest.client.models.RuleType.VALIDITY); - var noRoleAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); + var noRoleAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")); noRoleAdapter.setBaseUrl(registryV3ApiUrl); var noRoleClient = new RegistryClient(noRoleAdapter); - var readAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.READONLY_CLIENT_ID, "test1")); + var readAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.READONLY_CLIENT_ID, "test1")); readAdapter.setBaseUrl(registryV3ApiUrl); var readClient = new RegistryClient(readAdapter); - var devAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var devAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); devAdapter.setBaseUrl(registryV3ApiUrl); var devClient = new RegistryClient(devAdapter); - var adminAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + var adminAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adminAdapter.setBaseUrl(registryV3ApiUrl); var adminClient = new RegistryClient(adminAdapter); diff --git a/app/src/test/java/io/apicurio/registry/auth/MojoAuthTest.java b/app/src/test/java/io/apicurio/registry/auth/MojoAuthTest.java index cefecf5651..5a9c837156 100644 --- a/app/src/test/java/io/apicurio/registry/auth/MojoAuthTest.java +++ b/app/src/test/java/io/apicurio/registry/auth/MojoAuthTest.java @@ -1,6 +1,7 @@ package io.apicurio.registry.auth; import io.apicurio.common.apps.config.Info; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.maven.RegisterRegistryMojo; import io.apicurio.registry.noprofile.maven.RegistryMojoTestBase; import io.apicurio.registry.rest.client.RegistryClient; @@ -11,6 +12,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.eclipse.microprofile.config.inject.ConfigProperty; @@ -19,8 +21,6 @@ import java.io.IOException; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; - @QuarkusTest @TestProfile(AuthTestProfile.class) @Tag(ApicurioTestTags.SLOW) @@ -42,9 +42,9 @@ public class MojoAuthTest extends RegistryMojoTestBase { String testPassword = "sr-test-password"; @Override - protected RegistryClient createRestClientV3() { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + protected RegistryClient createRestClientV3(Vertx vertx) { + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -68,8 +68,6 @@ public void testBasicAuth() throws IOException, MojoFailureException, MojoExecut System.out.println("Auth is " + authEnabled); RegisterRegistryMojo registerRegistryMojo = new RegisterRegistryMojo(); - registerRegistryMojo.setClient(null); - registerRegistryMojo.setRegistryUrl(TestUtils.getRegistryV3ApiUrl(testPort)); registerRegistryMojo.setUsername(testUsername); registerRegistryMojo.setPassword(testPassword); diff --git a/app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java b/app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java index e0f1d77589..471ad430e6 100644 --- a/app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java +++ b/app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java @@ -2,6 +2,7 @@ import io.apicurio.common.apps.config.Info; import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.ArtifactMetaData; import io.apicurio.registry.rest.client.models.CreateArtifact; @@ -31,8 +32,6 @@ import java.util.UUID; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildSimpleAuthWebClient; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -52,9 +51,9 @@ public class SimpleAuthTest extends AbstractResourceTestBase { final String groupId = "authTestGroupId"; @Override - protected RegistryClient createRestClientV3() { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + protected RegistryClient createRestClientV3(Vertx vertx) { + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); return new RegistryClient(adapter); } @@ -81,8 +80,8 @@ protected void assertArtifactNotFound(Exception exception) { @Test public void testWrongCreds() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); var exception = Assertions.assertThrows(Exception.class, () -> { @@ -103,8 +102,8 @@ public void testNoCreds() throws Exception { @Test public void testReadOnly() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.READONLY_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.READONLY_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -127,8 +126,8 @@ public void testReadOnly() throws Exception { config.queryParameters.dryRun = true; }); - var devAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var devAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); devAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient devClient = new RegistryClient(devAdapter); @@ -151,8 +150,8 @@ public void testReadOnly() throws Exception { @Test public void testDevRole() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -190,8 +189,8 @@ public void testDevRole() throws Exception { @Test public void testAdminRole() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -226,8 +225,8 @@ public void testAdminRole() throws Exception { @Test public void testAdminRoleBasicAuth() throws Exception { - var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(JWKSMockServer.BASIC_USER, JWKSMockServer.BASIC_PASSWORD)); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildSimpleAuthWebClient(vertx, + JWKSMockServer.BASIC_USER, JWKSMockServer.BASIC_PASSWORD)); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -255,8 +254,8 @@ public void testAdminRoleBasicAuth() throws Exception { @Test public void testAdminRoleBasicAuthWrongCreds() throws Exception { - var adapter = new VertXRequestAdapter( - buildSimpleAuthWebClient(JWKSMockServer.WRONG_CREDS_CLIENT_ID, UUID.randomUUID().toString())); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildSimpleAuthWebClient(vertx, + JWKSMockServer.WRONG_CREDS_CLIENT_ID, UUID.randomUUID().toString())); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -274,13 +273,13 @@ public void testAdminRoleBasicAuthWrongCreds() throws Exception { @Test public void testOwnerOnlyAuthorization() throws Exception { - var devAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var devAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); devAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient clientDev = new RegistryClient(devAdapter); - var adminAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + var adminAdapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adminAdapter.setBaseUrl(registryV3ApiUrl); RegistryClient clientAdmin = new RegistryClient(adminAdapter); @@ -315,8 +314,8 @@ public void testOwnerOnlyAuthorization() throws Exception { @Test public void testGetArtifactOwner() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); @@ -344,8 +343,8 @@ public void testGetArtifactOwner() throws Exception { @Test public void testUpdateArtifactOwner() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); adapter.setBaseUrl(registryV3ApiUrl); RegistryClient client = new RegistryClient(adapter); @@ -388,12 +387,12 @@ public void testUpdateArtifactOwner() throws Exception { @Test public void testUpdateArtifactOwnerOnlyByOwner() throws Exception { - var adapter_dev1 = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var adapter_dev1 = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); adapter_dev1.setBaseUrl(registryV3ApiUrl); RegistryClient client_dev1 = new RegistryClient(adapter_dev1); - var adapter_dev2 = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_2_CLIENT_ID, "test1")); + var adapter_dev2 = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, + authServerUrlConfigured, JWKSMockServer.DEVELOPER_2_CLIENT_ID, "test1")); adapter_dev2.setBaseUrl(registryV3ApiUrl); RegistryClient client_dev2 = new RegistryClient(adapter_dev2); diff --git a/app/src/test/java/io/apicurio/registry/noprofile/resolver/SchemaResolverTest.java b/app/src/test/java/io/apicurio/registry/noprofile/resolver/SchemaResolverTest.java index 2d32bc92e8..6b0b08c343 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/resolver/SchemaResolverTest.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/resolver/SchemaResolverTest.java @@ -1,9 +1,11 @@ package io.apicurio.registry.noprofile.resolver; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; -import io.apicurio.registry.resolver.*; +import io.apicurio.registry.resolver.DefaultSchemaResolver; +import io.apicurio.registry.resolver.ParsedSchema; +import io.apicurio.registry.resolver.SchemaParser; +import io.apicurio.registry.resolver.SchemaResolver; import io.apicurio.registry.resolver.data.Metadata; import io.apicurio.registry.resolver.data.Record; import io.apicurio.registry.resolver.strategy.ArtifactReference; @@ -34,7 +36,7 @@ public class SchemaResolverTest extends AbstractResourceTestBase { @BeforeEach public void createIsolatedClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(TestUtils.getRegistryV3ApiUrl(testPort)); restClient = new RegistryClient(adapter); } diff --git a/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/impexp/ExportLoader.java b/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/impexp/ExportLoader.java index 0695d5dbbb..755f181a0e 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/impexp/ExportLoader.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/impexp/ExportLoader.java @@ -1,6 +1,5 @@ package io.apicurio.registry.noprofile.rest.v3.impexp; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rbac.AdminResourceTest; import io.apicurio.registry.rest.client.RegistryClient; @@ -12,6 +11,7 @@ import io.apicurio.registry.types.ContentTypes; import io.apicurio.registry.utils.tests.TestUtils; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import java.util.UUID; @@ -25,39 +25,44 @@ public class ExportLoader { + " \"description\": \"An example API design using OpenAPI.\"\r\n" + " }\r\n" + "}"; public static void main(String[] args) throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl("http://localhost:8080/apis/registry/v3"); RegistryClient client = new RegistryClient(adapter); - for (int idx = 0; idx < 1000; idx++) { - System.out.println("Iteration: " + idx); - String data = CONTENT.replace("1.0.0", "1.0." + idx); - String artifactId = UUID.randomUUID().toString(); - CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.OPENAPI, - data, ContentTypes.APPLICATION_JSON); - client.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts() - .post(createArtifact); - client.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts() - .byArtifactId(artifactId).delete(); - } + try { + for (int idx = 0; idx < 1000; idx++) { + System.out.println("Iteration: " + idx); + String data = CONTENT.replace("1.0.0", "1.0." + idx); + String artifactId = UUID.randomUUID().toString(); + CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, + ArtifactType.OPENAPI, data, ContentTypes.APPLICATION_JSON); + client.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts() + .post(createArtifact); + client.groups().byGroupId(GroupId.DEFAULT.getRawGroupIdWithDefaultString()).artifacts() + .byArtifactId(artifactId).delete(); + } - String testContent = CONTENT.replace("Empty API", "Test Artifact"); + String testContent = CONTENT.replace("Empty API", "Test Artifact"); - createVersion(client, "Artifact-1", "1.0.1"); - createVersion(client, "Artifact-1", "1.0.2"); - createVersion(client, "Artifact-1", "1.0.3"); - createVersion(client, "Artifact-2", "1.0.1"); - createVersion(client, "Artifact-3", "1.0.2"); + createVersion(client, "Artifact-1", "1.0.1"); + createVersion(client, "Artifact-1", "1.0.2"); + createVersion(client, "Artifact-1", "1.0.3"); + createVersion(client, "Artifact-2", "1.0.1"); + createVersion(client, "Artifact-3", "1.0.2"); - CreateRule createRule = new CreateRule(); - createRule.setRuleType(RuleType.VALIDITY); - createRule.setConfig("SYNTAX_ONLY"); - client.groups().byGroupId("ImportTest").artifacts().byArtifactId("Artifact-1").rules() - .post(createRule); + CreateRule createRule = new CreateRule(); + createRule.setRuleType(RuleType.VALIDITY); + createRule.setConfig("SYNTAX_ONLY"); + client.groups().byGroupId("ImportTest").artifacts().byArtifactId("Artifact-1").rules() + .post(createRule); - createRule = new CreateRule(); - createRule.setRuleType(RuleType.COMPATIBILITY); - createRule.setConfig("BACKWARD"); - client.admin().rules().post(createRule); + createRule = new CreateRule(); + createRule.setRuleType(RuleType.COMPATIBILITY); + createRule.setConfig("BACKWARD"); + client.admin().rules().post(createRule); + } finally { + vertx.close(); + } } private static void createVersion(RegistryClient client, String artifactId, String version) { diff --git a/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroPulsarSerdeTest.java b/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroPulsarSerdeTest.java index ec201406ca..bd93f18ead 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroPulsarSerdeTest.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroPulsarSerdeTest.java @@ -1,7 +1,6 @@ package io.apicurio.registry.noprofile.serde; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.resolver.strategy.ArtifactReferenceResolverStrategy; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.VersionMetaData; @@ -34,7 +33,7 @@ public class AvroPulsarSerdeTest extends AbstractResourceTestBase { @BeforeEach public void createIsolatedClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(TestUtils.getRegistryV3ApiUrl(testPort)); restClient = new RegistryClient(adapter); } diff --git a/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroSerdeTest.java b/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroSerdeTest.java index a1f67d4a50..56658a8028 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroSerdeTest.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/serde/AvroSerdeTest.java @@ -11,7 +11,6 @@ import com.kubetrade.schema.trade.AvroSchemaE; import com.kubetrade.schema.trade.AvroSchemaF; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.resolver.strategy.ArtifactReferenceResolverStrategy; import io.apicurio.registry.rest.client.RegistryClient; @@ -74,7 +73,7 @@ public class AvroSerdeTest extends AbstractResourceTestBase { @BeforeEach public void createIsolatedClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(TestUtils.getRegistryV3ApiUrl(testPort)); restClient = new RegistryClient(adapter); } diff --git a/app/src/test/java/io/apicurio/registry/noprofile/serde/JsonSchemaSerdeTest.java b/app/src/test/java/io/apicurio/registry/noprofile/serde/JsonSchemaSerdeTest.java index 94015f749f..24c982a261 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/serde/JsonSchemaSerdeTest.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/serde/JsonSchemaSerdeTest.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.networknt.schema.JsonSchema; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.resolver.DefaultSchemaResolver; import io.apicurio.registry.resolver.ParsedSchema; import io.apicurio.registry.resolver.SchemaResolver; @@ -64,7 +63,7 @@ public class JsonSchemaSerdeTest extends AbstractResourceTestBase { @BeforeEach public void createIsolatedClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(TestUtils.getRegistryV3ApiUrl(testPort)); restClient = new RegistryClient(adapter); } @@ -736,7 +735,7 @@ public void testWithReferencesDeserializerDereferencedComplexUsecase() throws Ex public void complexObjectValidation() throws Exception { final String version = "8"; - RegistryClient client = createRestClientV3(); + RegistryClient client = clientV3; InputStream account = getClass().getClassLoader() .getResourceAsStream("/io/apicurio/registry/util/sample.account.json"); diff --git a/app/src/test/java/io/apicurio/registry/noprofile/serde/ProtobufSerdeTest.java b/app/src/test/java/io/apicurio/registry/noprofile/serde/ProtobufSerdeTest.java index c26801c943..b61fe0afef 100644 --- a/app/src/test/java/io/apicurio/registry/noprofile/serde/ProtobufSerdeTest.java +++ b/app/src/test/java/io/apicurio/registry/noprofile/serde/ProtobufSerdeTest.java @@ -4,7 +4,6 @@ import com.google.protobuf.DynamicMessage; import io.api.sample.TableNotification; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.VersionMetaData; import io.apicurio.registry.serde.config.SerdeConfig; @@ -36,7 +35,7 @@ public class ProtobufSerdeTest extends AbstractResourceTestBase { @BeforeEach public void createIsolatedClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(TestUtils.getRegistryV3ApiUrl(testPort)); restClient = new RegistryClient(adapter); } diff --git a/app/src/test/java/io/apicurio/registry/rbac/RegistryClientTest.java b/app/src/test/java/io/apicurio/registry/rbac/RegistryClientTest.java index bc98428fa9..9a3d534a38 100644 --- a/app/src/test/java/io/apicurio/registry/rbac/RegistryClientTest.java +++ b/app/src/test/java/io/apicurio/registry/rbac/RegistryClientTest.java @@ -3,7 +3,6 @@ import com.microsoft.kiota.ApiException; import io.apicurio.registry.AbstractRegistryTestBase; import io.apicurio.registry.AbstractResourceTestBase; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.GroupId; import io.apicurio.registry.rest.client.models.ArtifactMetaData; import io.apicurio.registry.rest.client.models.ArtifactReference; @@ -1570,7 +1569,7 @@ public void testClientRateLimitProblemDetails() { TooManyRequestsMock mock = new TooManyRequestsMock(); mock.start(); try { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(mock.getMockUrl()); io.apicurio.registry.rest.client.RegistryClient client = new io.apicurio.registry.rest.client.RegistryClient( adapter); diff --git a/docs/modules/ROOT/partials/getting-started/proc-writing-registry-sdk.adoc b/docs/modules/ROOT/partials/getting-started/proc-writing-registry-sdk.adoc index 01bb8f215e..56345a75f8 100644 --- a/docs/modules/ROOT/partials/getting-started/proc-writing-registry-sdk.adoc +++ b/docs/modules/ROOT/partials/getting-started/proc-writing-registry-sdk.adoc @@ -29,21 +29,28 @@ You can write a client application to manage artifacts stored in {registry} by u + [source,java,subs="+quotes,attributes"] ---- -public class ClientExample { +import io.vertx.core.Vertx;public class ClientExample { public static void main(String[] args) throws Exception { - // Create a registry client - String registryUrl = "https://my-registry.my-domain.com/apis/registry/v3"; <1> - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); - vertXRequestAdapter.setBaseUrl(REGISTRY_URL); + // Create a registry client + String registryUrl = "https://my-registry.my-domain.com/apis/registry/v3"; <1> + Vertx vertx = Vertx.vertx(); <2> + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); + vertXRequestAdapter.setBaseUrl(REGISTRY_URL); - RegistryClient client = new RegistryClient(vertXRequestAdapter); <2> + RegistryClient client = new RegistryClient(vertXRequestAdapter); <3> + + // Use client here + + vertx.close(); <4> } } ---- + <1> If you specify an example {registry} URL of `\https://my-registry.my-domain.com`, the client will automatically append `/apis/registry/v3`. -<2> For more options when creating a {registry} client, see the Java client configuration in the next section. +<2> Create a new Vertx object (needed by the VertxRequestAdapter) +<3> For more options when creating a {registry} client, see the Java client configuration in the next section. +<4> When you are done with the client, close the Vertx object to free its resources. When the client is created, you can use all of the operations available in the {registry} REST API in the client. For more details, see the {registry-rest-api}. diff --git a/examples/custom-strategy/src/main/java/io/apicurio/registry/examples/custom/strategy/CustomStrategyExample.java b/examples/custom-strategy/src/main/java/io/apicurio/registry/examples/custom/strategy/CustomStrategyExample.java index 767a834825..22ecaa3892 100644 --- a/examples/custom-strategy/src/main/java/io/apicurio/registry/examples/custom/strategy/CustomStrategyExample.java +++ b/examples/custom-strategy/src/main/java/io/apicurio/registry/examples/custom/strategy/CustomStrategyExample.java @@ -16,7 +16,6 @@ package io.apicurio.registry.examples.custom.strategy; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateVersion; @@ -27,6 +26,7 @@ import io.apicurio.registry.serde.config.SerdeConfig; import io.apicurio.registry.types.ArtifactType; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; @@ -72,7 +72,8 @@ public static final void main(String[] args) throws Exception { String topicName = Config.TOPIC_NAME; String subjectName = Config.SUBJECT_NAME; - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(Config.REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); @@ -150,7 +151,7 @@ public static final void main(String[] args) throws Exception { consumer.close(); } - VertXAuthFactory.defaultVertx.close(); + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/jsonschema-validation/src/main/java/io/apicurio/registry/examples/validation/json/JsonSchemaValidationExample.java b/examples/jsonschema-validation/src/main/java/io/apicurio/registry/examples/validation/json/JsonSchemaValidationExample.java index 1edae168b4..2f7f5c80d9 100644 --- a/examples/jsonschema-validation/src/main/java/io/apicurio/registry/examples/validation/json/JsonSchemaValidationExample.java +++ b/examples/jsonschema-validation/src/main/java/io/apicurio/registry/examples/validation/json/JsonSchemaValidationExample.java @@ -16,6 +16,7 @@ package io.apicurio.registry.examples.validation.json; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.resolver.config.SchemaResolverConfig; import io.apicurio.registry.resolver.strategy.ArtifactReference; import io.apicurio.registry.rest.client.RegistryClient; @@ -30,6 +31,7 @@ import io.apicurio.schema.validation.json.JsonValidationResult; import io.apicurio.schema.validation.json.JsonValidator; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import java.nio.charset.StandardCharsets; import java.util.Date; @@ -37,9 +39,6 @@ import java.util.Map; import java.util.Optional; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; -import static io.apicurio.registry.client.auth.VertXAuthFactory.defaultVertx; - /** * This example demonstrates how to use Apicurio Registry Schema Validation library for JSON and JSON Schema. *

@@ -75,10 +74,11 @@ public class JsonSchemaValidationExample { public static final void main(String[] args) throws Exception { System.out.println("Starting example " + JsonSchemaValidationExample.class.getSimpleName()); + Vertx vertx = Vertx.vertx(); // Register the schema with the registry (only if it is not already registered) String artifactId = JsonSchemaValidationExample.class.getSimpleName(); - RegistryClient client = createRegistryClient(REGISTRY_URL); + RegistryClient client = createRegistryClient(vertx, REGISTRY_URL); CreateArtifact createArtifact = new CreateArtifact(); createArtifact.setArtifactId(artifactId); @@ -135,24 +135,25 @@ public static final void main(String[] args) throws Exception { JsonValidationResult recordValidationResult = validator.validate(record); System.out.println("Validation result: " + recordValidationResult); System.out.println(); - + vertx.close(); } /** * Creates the registry client */ - private static RegistryClient createRegistryClient(String registryUrl) { + private static RegistryClient createRegistryClient(Vertx vertx, String registryUrl) { final String tokenEndpoint = System.getenv(SchemaResolverConfig.AUTH_TOKEN_ENDPOINT); // Just if security values are present, then we configure them. if (tokenEndpoint != null) { final String authClient = System.getenv(SchemaResolverConfig.AUTH_CLIENT_ID); final String authSecret = System.getenv(SchemaResolverConfig.AUTH_CLIENT_SECRET); - var adapter = new VertXRequestAdapter(buildOIDCWebClient(tokenEndpoint, authClient, authSecret)); + var adapter = new VertXRequestAdapter( + VertXAuthFactory.buildOIDCWebClient(vertx, tokenEndpoint, authClient, authSecret)); adapter.setBaseUrl(registryUrl); return new RegistryClient(adapter); } else { - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(defaultVertx); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(registryUrl); return new RegistryClient(vertXRequestAdapter); } diff --git a/examples/protobuf-bean/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufBeanExample.java b/examples/protobuf-bean/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufBeanExample.java index 0cf535ea27..5cebe38b53 100644 --- a/examples/protobuf-bean/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufBeanExample.java +++ b/examples/protobuf-bean/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufBeanExample.java @@ -16,7 +16,6 @@ package io.apicurio.registry.examples.simple.protobuf; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.examples.AddressBookProtos; import io.apicurio.registry.examples.AddressBookProtos.AddressBook; import io.apicurio.registry.examples.AddressBookProtos.Person; @@ -26,6 +25,7 @@ import io.apicurio.registry.serde.protobuf.ProtobufKafkaSerializer; import io.apicurio.registry.utils.IoUtil; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -126,7 +126,8 @@ public static final void main(String[] args) throws Exception { consumer.close(); } - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); System.out.println("The artifact created in Apicurio Registry is: "); @@ -135,7 +136,7 @@ public static final void main(String[] args) throws Exception { System.out.println(IoUtil.toString(client.groups().byGroupId("default").artifacts() .byArtifactId(topicName + "-value").versions().byVersionExpression("1").content().get())); System.out.println(); - VertXAuthFactory.defaultVertx.close(); + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/protobuf-find-latest/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufFindLatestExample.java b/examples/protobuf-find-latest/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufFindLatestExample.java index f497ba78c9..e0ea476c5c 100644 --- a/examples/protobuf-find-latest/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufFindLatestExample.java +++ b/examples/protobuf-find-latest/src/main/java/io/apicurio/registry/examples/simple/protobuf/ProtobufFindLatestExample.java @@ -16,7 +16,6 @@ package io.apicurio.registry.examples.simple.protobuf; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.examples.AddressBookProtos; import io.apicurio.registry.examples.AddressBookProtos.AddressBook; import io.apicurio.registry.examples.AddressBookProtos.Person; @@ -32,6 +31,7 @@ import io.apicurio.registry.types.ContentTypes; import io.apicurio.registry.utils.IoUtil; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -81,7 +81,8 @@ public static final void main(String[] args) throws Exception { String topicName = TOPIC_NAME; String key = SCHEMA_NAME; - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); System.out.println("Manually creating the artifact in Apicurio Registry"); @@ -161,6 +162,7 @@ public static final void main(String[] args) throws Exception { consumer.close(); } + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/protobuf-validation/src/main/java/io/apicurio/registry/examples/validation/protobuf/ProtobufValidationExample.java b/examples/protobuf-validation/src/main/java/io/apicurio/registry/examples/validation/protobuf/ProtobufValidationExample.java index d879580f07..67fa81ab0f 100644 --- a/examples/protobuf-validation/src/main/java/io/apicurio/registry/examples/validation/protobuf/ProtobufValidationExample.java +++ b/examples/protobuf-validation/src/main/java/io/apicurio/registry/examples/validation/protobuf/ProtobufValidationExample.java @@ -16,6 +16,7 @@ package io.apicurio.registry.examples.validation.protobuf; +import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.resolver.config.SchemaResolverConfig; import io.apicurio.registry.resolver.strategy.ArtifactReference; import io.apicurio.registry.rest.client.RegistryClient; @@ -32,6 +33,7 @@ import io.apicurio.schema.validation.protobuf.ProtobufValidator; import io.apicurio.schema.validation.protobuf.ref.MessageExampleOuterClass.MessageExample; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -39,8 +41,6 @@ import java.util.Optional; import java.util.UUID; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; -import static io.apicurio.registry.client.auth.VertXAuthFactory.defaultVertx; import static io.apicurio.schema.validation.protobuf.ref.MessageExample2OuterClass.MessageExample2; /** @@ -74,10 +74,11 @@ public class ProtobufValidationExample { public static final void main(String[] args) throws Exception { System.out.println("Starting example " + ProtobufValidationExample.class.getSimpleName()); + Vertx vertx = Vertx.vertx(); // Register the schema with the registry (only if it is not already registered) String artifactId = ProtobufValidationExample.class.getSimpleName(); - RegistryClient client = createRegistryClient(REGISTRY_URL); + RegistryClient client = createRegistryClient(vertx, REGISTRY_URL); CreateArtifact createArtifact = new CreateArtifact(); createArtifact.setArtifactId(artifactId); @@ -132,24 +133,25 @@ public static final void main(String[] args) throws Exception { ProtobufValidationResult recordValidationResult = validator.validate(record); System.out.println("Validation result: " + recordValidationResult); System.out.println(); - defaultVertx.close(); + vertx.close(); } /** * Creates the registry client */ - private static RegistryClient createRegistryClient(String registryUrl) { + private static RegistryClient createRegistryClient(Vertx vertx, String registryUrl) { final String tokenEndpoint = System.getenv(SchemaResolverConfig.AUTH_TOKEN_ENDPOINT); // Just if security values are present, then we configure them. if (tokenEndpoint != null) { final String authClient = System.getenv(SchemaResolverConfig.AUTH_CLIENT_ID); final String authSecret = System.getenv(SchemaResolverConfig.AUTH_CLIENT_SECRET); - var adapter = new VertXRequestAdapter(buildOIDCWebClient(tokenEndpoint, authClient, authSecret)); + var adapter = new VertXRequestAdapter( + VertXAuthFactory.buildOIDCWebClient(vertx, tokenEndpoint, authClient, authSecret)); adapter.setBaseUrl(registryUrl); return new RegistryClient(adapter); } else { - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(defaultVertx); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(registryUrl); return new RegistryClient(vertXRequestAdapter); } diff --git a/examples/rest-client/src/main/java/io/apicurio/registry/examples/RegistryLoader.java b/examples/rest-client/src/main/java/io/apicurio/registry/examples/RegistryLoader.java index b9ec304ec8..106863713c 100644 --- a/examples/rest-client/src/main/java/io/apicurio/registry/examples/RegistryLoader.java +++ b/examples/rest-client/src/main/java/io/apicurio/registry/examples/RegistryLoader.java @@ -16,7 +16,6 @@ package io.apicurio.registry.examples; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateRule; @@ -24,6 +23,7 @@ import io.apicurio.registry.rest.client.models.RuleType; import io.apicurio.registry.rest.client.models.VersionContent; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import java.util.UUID; @@ -35,7 +35,8 @@ public class RegistryLoader { public static void main(String[] args) throws Exception { String registryUrl = "http://localhost:8080/apis/registry/v3"; - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(registryUrl); RegistryClient client = new RegistryClient(vertXRequestAdapter); @@ -51,6 +52,8 @@ public static void main(String[] args) throws Exception { Task task = new Task(simpleAvro, client, 100, i + 100); task.start(); } + + vertx.close(); } protected static class Task extends Thread { diff --git a/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemo.java b/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemo.java index 1f0509de64..6f4fb28e70 100644 --- a/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemo.java +++ b/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemo.java @@ -34,9 +34,6 @@ public static void main(String[] args) throws Exception { RegistryDemoUtil.createSchemaInServiceRegistry(client, artifactId, Constants.SCHEMA); - // Wait for the artifact to be available. - Thread.sleep(1000); - RegistryDemoUtil.getSchemaFromRegistry(client, artifactId); RegistryDemoUtil.deleteSchema(client, artifactId); @@ -49,7 +46,8 @@ public static RegistryClient createProperClient(String registryUrl) { if (tokenEndpoint != null) { final String authClient = System.getenv("AUTH_CLIENT_ID"); final String authSecret = System.getenv("AUTH_CLIENT_SECRET"); - var adapter = new VertXRequestAdapter(buildOIDCWebClient(tokenEndpoint, authClient, authSecret)); + var adapter = new VertXRequestAdapter( + buildOIDCWebClient(vertx, tokenEndpoint, authClient, authSecret)); adapter.setBaseUrl(registryUrl); return new RegistryClient(adapter); } else { diff --git a/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemoBasicAuth.java b/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemoBasicAuth.java index a0fdfccfe0..e347ecb2dd 100644 --- a/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemoBasicAuth.java +++ b/examples/rest-client/src/main/java/io/apicurio/registry/examples/SimpleRegistryDemoBasicAuth.java @@ -1,9 +1,9 @@ package io.apicurio.registry.examples; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.examples.util.RegistryDemoUtil; import io.apicurio.registry.rest.client.RegistryClient; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import java.util.UUID; @@ -19,6 +19,7 @@ public class SimpleRegistryDemoBasicAuth { private static final RegistryClient client; + private static final Vertx vertx = Vertx.vertx(); static { // Create a Service Registry client @@ -38,6 +39,7 @@ public static void main(String[] args) throws Exception { RegistryDemoUtil.getSchemaFromRegistry(client, artifactId); RegistryDemoUtil.deleteSchema(client, artifactId); + vertx.close(); } public static RegistryClient createProperClient(String registryUrl) { @@ -45,11 +47,11 @@ public static RegistryClient createProperClient(String registryUrl) { if (tokenEndpoint != null) { final String authClient = System.getenv("AUTH_CLIENT_ID"); final String authSecret = System.getenv("AUTH_CLIENT_SECRET"); - var adapter = new VertXRequestAdapter(buildSimpleAuthWebClient(authClient, authSecret)); + var adapter = new VertXRequestAdapter(buildSimpleAuthWebClient(vertx, authClient, authSecret)); adapter.setBaseUrl(registryUrl); return new RegistryClient(adapter); } else { - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(registryUrl); return new RegistryClient(vertXRequestAdapter); } diff --git a/examples/rest-client/src/main/java/io/apicurio/registry/examples/util/RegistryDemoUtil.java b/examples/rest-client/src/main/java/io/apicurio/registry/examples/util/RegistryDemoUtil.java index ee7b80a749..49b84c38f9 100644 --- a/examples/rest-client/src/main/java/io/apicurio/registry/examples/util/RegistryDemoUtil.java +++ b/examples/rest-client/src/main/java/io/apicurio/registry/examples/util/RegistryDemoUtil.java @@ -23,7 +23,7 @@ public class RegistryDemoUtil { * @param artifactId * @param schema */ - public static void createSchemaInServiceRegistry(RegistryClient service, String artifactId, + public static void createSchemaInServiceRegistry(RegistryClient registryClient, String artifactId, String schema) { LOGGER.info("---------------------------------------------------------"); @@ -40,7 +40,7 @@ public static void createSchemaInServiceRegistry(RegistryClient service, String createArtifact.getFirstVersion().getContent().setContent(IoUtil.toString(content)); createArtifact.getFirstVersion().getContent().setContentType("application/json"); - final io.apicurio.registry.rest.client.models.VersionMetaData metaData = service.groups() + final io.apicurio.registry.rest.client.models.VersionMetaData metaData = registryClient.groups() .byGroupId("default").artifacts().post(createArtifact, config -> { config.queryParameters.ifExists = IfArtifactExists.FIND_OR_CREATE_VERSION; }).getVersion(); diff --git a/examples/serdes-with-references/src/main/java/io/apicurio/registry/examples/references/JsonSerdeReferencesExample.java b/examples/serdes-with-references/src/main/java/io/apicurio/registry/examples/references/JsonSerdeReferencesExample.java index 96087134c6..6843abb437 100644 --- a/examples/serdes-with-references/src/main/java/io/apicurio/registry/examples/references/JsonSerdeReferencesExample.java +++ b/examples/serdes-with-references/src/main/java/io/apicurio/registry/examples/references/JsonSerdeReferencesExample.java @@ -1,6 +1,5 @@ package io.apicurio.registry.examples.references; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.examples.references.model.Citizen; import io.apicurio.registry.examples.references.model.City; import io.apicurio.registry.rest.client.RegistryClient; @@ -16,6 +15,7 @@ import io.apicurio.registry.types.ArtifactType; import io.apicurio.registry.utils.IoUtil; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -41,8 +41,9 @@ public class JsonSerdeReferencesExample { private static final String TOPIC_NAME = JsonSerdeReferencesExample.class.getSimpleName(); private static final String SUBJECT_NAME = "Greeting"; - public static void main(String[] args) throws Exception { + private static final Vertx vertx = Vertx.vertx(); + public static void main(String[] args) throws Exception { System.out.println("Starting example " + JsonSerdeReferencesExample.class.getSimpleName()); String topicName = TOPIC_NAME; String subjectName = SUBJECT_NAME; @@ -151,6 +152,7 @@ public static void main(String[] args) throws Exception { consumer.close(); } + vertx.close(); System.out.println("Done (success)."); } @@ -250,11 +252,12 @@ private static RegistryClient createRegistryClient(String registryUrl) { if (tokenEndpoint != null) { final String authClient = System.getenv(SerdeConfig.AUTH_CLIENT_ID); final String authSecret = System.getenv(SerdeConfig.AUTH_CLIENT_SECRET); - var adapter = new VertXRequestAdapter(buildOIDCWebClient(tokenEndpoint, authClient, authSecret)); + var adapter = new VertXRequestAdapter( + buildOIDCWebClient(vertx, tokenEndpoint, authClient, authSecret)); adapter.setBaseUrl(registryUrl); return new RegistryClient(adapter); } else { - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); return new RegistryClient(vertXRequestAdapter); } diff --git a/examples/simple-avro-maven/src/main/java/io/apicurio/registry/examples/simple/avro/maven/SimpleAvroMavenExample.java b/examples/simple-avro-maven/src/main/java/io/apicurio/registry/examples/simple/avro/maven/SimpleAvroMavenExample.java index ca9be21d35..d10ce649bd 100644 --- a/examples/simple-avro-maven/src/main/java/io/apicurio/registry/examples/simple/avro/maven/SimpleAvroMavenExample.java +++ b/examples/simple-avro-maven/src/main/java/io/apicurio/registry/examples/simple/avro/maven/SimpleAvroMavenExample.java @@ -17,13 +17,13 @@ package io.apicurio.registry.examples.simple.avro.maven; import com.microsoft.kiota.ApiException; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.v2.beans.IfExists; import io.apicurio.registry.serde.avro.AvroKafkaDeserializer; import io.apicurio.registry.serde.avro.AvroKafkaSerializer; import io.apicurio.registry.serde.config.SerdeConfig; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.avro.Schema; import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; @@ -85,7 +85,8 @@ public static final void main(String[] args) throws Exception { String artifactId = topicName + "-value"; // Get the schema from the registry so we can use it to create GenericData.Records later - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); @@ -158,6 +159,7 @@ public static final void main(String[] args) throws Exception { consumer.close(); } + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/simple-json/src/main/java/io/apicurio/registry/examples/simple/json/SimpleJsonSchemaExample.java b/examples/simple-json/src/main/java/io/apicurio/registry/examples/simple/json/SimpleJsonSchemaExample.java index b3c255824f..d34c35ee1f 100644 --- a/examples/simple-json/src/main/java/io/apicurio/registry/examples/simple/json/SimpleJsonSchemaExample.java +++ b/examples/simple-json/src/main/java/io/apicurio/registry/examples/simple/json/SimpleJsonSchemaExample.java @@ -16,7 +16,6 @@ package io.apicurio.registry.examples.simple.json; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateVersion; @@ -29,6 +28,7 @@ import io.apicurio.registry.types.ArtifactType; import io.apicurio.registry.utils.IoUtil; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -91,7 +91,8 @@ public static void main(String[] args) throws Exception { String artifactId = TOPIC_NAME + "-value"; // use the topic name as the artifactId because we're going // to map topic name to artifactId later on. - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); @@ -165,6 +166,7 @@ public static void main(String[] args) throws Exception { consumer.close(); } + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/simple-protobuf/src/main/java/io/apicurio/registry/examples/simple/protobuf/SimpleProtobufExample.java b/examples/simple-protobuf/src/main/java/io/apicurio/registry/examples/simple/protobuf/SimpleProtobufExample.java index 3bfd1fc635..d4c125b7d4 100644 --- a/examples/simple-protobuf/src/main/java/io/apicurio/registry/examples/simple/protobuf/SimpleProtobufExample.java +++ b/examples/simple-protobuf/src/main/java/io/apicurio/registry/examples/simple/protobuf/SimpleProtobufExample.java @@ -17,7 +17,6 @@ package io.apicurio.registry.examples.simple.protobuf; import com.google.protobuf.DynamicMessage; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.examples.AddressBookProtos; import io.apicurio.registry.examples.AddressBookProtos.AddressBook; import io.apicurio.registry.examples.AddressBookProtos.Person; @@ -27,6 +26,7 @@ import io.apicurio.registry.serde.protobuf.ProtobufKafkaSerializer; import io.apicurio.registry.utils.IoUtil; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -125,7 +125,8 @@ public static final void main(String[] args) throws Exception { consumer.close(); } - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(REGISTRY_URL); RegistryClient client = new RegistryClient(vertXRequestAdapter); System.out.println("The artifact created in Apicurio Registry is: "); @@ -134,7 +135,7 @@ public static final void main(String[] args) throws Exception { System.out.println(IoUtil.toString(client.groups().byGroupId("default").artifacts() .byArtifactId(topicName + "-value").versions().byVersionExpression("1").content().get())); System.out.println(); - VertXAuthFactory.defaultVertx.close(); + vertx.close(); System.out.println("Done (success)."); } diff --git a/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/MessageValidator.java b/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/MessageValidator.java index 48fd003284..323a6d1961 100644 --- a/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/MessageValidator.java +++ b/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/MessageValidator.java @@ -16,9 +16,9 @@ package io.apicurio.registry.examples.simple.json; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.everit.json.schema.Schema; import org.everit.json.schema.ValidationException; import org.everit.json.schema.loader.SchemaLoader; @@ -44,11 +44,11 @@ public class MessageValidator { * @param group * @param artifactId */ - public MessageValidator(String registryUrl, String group, String artifactId) { + public MessageValidator(Vertx vertx, String registryUrl, String group, String artifactId) { this.group = group; this.artifactId = artifactId; - VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + VertXRequestAdapter vertXRequestAdapter = new VertXRequestAdapter(vertx); vertXRequestAdapter.setBaseUrl(registryUrl); this.client = new RegistryClient(vertXRequestAdapter); } diff --git a/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/SimpleValidationExample.java b/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/SimpleValidationExample.java index bc5954fde6..15ff06b0dc 100644 --- a/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/SimpleValidationExample.java +++ b/examples/simple-validation/src/main/java/io/apicurio/registry/examples/simple/json/SimpleValidationExample.java @@ -16,6 +16,7 @@ package io.apicurio.registry.examples.simple.json; +import io.vertx.core.Vertx; import org.everit.json.schema.ValidationException; import java.security.SecureRandom; @@ -48,6 +49,7 @@ public class SimpleValidationExample { public static final void main(String[] args) throws Exception { System.out.println("Starting example " + SimpleValidationExample.class.getSimpleName()); + Vertx vertx = Vertx.vertx(); // Start a mock broker SimpleBroker broker = new SimpleBroker(); @@ -59,7 +61,7 @@ public static final void main(String[] args) throws Exception { String artifactId = Optional.ofNullable(System.getenv("ARTIFACT_ID")).orElse(ARTIFACT_ID); // Create a message validator and message publisher - MessageValidator validator = new MessageValidator(registryUrl, group, artifactId); + MessageValidator validator = new MessageValidator(vertx, registryUrl, group, artifactId); MessagePublisher publisher = new MessagePublisher(); // Produce messages in a loop. @@ -83,6 +85,7 @@ public static final void main(String[] args) throws Exception { Thread.sleep(5000); } + vertx.close(); System.out.println("Done (success)."); } diff --git a/integration-tests/src/test/java/io/apicurio/deployment/KafkaSqlDeploymentManager.java b/integration-tests/src/test/java/io/apicurio/deployment/KafkaSqlDeploymentManager.java index 0258928516..33ae6f1faf 100644 --- a/integration-tests/src/test/java/io/apicurio/deployment/KafkaSqlDeploymentManager.java +++ b/integration-tests/src/test/java/io/apicurio/deployment/KafkaSqlDeploymentManager.java @@ -1,6 +1,5 @@ package io.apicurio.deployment; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateRule; @@ -12,6 +11,7 @@ import io.fabric8.kubernetes.api.model.apps.Deployment; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,7 +67,8 @@ private static void prepareSnapshotData(String registryBaseUrl) { // Create a bunch of artifacts and rules, so they're added to the snapshot. String simpleAvro = resourceToString("artifactTypes/avro/multi-field_v1.json"); - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(registryBaseUrl); RegistryClient client = new RegistryClient(adapter); @@ -101,6 +102,8 @@ private static void prepareSnapshotData(String registryBaseUrl) { client.groups().byGroupId("default").artifacts().byArtifactId(artifactId).rules() .post(createRule); } + + vertx.close(); } private static void deleteRegistryDeployment() { diff --git a/integration-tests/src/test/java/io/apicurio/tests/ApicurioRegistryBaseIT.java b/integration-tests/src/test/java/io/apicurio/tests/ApicurioRegistryBaseIT.java index 8651db2a96..a176ca890e 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/ApicurioRegistryBaseIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/ApicurioRegistryBaseIT.java @@ -2,7 +2,6 @@ import com.microsoft.kiota.ApiException; import io.apicurio.deployment.PortForwardManager; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateArtifactResponse; @@ -21,7 +20,9 @@ import io.restassured.RestAssured; import io.restassured.parsing.Parser; import io.restassured.response.Response; +import io.vertx.core.Vertx; import org.eclipse.microprofile.config.ConfigProvider; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayNameGeneration; @@ -80,28 +81,35 @@ public class ApicurioRegistryBaseIT implements TestSeparator, Constants { protected Function errorCodeExtractor = e -> ((ApiException) e) .getResponseStatusCode(); + protected Vertx vertx; protected RegistryClient registryClient; protected String authServerUrlConfigured; - protected RegistryClient createRegistryClient() { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + protected RegistryClient createRegistryClient(Vertx vertx) { + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(getRegistryV3ApiUrl()); return new RegistryClient(adapter); } @BeforeAll void prepareRestAssured() { + vertx = Vertx.vertx(); authServerUrlConfigured = Optional .ofNullable(ConfigProvider.getConfig().getConfigValue("quarkus.oidc.token-path").getValue()) .orElse("http://localhost:8090/realms/registry/protocol/openid-connect/token"); - registryClient = createRegistryClient(); + registryClient = createRegistryClient(vertx); RestAssured.baseURI = getRegistryV3ApiUrl(); logger.info("RestAssured configured with {}", RestAssured.baseURI); RestAssured.defaultParser = Parser.JSON; RestAssured.urlEncodingEnabled = false; } + @AfterAll + void closeVertx() { + vertx.close(); + } + private static String normalizeGroupId(String groupId) { return groupId != null ? groupId : "default"; // TODO } diff --git a/integration-tests/src/test/java/io/apicurio/tests/auth/SimpleAuthIT.java b/integration-tests/src/test/java/io/apicurio/tests/auth/SimpleAuthIT.java index a7dab987b3..8602405986 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/auth/SimpleAuthIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/auth/SimpleAuthIT.java @@ -19,6 +19,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusIntegrationTest; import io.quarkus.test.junit.TestProfile; +import io.vertx.core.Vertx; import io.vertx.ext.web.client.WebClient; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; @@ -45,8 +46,9 @@ public class SimpleAuthIT extends ApicurioRegistryBaseIT { } @Override - protected RegistryClient createRegistryClient() { - var auth = buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"); + protected RegistryClient createRegistryClient(Vertx vertx) { + var auth = buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, + "test1"); return createClient(auth); } @@ -58,7 +60,7 @@ private RegistryClient createClient(WebClient auth) { @Test public void testWrongCreds() throws Exception { - var auth = buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, + var auth = buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"); RegistryClient client = createClient(auth); var exception = Assertions.assertThrows(Exception.class, () -> { @@ -69,8 +71,8 @@ public void testWrongCreds() throws Exception { @Test public void testReadOnly() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.READONLY_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(buildOIDCWebClient(vertx, authServerUrlConfigured, + JWKSMockServer.READONLY_CLIENT_ID, "test1")); adapter.setBaseUrl(getRegistryV3ApiUrl()); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -89,8 +91,8 @@ public void testReadOnly() throws Exception { }); assertForbidden(exception3); - var devAdapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var devAdapter = new VertXRequestAdapter(buildOIDCWebClient(vertx, authServerUrlConfigured, + JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); devAdapter.setBaseUrl(getRegistryV3ApiUrl()); RegistryClient devClient = new RegistryClient(devAdapter); @@ -112,8 +114,8 @@ public void testReadOnly() throws Exception { @Test public void testDevRole() throws Exception { - var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); + var adapter = new VertXRequestAdapter(buildOIDCWebClient(vertx, authServerUrlConfigured, + JWKSMockServer.DEVELOPER_CLIENT_ID, "test1")); adapter.setBaseUrl(getRegistryV3ApiUrl()); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); @@ -153,7 +155,7 @@ public void testDevRole() throws Exception { @Test public void testAdminRole() throws Exception { var adapter = new VertXRequestAdapter( - buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); + buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1")); adapter.setBaseUrl(getRegistryV3ApiUrl()); RegistryClient client = new RegistryClient(adapter); String artifactId = TestUtils.generateArtifactId(); diff --git a/integration-tests/src/test/java/io/apicurio/tests/converters/RegistryConverterIT.java b/integration-tests/src/test/java/io/apicurio/tests/converters/RegistryConverterIT.java index 7d9bd328aa..cdcbe456bf 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/converters/RegistryConverterIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/converters/RegistryConverterIT.java @@ -200,7 +200,7 @@ public void testAvro() throws Exception { @Test public void testPrettyJson() throws Exception { - testJson(createRegistryClient(), new PrettyFormatStrategy(), input -> { + testJson(createRegistryClient(vertx), new PrettyFormatStrategy(), input -> { try { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(input); @@ -314,7 +314,7 @@ private static Struct buildTransactionStruct() { @Test public void testCompactJson() throws Exception { - testJson(createRegistryClient(), new CompactFormatStrategy(), input -> { + testJson(createRegistryClient(vertx), new CompactFormatStrategy(), input -> { ByteBuffer buffer = BaseSerde.getByteBuffer(input); return buffer.getInt(); }); diff --git a/integration-tests/src/test/java/io/apicurio/tests/migration/DataMigrationIT.java b/integration-tests/src/test/java/io/apicurio/tests/migration/DataMigrationIT.java index 56b4fa5071..3ace771e33 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/migration/DataMigrationIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/migration/DataMigrationIT.java @@ -1,6 +1,5 @@ package io.apicurio.tests.migration; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.ArtifactReference; import io.apicurio.registry.rest.client.models.ProblemDetails; @@ -12,6 +11,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.vertx.core.Vertx; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -50,32 +50,38 @@ public class DataMigrationIT extends ApicurioRegistryBaseIT { */ @Test public void migrate() throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(ApicurioRegistryBaseIT.getRegistryV3ApiUrl()); RegistryClient dest = new RegistryClient(adapter); given().when().contentType("application/zip").body(migrateDataToImport) .post("/apis/registry/v2/admin/import").then().statusCode(204).body(anything()); - for (long gid : migrateGlobalIds) { - dest.ids().globalIds().byGlobalId(gid).get(); - if (migrateReferencesMap.containsKey(gid)) { - List srcReferences = migrateReferencesMap - .get(gid); - List destReferences = dest.ids().globalIds().byGlobalId(gid).references() - .get(); - assertTrue(matchesReferencesV2V3(srcReferences, destReferences)); - } - } try { - assertEquals("SYNTAX_ONLY", dest.groups().byGroupId("migrateTest").artifacts() - .byArtifactId("avro-0").rules().byRuleType(RuleType.VALIDITY.name()).get().getConfig()); - assertEquals("BACKWARD", - dest.admin().rules().byRuleType(RuleType.COMPATIBILITY.name()).get().getConfig()); - } catch (ProblemDetails e) { - log.error("REST Client error: " + e.getTitle()); - log.error(" : " + e.getDetail()); - throw e; + for (long gid : migrateGlobalIds) { + dest.ids().globalIds().byGlobalId(gid).get(); + if (migrateReferencesMap.containsKey(gid)) { + List srcReferences = migrateReferencesMap + .get(gid); + List destReferences = dest.ids().globalIds().byGlobalId(gid) + .references().get(); + assertTrue(matchesReferencesV2V3(srcReferences, destReferences)); + } + } + try { + assertEquals("SYNTAX_ONLY", + dest.groups().byGroupId("migrateTest").artifacts().byArtifactId("avro-0").rules() + .byRuleType(RuleType.VALIDITY.name()).get().getConfig()); + assertEquals("BACKWARD", + dest.admin().rules().byRuleType(RuleType.COMPATIBILITY.name()).get().getConfig()); + } catch (ProblemDetails e) { + log.error("REST Client error: " + e.getTitle()); + log.error(" : " + e.getDetail()); + throw e; + } + } finally { + vertx.close(); } } @@ -83,10 +89,11 @@ public static class MigrateTestInitializer extends AbstractTestDataInitializer { @Override public Map start() { + Vertx vertx = Vertx.vertx(); String registryBaseUrl = startRegistryApplication( "quay.io/apicurio/apicurio-registry-mem:latest-release"); - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(getRegistryV2ApiUrl()); io.apicurio.registry.rest.client.v2.RegistryClient source = new io.apicurio.registry.rest.client.v2.RegistryClient( adapter); @@ -102,6 +109,8 @@ public Map start() { } catch (Exception ex) { log.error("Error filling origin registry with data:", ex); + } finally { + vertx.close(); } return Map.of("apicurio.rest.deletion.artifact.enabled", "true"); diff --git a/integration-tests/src/test/java/io/apicurio/tests/migration/DoNotPreserveIdsImportIT.java b/integration-tests/src/test/java/io/apicurio/tests/migration/DoNotPreserveIdsImportIT.java index f2812960a2..d1f3840d17 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/migration/DoNotPreserveIdsImportIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/migration/DoNotPreserveIdsImportIT.java @@ -1,6 +1,5 @@ package io.apicurio.tests.migration; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.types.ArtifactType; @@ -15,6 +14,7 @@ import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.vertx.core.Vertx; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -44,62 +44,70 @@ public class DoNotPreserveIdsImportIT extends ApicurioRegistryBaseIT { @Test public void testDoNotPreserveIdsImport() throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(ApicurioRegistryBaseIT.getRegistryV3ApiUrl()); RegistryClient dest = new RegistryClient(adapter); - // Fill the destination registry with data (Avro content is inserted first to ensure that the content - // IDs are different) - for (int idx = 0; idx < 15; idx++) { - AvroGenericRecordSchemaFactory avroSchema = new AvroGenericRecordSchemaFactory( - List.of("a" + idx)); - String artifactId = "avro-" + idx + "-" + UUID.randomUUID().toString(); // Artifact ids need to be - // different we do not - // support identical - // artifact ids - String content = IoUtil.toString(avroSchema.generateSchemaStream()); - - CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.AVRO, - content, ContentTypes.APPLICATION_JSON); - var response = dest.groups().byGroupId("testDoNotPreserveIdsImport").artifacts() - .post(createArtifact); - retry(() -> dest.ids().globalIds().byGlobalId(response.getVersion().getGlobalId())); - doNotPreserveIdsImportArtifacts.put("testDoNotPreserveIdsImport:" + artifactId, content); - } + try { + // Fill the destination registry with data (Avro content is inserted first to ensure that the + // content + // IDs are different) + for (int idx = 0; idx < 15; idx++) { + AvroGenericRecordSchemaFactory avroSchema = new AvroGenericRecordSchemaFactory( + List.of("a" + idx)); + String artifactId = "avro-" + idx + "-" + UUID.randomUUID().toString(); // Artifact ids need + // to be + // different we do not + // support identical + // artifact ids + String content = IoUtil.toString(avroSchema.generateSchemaStream()); + + CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.AVRO, + content, ContentTypes.APPLICATION_JSON); + var response = dest.groups().byGroupId("testDoNotPreserveIdsImport").artifacts() + .post(createArtifact); + retry(() -> dest.ids().globalIds().byGlobalId(response.getVersion().getGlobalId())); + doNotPreserveIdsImportArtifacts.put("testDoNotPreserveIdsImport:" + artifactId, content); + } - for (int idx = 0; idx < 50; idx++) { - String artifactId = idx + "-" + UUID.randomUUID().toString(); // Artifact ids need to be different - // we do not support identical - // artifact ids - String content = IoUtil.toString(jsonSchema.getSchemaStream()); - CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.JSON, - content, ContentTypes.APPLICATION_JSON); - var response = dest.groups().byGroupId("testDoNotPreserveIdsImport").artifacts() - .post(createArtifact, config -> { - config.headers.add("X-Registry-ArtifactId", artifactId); - }); - retry(() -> dest.ids().globalIds().byGlobalId(response.getVersion().getGlobalId())); - doNotPreserveIdsImportArtifacts.put("testDoNotPreserveIdsImport:" + artifactId, content); - } + for (int idx = 0; idx < 50; idx++) { + String artifactId = idx + "-" + UUID.randomUUID().toString(); // Artifact ids need to be + // different + // we do not support identical + // artifact ids + String content = IoUtil.toString(jsonSchema.getSchemaStream()); + CreateArtifact createArtifact = TestUtils.clientCreateArtifact(artifactId, ArtifactType.JSON, + content, ContentTypes.APPLICATION_JSON); + var response = dest.groups().byGroupId("testDoNotPreserveIdsImport").artifacts() + .post(createArtifact, config -> { + config.headers.add("X-Registry-ArtifactId", artifactId); + }); + retry(() -> dest.ids().globalIds().byGlobalId(response.getVersion().getGlobalId())); + doNotPreserveIdsImportArtifacts.put("testDoNotPreserveIdsImport:" + artifactId, content); + } - // Import the data - var importReq = dest.admin().importEscaped() - .toPostRequestInformation(doNotPreserveIdsImportDataToImport, config -> { - config.headers.add("X-Registry-Preserve-GlobalId", "false"); - config.headers.add("X-Registry-Preserve-ContentId", "false"); - }); - importReq.headers.replace("Content-Type", Set.of("application/zip")); - adapter.sendPrimitive(importReq, new HashMap<>(), Void.class); - - // Check that the import was successful - for (var entry : doNotPreserveIdsImportArtifacts.entrySet()) { - String groupId = entry.getKey().split(":")[0]; - String artifactId = entry.getKey().split(":")[1]; - String content = entry.getValue(); - var registryContent = dest.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) - .versions().byVersionExpression("branch=latest").content().get(); - assertNotNull(registryContent); - assertEquals(content, IoUtil.toString(registryContent)); + // Import the data + var importReq = dest.admin().importEscaped() + .toPostRequestInformation(doNotPreserveIdsImportDataToImport, config -> { + config.headers.add("X-Registry-Preserve-GlobalId", "false"); + config.headers.add("X-Registry-Preserve-ContentId", "false"); + }); + importReq.headers.replace("Content-Type", Set.of("application/zip")); + adapter.sendPrimitive(importReq, new HashMap<>(), Void.class); + + // Check that the import was successful + for (var entry : doNotPreserveIdsImportArtifacts.entrySet()) { + String groupId = entry.getKey().split(":")[0]; + String artifactId = entry.getKey().split(":")[1]; + String content = entry.getValue(); + var registryContent = dest.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) + .versions().byVersionExpression("branch=latest").content().get(); + assertNotNull(registryContent); + assertEquals(content, IoUtil.toString(registryContent)); + } + } finally { + vertx.close(); } } @@ -107,10 +115,11 @@ public static class DoNotPreserveIdsInitializer extends AbstractTestDataInitiali @Override public Map start() { + Vertx vertx = Vertx.vertx(); String registryBaseUrl = startRegistryApplication( "quay.io/apicurio/apicurio-registry-mem:latest-release"); - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(getRegistryV2ApiUrl()); io.apicurio.registry.rest.client.v2.RegistryClient source = new io.apicurio.registry.rest.client.v2.RegistryClient( adapter); @@ -125,6 +134,8 @@ public Map start() { } catch (Exception ex) { log.error("Error filling origin registry with data:", ex); + } finally { + vertx.close(); } return Map.of("apicurio.rest.deletion.artifact.enabled", "true"); diff --git a/integration-tests/src/test/java/io/apicurio/tests/migration/GenerateCanonicalHashImportIT.java b/integration-tests/src/test/java/io/apicurio/tests/migration/GenerateCanonicalHashImportIT.java index 44d6b11889..481ceea1eb 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/migration/GenerateCanonicalHashImportIT.java +++ b/integration-tests/src/test/java/io/apicurio/tests/migration/GenerateCanonicalHashImportIT.java @@ -1,6 +1,5 @@ package io.apicurio.tests.migration; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.apicurio.registry.model.BranchId; import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.ProblemDetails; @@ -18,6 +17,7 @@ import io.apicurio.tests.utils.Constants; import io.kiota.http.vertx.VertXRequestAdapter; import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.vertx.core.Vertx; import org.apache.commons.codec.digest.DigestUtils; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; @@ -46,44 +46,50 @@ public class GenerateCanonicalHashImportIT extends ApicurioRegistryBaseIT { @Test public void testGeneratingCanonicalHashOnImport() throws Exception { - var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx); + Vertx vertx = Vertx.vertx(); + var adapter = new VertXRequestAdapter(vertx); adapter.setBaseUrl(ApicurioRegistryBaseIT.getRegistryV3ApiUrl()); RegistryClient client = new RegistryClient(adapter); - Map artifacts = new HashMap<>(); + try { + Map artifacts = new HashMap<>(); - JsonSchemaMsgFactory jsonSchema = new JsonSchemaMsgFactory(); - for (int i = 0; i < 20; i++) { - String artifactId = i + "-" + UUID.randomUUID(); - String content = jsonSchema.getSchemaString(); - artifacts.put(artifactId, content); - } - var importReq = client.admin().importEscaped() - .toPostRequestInformation(generateExportedZip(artifacts)); - importReq.headers.replace("Content-Type", Set.of("application/zip")); - adapter.sendPrimitive(importReq, new HashMap<>(), Void.class); - - for (var entry : artifacts.entrySet()) { - String groupId = "default"; - String artifactId = entry.getKey(); - String content = entry.getValue(); - - /* - * TODO: Check if the canonical hash is generated correctly. The only way is to generate canonical - * hash and then search artifact by it. But that needs apicurio-registry-app module as dependency. - */ - - try { - var registryContent = client.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) - .versions().byVersionExpression("1.0").content().get(); - assertNotNull(registryContent); - assertEquals(content, IoUtil.toString(registryContent)); - } catch (ProblemDetails e) { - System.out.println("---"); - System.out.println("REST CLIENT ERROR>> " + e.getDetail()); - System.out.println("---"); - throw e; + JsonSchemaMsgFactory jsonSchema = new JsonSchemaMsgFactory(); + for (int i = 0; i < 20; i++) { + String artifactId = i + "-" + UUID.randomUUID(); + String content = jsonSchema.getSchemaString(); + artifacts.put(artifactId, content); + } + var importReq = client.admin().importEscaped() + .toPostRequestInformation(generateExportedZip(artifacts)); + importReq.headers.replace("Content-Type", Set.of("application/zip")); + adapter.sendPrimitive(importReq, new HashMap<>(), Void.class); + + for (var entry : artifacts.entrySet()) { + String groupId = "default"; + String artifactId = entry.getKey(); + String content = entry.getValue(); + + /* + * TODO: Check if the canonical hash is generated correctly. The only way is to generate + * canonical hash and then search artifact by it. But that needs apicurio-registry-app module + * as dependency. + */ + + try { + var registryContent = client.groups().byGroupId(groupId).artifacts() + .byArtifactId(artifactId).versions().byVersionExpression("1.0").content().get(); + assertNotNull(registryContent); + assertEquals(content, IoUtil.toString(registryContent)); + } catch (ProblemDetails e) { + System.out.println("---"); + System.out.println("REST CLIENT ERROR>> " + e.getDetail()); + System.out.println("---"); + throw e; + } } + } finally { + vertx.close(); } } diff --git a/integration-tests/src/test/java/io/apicurio/tests/utils/LimitingProxy.java b/integration-tests/src/test/java/io/apicurio/tests/utils/LimitingProxy.java index d44af461b4..28437989f9 100644 --- a/integration-tests/src/test/java/io/apicurio/tests/utils/LimitingProxy.java +++ b/integration-tests/src/test/java/io/apicurio/tests/utils/LimitingProxy.java @@ -1,6 +1,5 @@ package io.apicurio.tests.utils; -import io.apicurio.registry.client.auth.VertXAuthFactory; import io.vertx.core.Vertx; import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; @@ -20,7 +19,7 @@ public abstract class LimitingProxy { protected final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); - private Vertx vertx; + private final Vertx vertx = Vertx.vertx(); private int port = 30001; private HttpServer server; @@ -30,8 +29,6 @@ public abstract class LimitingProxy { private int destinationPort; public LimitingProxy(String destinationHost, int destinationPort) { - - vertx = VertXAuthFactory.defaultVertx; client = vertx.createHttpClient(new HttpClientOptions()); if (destinationHost.endsWith("127.0.0.1.nip.io")) { logger.info("Changing proxy destination host to localhost"); @@ -69,6 +66,7 @@ public void stop() { if (server != null) { server.close(); } + vertx.close(); } abstract protected boolean allowed(); diff --git a/java-sdk/pom.xml b/java-sdk/pom.xml index c950bf6c67..c53871b21a 100644 --- a/java-sdk/pom.xml +++ b/java-sdk/pom.xml @@ -34,6 +34,11 @@ microsoft-kiota-abstractions ${kiota.libs.version} + + io.kiota + kiota-http-jdk + ${kiota.community.version} + io.kiota kiota-http-vertx diff --git a/java-sdk/src/main/java/io/apicurio/registry/client/auth/VertXAuthFactory.java b/java-sdk/src/main/java/io/apicurio/registry/client/auth/VertXAuthFactory.java index f0ac0f573a..e91bbbd251 100644 --- a/java-sdk/src/main/java/io/apicurio/registry/client/auth/VertXAuthFactory.java +++ b/java-sdk/src/main/java/io/apicurio/registry/client/auth/VertXAuthFactory.java @@ -12,22 +12,15 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; +/** + * A factory class to make it easier to create Vertx web clients with authentication enabled. Supports OIDC + * and BASIC auth. + */ public class VertXAuthFactory { - public final static Vertx defaultVertx = Vertx.vertx(); - - public static WebClient buildOIDCWebClient(String tokenUrl, String clientId, String clientSecret) { - return buildOIDCWebClient(defaultVertx, tokenUrl, clientId, clientSecret, null); - } - public static WebClient buildOIDCWebClient(Vertx vertx, String tokenUrl, String clientId, String clientSecret) { - return buildOIDCWebClient(tokenUrl, clientId, clientSecret, null); - } - - public static WebClient buildOIDCWebClient(String tokenUrl, String clientId, String clientSecret, - String scope) { - return buildOIDCWebClient(defaultVertx, tokenUrl, clientId, clientSecret, scope); + return buildOIDCWebClient(vertx, tokenUrl, clientId, clientSecret, null); } public static WebClient buildOIDCWebClient(Vertx vertx, String tokenUrl, String clientId, @@ -45,10 +38,6 @@ public static WebClient buildOIDCWebClient(Vertx vertx, String tokenUrl, String return oauth2WebClient; } - public static WebClient buildSimpleAuthWebClient(String username, String password) { - return buildSimpleAuthWebClient(defaultVertx, username, password); - } - public static WebClient buildSimpleAuthWebClient(Vertx vertx, String username, String password) { String usernameAndPassword = Base64.getEncoder() .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8)); diff --git a/utils/importexport/src/main/java/io/apicurio/registry/utils/impexp/EntityReader.java b/utils/importexport/src/main/java/io/apicurio/registry/utils/impexp/EntityReader.java index 651d649001..59e0465a9e 100644 --- a/utils/importexport/src/main/java/io/apicurio/registry/utils/impexp/EntityReader.java +++ b/utils/importexport/src/main/java/io/apicurio/registry/utils/impexp/EntityReader.java @@ -172,8 +172,8 @@ private void createEntityIndex() { // so that the "latest" branch contains the versions in the correct order. if (majorVersion == 2) { versions.sort((v1, v2) -> { - long v1GlobalId = getArtifactVersionOrder(v1); - long v2GlobalId = getArtifactVersionOrder(v2); + long v1GlobalId = getArtifactVersionGlobalId(v1); + long v2GlobalId = getArtifactVersionGlobalId(v2); return (int) (v1GlobalId - v2GlobalId); }); } @@ -288,7 +288,7 @@ private T readEntry(EntityInfo entry, Class theClass) throws IOException return entity; } - private long getArtifactVersionOrder(EntityInfo artifactVersionEntityInfo) { + private long getArtifactVersionGlobalId(EntityInfo artifactVersionEntityInfo) { try { Entity entity = readArtifactVersion(artifactVersionEntityInfo); return ((io.apicurio.registry.utils.impexp.v2.ArtifactVersionEntity) entity).globalId; diff --git a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/AbstractRegistryMojo.java b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/AbstractRegistryMojo.java index 3d4c77ddb9..9b070557b8 100644 --- a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/AbstractRegistryMojo.java +++ b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/AbstractRegistryMojo.java @@ -4,6 +4,7 @@ import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.types.ContentTypes; import io.kiota.http.vertx.VertXRequestAdapter; +import io.vertx.core.Vertx; import io.vertx.ext.web.client.WebClient; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -13,9 +14,6 @@ import java.util.Locale; import java.util.concurrent.ExecutionException; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient; -import static io.apicurio.registry.client.auth.VertXAuthFactory.buildSimpleAuthWebClient; - /** * Base class for all Registry Mojo's. It handles RegistryService's (aka client) lifecycle. */ @@ -45,28 +43,20 @@ public abstract class AbstractRegistryMojo extends AbstractMojo { @Parameter(property = "password") String password; - private RegistryClient client; - - protected RegistryClient getClient() { - if (client == null) { - WebClient provider = null; - if (authServerUrl != null && clientId != null && clientSecret != null) { - provider = buildOIDCWebClient(authServerUrl, clientId, clientSecret, clientScope); - } else if (username != null && password != null) { - provider = buildSimpleAuthWebClient(username, password); - } else { - provider = WebClient.create(VertXAuthFactory.defaultVertx); - } - - var adapter = new VertXRequestAdapter(provider); - adapter.setBaseUrl(registryUrl); - client = new RegistryClient(adapter); + protected RegistryClient createClient(Vertx vertx) { + WebClient provider = null; + if (authServerUrl != null && clientId != null && clientSecret != null) { + provider = VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl, clientId, clientSecret, + clientScope); + } else if (username != null && password != null) { + provider = VertXAuthFactory.buildSimpleAuthWebClient(vertx, username, password); + } else { + provider = WebClient.create(vertx); } - return client; - } - public void setClient(RegistryClient client) { - this.client = client; + var adapter = new VertXRequestAdapter(provider); + adapter.setBaseUrl(registryUrl); + return new RegistryClient(adapter); } @Override diff --git a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/DownloadRegistryMojo.java b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/DownloadRegistryMojo.java index 74708e9453..ac31a63f8a 100644 --- a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/DownloadRegistryMojo.java +++ b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/DownloadRegistryMojo.java @@ -1,5 +1,7 @@ package io.apicurio.registry.maven; +import io.apicurio.registry.rest.client.RegistryClient; +import io.vertx.core.Vertx; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -74,19 +76,27 @@ protected void validate() throws MojoExecutionException { protected void executeInternal() throws MojoExecutionException, ExecutionException, InterruptedException { validate(); - int errorCount = 0; - if (artifacts != null) { - for (DownloadArtifact artifact : artifacts) { - errorCount += downloadArtifact(artifact); + Vertx vertx = Vertx.vertx(); + RegistryClient registryClient = createClient(vertx); + + try { + int errorCount = 0; + if (artifacts != null) { + for (DownloadArtifact artifact : artifacts) { + errorCount += downloadArtifact(registryClient, artifact); + } } - } - if (errorCount > 0) { - throw new MojoExecutionException("Errors while downloading artifacts ..."); + if (errorCount > 0) { + throw new MojoExecutionException("Errors while downloading artifacts ..."); + } + } finally { + vertx.close(); } } - private int downloadArtifact(DownloadArtifact artifact) throws ExecutionException, InterruptedException { + private int downloadArtifact(RegistryClient registryClient, DownloadArtifact artifact) + throws ExecutionException, InterruptedException { int errorCount = 0; String groupId = artifact.getGroupId(); String artifactId = artifact.getArtifactId(); @@ -99,7 +109,7 @@ private int downloadArtifact(DownloadArtifact artifact) throws ExecutionExceptio getLog().info(String.format("Downloading artifact [%s] / [%s] (version %s).", groupId, artifactId, version)); - try (InputStream content = getClient().groups().byGroupId(groupId).artifacts() + try (InputStream content = registryClient.groups().byGroupId(groupId).artifacts() .byArtifactId(artifactId).versions().byVersionExpression(version).content().get()) { if (!artifact.getFile().getParentFile().exists()) { @@ -123,7 +133,7 @@ private int downloadArtifact(DownloadArtifact artifact) throws ExecutionExceptio if (artifact.getArtifactReferences() != null && !artifact.getArtifactReferences().isEmpty()) { for (DownloadArtifact reference : artifact.getArtifactReferences()) { - errorCount += downloadArtifact(reference); + errorCount += downloadArtifact(registryClient, reference); } } diff --git a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java index c7397f2af8..84e4092272 100644 --- a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java +++ b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/RegisterRegistryMojo.java @@ -9,6 +9,7 @@ import io.apicurio.registry.content.refs.ReferenceFinder; import io.apicurio.registry.maven.refs.IndexedResource; import io.apicurio.registry.maven.refs.ReferenceIndex; +import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.ArtifactReference; import io.apicurio.registry.rest.client.models.CreateArtifact; import io.apicurio.registry.rest.client.models.CreateVersion; @@ -20,6 +21,7 @@ import io.apicurio.registry.types.ContentTypes; import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider; import io.apicurio.registry.types.provider.DefaultArtifactTypeUtilProviderImpl; +import io.vertx.core.Vertx; import org.apache.avro.Schema; import org.apache.commons.io.FileUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -123,6 +125,9 @@ protected boolean validate() throws MojoExecutionException { protected void executeInternal() throws MojoExecutionException { int errorCount = 0; if (validate()) { + Vertx vertx = Vertx.vertx(); + RegistryClient registryClient = createClient(vertx); + for (RegisterArtifact artifact : artifacts) { String groupId = artifact.getGroupId(); String artifactId = artifact.getArtifactId(); @@ -131,11 +136,11 @@ protected void executeInternal() throws MojoExecutionException { // If we have references, then we'll need to create the local resource index and then // process all refs. ReferenceIndex index = createIndex(artifact.getFile()); - addExistingReferencesToIndex(index, existingReferences); - addExistingReferencesToIndex(index, artifact.getExistingReferences()); + addExistingReferencesToIndex(registryClient, index, existingReferences); + addExistingReferencesToIndex(registryClient, index, artifact.getExistingReferences()); Stack registrationStack = new Stack<>(); - registerWithAutoRefs(artifact, index, registrationStack); + registerWithAutoRefs(registryClient, artifact, index, registrationStack); } else if (artifact.getAnalyzeDirectory() != null && artifact.getAnalyzeDirectory()) { // Auto // register // selected, @@ -152,15 +157,15 @@ protected void executeInternal() throws MojoExecutionException { // the // directory // structure - registerDirectory(artifact); + registerDirectory(registryClient, artifact); } else { List references = new ArrayList<>(); // First, we check if the artifact being processed has references defined if (hasReferences(artifact)) { - references = processArtifactReferences(artifact.getReferences()); + references = processArtifactReferences(registryClient, artifact.getReferences()); } - registerArtifact(artifact, references); + registerArtifact(registryClient, artifact, references); } } catch (Exception e) { errorCount++; @@ -176,8 +181,8 @@ protected void executeInternal() throws MojoExecutionException { } } - private VersionMetaData registerWithAutoRefs(RegisterArtifact artifact, ReferenceIndex index, - Stack registrationStack) + private VersionMetaData registerWithAutoRefs(RegistryClient registryClient, RegisterArtifact artifact, + ReferenceIndex index, Stack registrationStack) throws IOException, ExecutionException, InterruptedException { if (loopDetected(artifact, registrationStack)) { throw new RuntimeException( @@ -219,7 +224,7 @@ private VersionMetaData registerWithAutoRefs(RegisterArtifact artifact, Referenc refArtifact.setFile(localFile); refArtifact.setContentType(getContentTypeByExtension(localFile.getName())); try { - var car = registerWithAutoRefs(refArtifact, index, registrationStack); + var car = registerWithAutoRefs(registryClient, refArtifact, index, registrationStack); iresource.setRegistration(car); } catch (IOException | ExecutionException | InterruptedException e) { throw new RuntimeException(e); @@ -236,33 +241,33 @@ private VersionMetaData registerWithAutoRefs(RegisterArtifact artifact, Referenc }).sorted((ref1, ref2) -> ref1.getName().compareTo(ref2.getName())).collect(Collectors.toList()); registrationStack.pop(); - return registerArtifact(artifact, registeredReferences); + return registerArtifact(registryClient, artifact, registeredReferences); } - private void registerDirectory(RegisterArtifact artifact) + private void registerDirectory(RegistryClient registryClient, RegisterArtifact artifact) throws IOException, ExecutionException, InterruptedException { switch (artifact.getArtifactType()) { case ArtifactType.AVRO: - final AvroDirectoryParser avroDirectoryParser = new AvroDirectoryParser(getClient()); + final AvroDirectoryParser avroDirectoryParser = new AvroDirectoryParser(registryClient); final ParsedDirectoryWrapper schema = avroDirectoryParser.parse(artifact.getFile()); - registerArtifact(artifact, avroDirectoryParser.handleSchemaReferences(artifact, - schema.getSchema(), schema.getSchemaContents())); + registerArtifact(registryClient, artifact, avroDirectoryParser + .handleSchemaReferences(artifact, schema.getSchema(), schema.getSchemaContents())); break; case ArtifactType.PROTOBUF: final ProtobufDirectoryParser protobufDirectoryParser = new ProtobufDirectoryParser( - getClient()); + registryClient); final ParsedDirectoryWrapper protoSchema = protobufDirectoryParser .parse(artifact.getFile()); - registerArtifact(artifact, protobufDirectoryParser.handleSchemaReferences(artifact, - protoSchema.getSchema(), protoSchema.getSchemaContents())); + registerArtifact(registryClient, artifact, protobufDirectoryParser.handleSchemaReferences( + artifact, protoSchema.getSchema(), protoSchema.getSchemaContents())); break; case ArtifactType.JSON: final JsonSchemaDirectoryParser jsonSchemaDirectoryParser = new JsonSchemaDirectoryParser( - getClient()); + registryClient); final ParsedDirectoryWrapper jsonSchema = jsonSchemaDirectoryParser .parse(artifact.getFile()); - registerArtifact(artifact, jsonSchemaDirectoryParser.handleSchemaReferences(artifact, - jsonSchema.getSchema(), jsonSchema.getSchemaContents())); + registerArtifact(registryClient, artifact, jsonSchemaDirectoryParser.handleSchemaReferences( + artifact, jsonSchema.getSchema(), jsonSchema.getSchemaContents())); break; default: throw new IllegalArgumentException( @@ -271,21 +276,24 @@ private void registerDirectory(RegisterArtifact artifact) } } - private VersionMetaData registerArtifact(RegisterArtifact artifact, List references) + private VersionMetaData registerArtifact(RegistryClient registryClient, RegisterArtifact artifact, + List references) throws FileNotFoundException, ExecutionException, InterruptedException { if (artifact.getFile() != null) { - return registerArtifact(artifact, new FileInputStream(artifact.getFile()), references); + return registerArtifact(registryClient, artifact, new FileInputStream(artifact.getFile()), + references); } else { - return getArtifactVersionMetadata(artifact); + return getArtifactVersionMetadata(registryClient, artifact); } } - private VersionMetaData getArtifactVersionMetadata(RegisterArtifact artifact) { + private VersionMetaData getArtifactVersionMetadata(RegistryClient registryClient, + RegisterArtifact artifact) { String groupId = artifact.getGroupId(); String artifactId = artifact.getArtifactId(); String version = artifact.getVersion(); - VersionMetaData amd = getClient().groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) + VersionMetaData amd = registryClient.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) .versions().byVersionExpression(version).get(); getLog().info(String.format("Successfully processed artifact [%s] / [%s]. GlobalId is [%d]", groupId, artifactId, amd.getGlobalId())); @@ -293,8 +301,9 @@ private VersionMetaData getArtifactVersionMetadata(RegisterArtifact artifact) { return amd; } - private VersionMetaData registerArtifact(RegisterArtifact artifact, InputStream artifactContent, - List references) throws ExecutionException, InterruptedException { + private VersionMetaData registerArtifact(RegistryClient registryClient, RegisterArtifact artifact, + InputStream artifactContent, List references) + throws ExecutionException, InterruptedException { String groupId = artifact.getGroupId(); String artifactId = artifact.getArtifactId(); String version = artifact.getVersion(); @@ -337,7 +346,7 @@ private VersionMetaData registerArtifact(RegisterArtifact artifact, InputStream createVersion.setContent(content); try { - var vmd = getClient().groups().byGroupId(groupId).artifacts().post(createArtifact, config -> { + var vmd = registryClient.groups().byGroupId(groupId).artifacts().post(createArtifact, config -> { if (artifact.getIfExists() != null) { config.queryParameters.ifExists = IfArtifactExists .forValue(artifact.getIfExists().value()); @@ -358,7 +367,7 @@ private static boolean hasReferences(RegisterArtifact artifact) { return artifact.getReferences() != null && !artifact.getReferences().isEmpty(); } - private List processArtifactReferences( + private List processArtifactReferences(RegistryClient registryClient, List referencedArtifacts) throws FileNotFoundException, ExecutionException, InterruptedException { List references = new ArrayList<>(); @@ -367,9 +376,10 @@ private List processArtifactReferences( // First, we check if the artifact being processed has references defined, and register them if // needed if (hasReferences(artifact)) { - nestedReferences = processArtifactReferences(artifact.getReferences()); + nestedReferences = processArtifactReferences(registryClient, artifact.getReferences()); } - final VersionMetaData artifactMetaData = registerArtifact(artifact, nestedReferences); + final VersionMetaData artifactMetaData = registerArtifact(registryClient, artifact, + nestedReferences); references.add(buildReferenceFromMetadata(artifactMetaData, artifact.getName())); } return references; @@ -407,13 +417,13 @@ private static ReferenceIndex createIndex(File file) { return index; } - private void addExistingReferencesToIndex(ReferenceIndex index, + private void addExistingReferencesToIndex(RegistryClient registryClient, ReferenceIndex index, List existingReferences) throws ExecutionException, InterruptedException { if (existingReferences != null && !existingReferences.isEmpty()) { for (ExistingReference ref : existingReferences) { VersionMetaData vmd; if (ref.getVersion() == null || "LATEST".equalsIgnoreCase(ref.getVersion())) { - vmd = getClient().groups().byGroupId(ref.getGroupId()).artifacts() + vmd = registryClient.groups().byGroupId(ref.getGroupId()).artifacts() .byArtifactId(ref.getArtifactId()).versions().byVersionExpression("branch=latest") .get(); } else { diff --git a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/TestUpdateRegistryMojo.java b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/TestUpdateRegistryMojo.java index 45ab0a86eb..f64187170c 100644 --- a/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/TestUpdateRegistryMojo.java +++ b/utils/maven-plugin/src/main/java/io/apicurio/registry/maven/TestUpdateRegistryMojo.java @@ -1,8 +1,10 @@ package io.apicurio.registry.maven; +import io.apicurio.registry.rest.client.RegistryClient; import io.apicurio.registry.rest.client.models.CreateVersion; import io.apicurio.registry.rest.client.models.VersionContent; import io.apicurio.registry.utils.IoUtil; +import io.vertx.core.Vertx; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -69,37 +71,43 @@ protected void validate() throws MojoExecutionException { @Override protected void executeInternal() throws MojoExecutionException { validate(); + Vertx vertx = Vertx.vertx(); + RegistryClient registryClient = createClient(vertx); - int errorCount = 0; - if (artifacts != null) { - for (TestArtifact artifact : artifacts) { - String groupId = artifact.getGroupId(); - String artifactId = artifact.getArtifactId(); - String contentType = contentType(artifact); - try (InputStream data = new FileInputStream(artifact.getFile())) { - String content = IoUtil.toString(data); - CreateVersion cv = new CreateVersion(); - cv.setContent(new VersionContent()); - cv.getContent().setContentType(contentType); - cv.getContent().setContent(content); - getClient().groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions() - .post(cv, config -> { - config.queryParameters.dryRun = true; - }); - getLog().info(String.format( - "[%s] / [%s] :: Artifact successfully tested (updating is allowed for the given content).", - groupId, artifactId)); - } catch (Exception e) { - errorCount++; - getLog().error(String.format( - "[%s] / [%s] :: Artifact test FAILED (updating is not allowed for the given content).", - groupId, artifactId), e); + try { + int errorCount = 0; + if (artifacts != null) { + for (TestArtifact artifact : artifacts) { + String groupId = artifact.getGroupId(); + String artifactId = artifact.getArtifactId(); + String contentType = contentType(artifact); + try (InputStream data = new FileInputStream(artifact.getFile())) { + String content = IoUtil.toString(data); + CreateVersion cv = new CreateVersion(); + cv.setContent(new VersionContent()); + cv.getContent().setContentType(contentType); + cv.getContent().setContent(content); + registryClient.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId) + .versions().post(cv, config -> { + config.queryParameters.dryRun = true; + }); + getLog().info(String.format( + "[%s] / [%s] :: Artifact successfully tested (updating is allowed for the given content).", + groupId, artifactId)); + } catch (Exception e) { + errorCount++; + getLog().error(String.format( + "[%s] / [%s] :: Artifact test FAILED (updating is not allowed for the given content).", + groupId, artifactId), e); + } } } - } - if (errorCount > 0) { - throw new MojoExecutionException("Errors while testing artifacts for update..."); + if (errorCount > 0) { + throw new MojoExecutionException("Errors while testing artifacts for update..."); + } + } finally { + vertx.close(); } }