Skip to content

Commit 09bc96b

Browse files
Kiota client (#3686)
* Use a Kiota generated client, baby steps * surviving the rebase * close to be compiling * more * more * more * one more * likely 2 to go * one left to compile * integration tests compiling * verify in ci * minor * Use default group for creating artifacts in the integration tests * Run tests on mac os and add default group to create version * Fix in memory tests execution in mac os * Fix tests execution on mac and fix serdes tests * more fixes * minor improvements * more fixes * more * one left * debug in ci again * last fix * attempt to fix the issue * restore auth tests * debug in ci * checkstyle fix * Fix kafka tests * Fix auth test * Fix migration and avro tests * Fix the Python SDK * remove pip auto-upgrade * py fmt --------- Co-authored-by: Carles Arnal <carlesarnal92@gmail.com>
1 parent 3104a19 commit 09bc96b

File tree

145 files changed

+4185
-7050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+4185
-7050
lines changed

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ updates:
8484
versions:
8585
- 4.9.1
8686

87-
- package-ecosystem: pip
87+
- package-ecosystem: nuget
8888
directory: "/python-sdk"
8989
schedule:
9090
interval: daily

app/src/test/java/io/apicurio/registry/AbstractRegistryTestBase.java

+21
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616

1717
package io.apicurio.registry;
1818

19+
import com.microsoft.kiota.ApiException;
1920
import io.apicurio.registry.content.ContentHandle;
2021
import io.apicurio.registry.utils.tests.ParallelizableTest;
2122
import io.apicurio.registry.utils.tests.TestUtils;
2223

24+
import io.apicurio.rest.client.auth.exception.NotAuthorizedException;
2325
import org.eclipse.microprofile.config.inject.ConfigProperty;
2426
import org.junit.jupiter.api.Assertions;
2527
import java.io.BufferedReader;
2628
import java.io.IOException;
2729
import java.io.InputStream;
2830
import java.io.InputStreamReader;
2931
import java.nio.charset.StandardCharsets;
32+
import java.util.concurrent.ExecutionException;
3033
import java.util.stream.Collectors;
3134

3235
/**
@@ -78,4 +81,22 @@ public static void assertMultilineTextEquals(String expected, String actual) thr
7881
Assertions.assertEquals(TestUtils.normalizeMultiLineString(expected), TestUtils.normalizeMultiLineString(actual));
7982
}
8083

84+
protected void assertForbidden(ExecutionException executionException) {
85+
Assertions.assertNotNull(executionException.getCause());
86+
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
87+
Assertions.assertEquals(403, ((ApiException)executionException.getCause()).responseStatusCode);
88+
}
89+
90+
protected void assertNotAuthorized(ExecutionException executionException) {
91+
Assertions.assertNotNull(executionException.getCause());
92+
93+
if (executionException.getCause() instanceof NotAuthorizedException) {
94+
// thrown by the token provider adapter
95+
} else {
96+
// mapped by Kiota
97+
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
98+
Assertions.assertEquals(401, ((ApiException) executionException.getCause()).responseStatusCode);
99+
}
100+
}
101+
81102
}

app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java

+164-117
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.apicurio.registry;
2+
3+
import com.microsoft.kiota.RequestInformation;
4+
import com.microsoft.kiota.authentication.AuthenticationProvider;
5+
import jakarta.annotation.Nonnull;
6+
import jakarta.annotation.Nullable;
7+
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.Base64;
10+
import java.util.Map;
11+
import java.util.concurrent.CompletableFuture;
12+
13+
public class BasicAuthenticationProvider implements AuthenticationProvider {
14+
15+
private final String username;
16+
private final String password;
17+
private final String encoded;
18+
19+
public BasicAuthenticationProvider(String username, String password) {
20+
this.username = username;
21+
this.password = password;
22+
encoded = Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
23+
}
24+
25+
private final static String authorizationHeaderKey = "Authorization";
26+
public static final String BASIC = "Basic ";
27+
@Override
28+
public CompletableFuture<Void> authenticateRequest(@Nonnull final RequestInformation request, @Nullable final Map<String, Object> additionalAuthenticationContext) {
29+
request.headers.add(authorizationHeaderKey, BASIC + encoded);
30+
return CompletableFuture.completedFuture(null);
31+
}
32+
}

app/src/test/java/io/apicurio/registry/MigrationTest.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@
1919
import io.quarkus.test.junit.QuarkusTest;
2020
import org.junit.jupiter.api.Test;
2121

22-
import java.io.IOException;
2322
import java.io.InputStream;
23+
import java.util.concurrent.TimeUnit;
2424

2525
@QuarkusTest
2626
public class MigrationTest extends AbstractResourceTestBase {
2727

2828

2929
@Test
30-
public void migrateData() throws IOException {
30+
public void migrateData() throws Exception {
3131

3232
InputStream originalData = getClass().getResource("rest/v2/destination_original_data.zip").openStream();
3333
InputStream migratedData = getClass().getResource("rest/v2/migration_test_data_dump.zip").openStream();
3434

35-
clientV2.importData(originalData);
36-
clientV2.importData(migratedData, false, false);
35+
clientV2.admin().importEscaped().post(originalData, config -> {
36+
// TODO: this header should be injected by Kiota
37+
config.headers.add("Content-Type", "application/zip");
38+
}).get(10, TimeUnit.SECONDS);
39+
clientV2.admin().importEscaped().post(migratedData, config -> {
40+
// TODO: this header should be injected by Kiota
41+
config.headers.add("Content-Type", "application/zip");
42+
config.headers.add("X-Registry-Preserve-GlobalId", "false");
43+
config.headers.add("X-Registry-Preserve-ContentId", "false");
44+
}).get(40, TimeUnit.SECONDS);
3745
}
3846
}

app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java

+34-39
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,26 @@
1616

1717
package io.apicurio.registry.auth;
1818

19+
import com.microsoft.kiota.ApiException;
20+
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
21+
import com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider;
22+
import com.microsoft.kiota.http.OkHttpRequestAdapter;
1923
import io.apicurio.common.apps.config.Info;
2024
import io.apicurio.registry.AbstractResourceTestBase;
21-
import io.apicurio.registry.rest.client.AdminClient;
2225
import io.apicurio.registry.rest.client.RegistryClient;
23-
import io.apicurio.registry.rest.client.RegistryClientFactory;
24-
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
2526
import io.apicurio.registry.types.ArtifactType;
2627
import io.apicurio.registry.utils.tests.ApicurioTestTags;
2728
import io.apicurio.registry.utils.tests.AuthTestProfileAnonymousCredentials;
2829
import io.apicurio.registry.utils.tests.JWKSMockServer;
29-
import io.apicurio.rest.client.auth.Auth;
30-
import io.apicurio.rest.client.auth.OidcAuth;
31-
import io.apicurio.rest.client.auth.exception.AuthErrorHandler;
32-
import io.apicurio.rest.client.auth.exception.NotAuthorizedException;
33-
import io.apicurio.rest.client.spi.ApicurioHttpClient;
34-
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
3530
import io.quarkus.test.junit.QuarkusTest;
3631
import io.quarkus.test.junit.TestProfile;
3732
import org.eclipse.microprofile.config.inject.ConfigProperty;
3833
import org.junit.jupiter.api.Assertions;
3934
import org.junit.jupiter.api.Tag;
4035
import org.junit.jupiter.api.Test;
4136

42-
import java.io.ByteArrayInputStream;
43-
import java.io.InputStream;
44-
import java.nio.charset.StandardCharsets;
45-
import java.util.Collections;
37+
import java.util.concurrent.ExecutionException;
38+
import java.util.concurrent.TimeUnit;
4639

4740
/**
4841
* @author eric.wittmann@gmail.com
@@ -58,47 +51,49 @@ public class AuthTestAnonymousCredentials extends AbstractResourceTestBase {
5851

5952
final String groupId = getClass().getSimpleName() + "Group";
6053

61-
ApicurioHttpClient httpClient;
62-
63-
@Override
64-
protected RegistryClient createRestClientV2() {
65-
httpClient = ApicurioHttpClientFactory.create(authServerUrl, new AuthErrorHandler());
66-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1");
67-
return this.createClient(auth);
68-
}
69-
70-
@Override
71-
protected AdminClient createAdminClientV2(){
72-
httpClient = ApicurioHttpClientFactory.create(authServerUrl, new AuthErrorHandler());
73-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.ADMIN_CLIENT_ID, "test1");
74-
return this.createAdminClient(auth);
75-
}
76-
7754
@Test
7855
public void testWrongCreds() throws Exception {
79-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "secret");
80-
RegistryClient client = createClient(auth);
81-
Assertions.assertThrows(NotAuthorizedException.class, () -> {
82-
client.listArtifactsInGroup(groupId);
56+
var adapter = new OkHttpRequestAdapter(
57+
new BaseBearerTokenAuthenticationProvider(
58+
new OidcAccessTokenProvider(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "secret")));
59+
adapter.setBaseUrl(registryV2ApiUrl);
60+
RegistryClient client = new RegistryClient(adapter);
61+
var executionException = Assertions.assertThrows(ExecutionException.class, () -> {
62+
client.groups().byGroupId(groupId).artifacts().get().get(3, TimeUnit.SECONDS);
8363
});
64+
assertNotAuthorized(executionException);
8465
}
8566

8667
@Test
8768
public void testNoCredentials() throws Exception {
88-
RegistryClient client = RegistryClientFactory.create(registryV2ApiUrl, Collections.emptyMap(), null);
69+
var adapter = new OkHttpRequestAdapter(new AnonymousAuthenticationProvider());
70+
adapter.setBaseUrl(registryV2ApiUrl);
71+
RegistryClient client = new RegistryClient(adapter);
8972
// Read-only operation should work without any credentials.
90-
ArtifactSearchResults results = client.searchArtifacts(groupId, null, null, null, null, null, null, null, null);
73+
var results = client.search().artifacts().get(config -> config.queryParameters.group = groupId).get(3, TimeUnit.SECONDS);
9174
Assertions.assertTrue(results.getCount() >= 0);
9275

9376
// Write operation should fail without any credentials
94-
InputStream data = new ByteArrayInputStream(("{\r\n" +
77+
String data = "{\r\n" +
9578
" \"type\" : \"record\",\r\n" +
9679
" \"name\" : \"userInfo\",\r\n" +
9780
" \"namespace\" : \"my.example\",\r\n" +
9881
" \"fields\" : [{\"name\" : \"age\", \"type\" : \"int\"}]\r\n" +
99-
"}").getBytes(StandardCharsets.UTF_8));
100-
Assertions.assertThrows(NotAuthorizedException.class, () -> {
101-
client.createArtifact(groupId, "testNoCredentials", ArtifactType.AVRO, data);
82+
"}";
83+
var executionException = Assertions.assertThrows(ExecutionException.class, () -> {
84+
var content = new io.apicurio.registry.rest.client.models.ArtifactContent();
85+
content.setContent(data);
86+
client
87+
.groups()
88+
.byGroupId(groupId)
89+
.artifacts()
90+
.post(content, config -> {
91+
config.headers.add("X-Registry-ArtifactType", ArtifactType.AVRO);
92+
config.headers.add("X-Registry-ArtifactId", "testNoCredentials");
93+
}).get(3, TimeUnit.SECONDS);
10294
});
95+
Assertions.assertNotNull(executionException.getCause());
96+
Assertions.assertEquals(ApiException.class, executionException.getCause().getClass());
97+
Assertions.assertEquals(401, ((ApiException)executionException.getCause()).responseStatusCode);
10398
}
10499
}

app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java

+29-31
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,24 @@
2020
* @author carnalca@redhat.com
2121
*/
2222

23+
import com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider;
24+
import com.microsoft.kiota.http.OkHttpRequestAdapter;
2325
import io.apicurio.common.apps.config.Info;
2426
import io.apicurio.registry.AbstractResourceTestBase;
25-
import io.apicurio.registry.rest.client.AdminClient;
2627
import io.apicurio.registry.rest.client.RegistryClient;
27-
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
2828
import io.apicurio.registry.types.ArtifactType;
2929
import io.apicurio.registry.utils.tests.ApicurioTestTags;
3030
import io.apicurio.registry.utils.tests.AuthTestProfileAuthenticatedReadAccess;
3131
import io.apicurio.registry.utils.tests.JWKSMockServer;
32-
import io.apicurio.rest.client.auth.Auth;
33-
import io.apicurio.rest.client.auth.OidcAuth;
34-
import io.apicurio.rest.client.auth.exception.AuthErrorHandler;
35-
import io.apicurio.rest.client.auth.exception.ForbiddenException;
36-
import io.apicurio.rest.client.spi.ApicurioHttpClient;
37-
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
3832
import io.quarkus.test.junit.QuarkusTest;
3933
import io.quarkus.test.junit.TestProfile;
4034
import org.eclipse.microprofile.config.inject.ConfigProperty;
4135
import org.junit.jupiter.api.Assertions;
4236
import org.junit.jupiter.api.Tag;
4337
import org.junit.jupiter.api.Test;
4438

45-
import java.io.ByteArrayInputStream;
46-
import java.io.InputStream;
47-
import java.nio.charset.StandardCharsets;
39+
import java.util.concurrent.ExecutionException;
40+
import java.util.concurrent.TimeUnit;
4841

4942
@QuarkusTest
5043
@TestProfile(AuthTestProfileAuthenticatedReadAccess.class)
@@ -57,40 +50,45 @@ public class AuthTestAuthenticatedReadAccess extends AbstractResourceTestBase {
5750

5851
final String groupId = getClass().getSimpleName() + "Group";
5952

60-
ApicurioHttpClient httpClient;
61-
6253
@Override
6354
protected RegistryClient createRestClientV2() {
64-
httpClient = ApicurioHttpClientFactory.create(authServerUrl, new AuthErrorHandler());
65-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.ADMIN_CLIENT_ID, "test1");
66-
return this.createClient(auth);
67-
}
68-
69-
@Override
70-
protected AdminClient createAdminClientV2() {
71-
httpClient = ApicurioHttpClientFactory.create(authServerUrl, new AuthErrorHandler());
72-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.ADMIN_CLIENT_ID, "test1");
73-
return this.createAdminClient(auth);
55+
var adapter = new OkHttpRequestAdapter(
56+
new BaseBearerTokenAuthenticationProvider(
57+
new OidcAccessTokenProvider(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1")));
58+
adapter.setBaseUrl(registryV2ApiUrl);
59+
return new RegistryClient(adapter);
7460
}
7561

7662
@Test
7763
public void testReadOperationWithNoRole() throws Exception {
7864
// Read-only operation should work with credentials but no role.
79-
80-
Auth auth = new OidcAuth(httpClient, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1");
81-
RegistryClient client = this.createClient(auth);
82-
ArtifactSearchResults results = client.searchArtifacts(groupId, null, null, null, null, null, null, null, null);
65+
var adapter = new OkHttpRequestAdapter(
66+
new BaseBearerTokenAuthenticationProvider(
67+
new OidcAccessTokenProvider(authServerUrl, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1")));
68+
adapter.setBaseUrl(registryV2ApiUrl);
69+
RegistryClient client = new RegistryClient(adapter);
70+
var results = client.search().artifacts().get(config -> config.queryParameters.group = groupId).get(3, TimeUnit.SECONDS);
8371
Assertions.assertTrue(results.getCount() >= 0);
8472

8573
// Write operation should fail with credentials but not role.
86-
InputStream data = new ByteArrayInputStream(("{\r\n" +
74+
String data = "{\r\n" +
8775
" \"type\" : \"record\",\r\n" +
8876
" \"name\" : \"userInfo\",\r\n" +
8977
" \"namespace\" : \"my.example\",\r\n" +
9078
" \"fields\" : [{\"name\" : \"age\", \"type\" : \"int\"}]\r\n" +
91-
"}").getBytes(StandardCharsets.UTF_8));
92-
Assertions.assertThrows(ForbiddenException.class, () -> {
93-
client.createArtifact(groupId, "testReadOperationWithNoRole", ArtifactType.AVRO, data);
79+
"}";
80+
var executionException = Assertions.assertThrows(ExecutionException.class, () -> {
81+
var content = new io.apicurio.registry.rest.client.models.ArtifactContent();
82+
content.setContent(data);
83+
client
84+
.groups()
85+
.byGroupId(groupId)
86+
.artifacts()
87+
.post(content, config -> {
88+
config.headers.add("X-Registry-ArtifactType", ArtifactType.AVRO);
89+
config.headers.add("X-Registry-ArtifactId", "testReadOperationWithNoRole");
90+
}).get(3, TimeUnit.SECONDS);
9491
});
92+
assertForbidden(executionException);
9593
}
9694
}

0 commit comments

Comments
 (0)