Skip to content

Commit ebff7c8

Browse files
authored
DGS-21546 Follow up PR to handle old CP versions (#3902) (#3906)
1 parent d30dec1 commit ebff7c8

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

dek-registry-client/src/main/java/io/confluent/dekregistry/client/rest/DekRegistryRestService.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,30 @@ public Dek createDek(
264264
String kekName,
265265
CreateDekRequest request)
266266
throws IOException, RestClientException {
267-
UriBuilder builder = UriBuilder.fromPath("/dek-registry/v1/keks/{name}/deks/{subject}");
268-
String path = builder.build(kekName, request.getSubject()).toString();
269-
270-
return httpRequest(
271-
path, "POST",
272-
request.toJson().getBytes(StandardCharsets.UTF_8),
273-
requestProperties,
274-
DEK_TYPE);
267+
try {
268+
UriBuilder builder = UriBuilder.fromPath("/dek-registry/v1/keks/{name}/deks/{subject}");
269+
String path = builder.build(kekName, request.getSubject()).toString();
270+
271+
return httpRequest(
272+
path, "POST",
273+
request.toJson().getBytes(StandardCharsets.UTF_8),
274+
requestProperties,
275+
DEK_TYPE);
276+
} catch (RestClientException e) {
277+
if (e.getErrorCode() == 405) {
278+
// Try fallback to older API that does not have subject in the path
279+
UriBuilder builder = UriBuilder.fromPath("/dek-registry/v1/keks/{name}/deks");
280+
String path = builder.build(kekName).toString();
281+
282+
return httpRequest(
283+
path, "POST",
284+
request.toJson().getBytes(StandardCharsets.UTF_8),
285+
requestProperties,
286+
DEK_TYPE);
287+
} else {
288+
throw e;
289+
}
290+
}
275291
}
276292

277293
public Kek updateKek(String name, UpdateKekRequest request)

0 commit comments

Comments
 (0)