Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,6 @@ public Flux<Schema> list(String namespace, @QueryValue(defaultValue = "*") Strin
: Flux.fromIterable(schemas));
}

/**
* Get the last version of a schema by namespace and subject.
*
* @param namespace The namespace
* @param subject The subject
* @return A schema
* @deprecated use {@link #list(String, String)} instead.
*/
@Get("/{subject}")
@Deprecated(since = "1.12.0")
public Mono<Schema> get(String namespace, String subject) {
Namespace ns = getNamespace(namespace);

if (!schemaService.isNamespaceOwnerOfSubject(ns, subject)) {
return Mono.empty();
}

return schemaService.getSubjectLatestVersion(ns, subject);
}

/**
* Publish a schema.
*
Expand Down Expand Up @@ -209,7 +189,7 @@ public Mono<HttpResponse<Schema>> apply(
* @return A HTTP response
*/
@Delete
public Mono<HttpResponse<List<Schema>>> bulkDelete(
public Mono<HttpResponse<List<Schema>>> delete(
String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue("version") Optional<String> versionOptional,
Expand Down Expand Up @@ -260,67 +240,7 @@ public Mono<HttpResponse<List<Schema>>> bulkDelete(
}

/**
* Delete all schema versions or a specific schema version if specified, under the given subject.
*
* @param namespace The namespace
* @param subject The subject
* @param versionOptional The version of the schema to delete
* @param dryrun Run in dry mode or not?
* @return A HTTP response
* @deprecated use {@link #bulkDelete(String, String, Optional, boolean)} instead.
*/
@Delete("/{subject}")
@Deprecated(since = "1.13.0")
public Mono<HttpResponse<Void>> delete(
String namespace,
@PathVariable String subject,
@QueryValue("version") Optional<String> versionOptional,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

// Validate ownership
if (!schemaService.isNamespaceOwnerOfSubject(ns, subject)) {
return Mono.error(new ResourceValidationException(SCHEMA, subject, invalidOwner(subject)));
}

return versionOptional
// If version is specified, get the schema with the version
.map(version -> schemaService.getSubjectByVersion(ns, subject, version))
// If version is not specified, get the latest schema
.orElseGet(() -> schemaService.getSubjectLatestVersion(ns, subject))
.map(Optional::of)
.defaultIfEmpty(Optional.empty())
.flatMap(subjectOptional -> {
if (subjectOptional.isEmpty()) {
return Mono.just(HttpResponse.notFound());
}

if (dryrun) {
return Mono.just(HttpResponse.noContent());
}

return (versionOptional.isEmpty()
? schemaService.deleteAllVersions(ns, subject)
: schemaService.deleteVersion(ns, subject, versionOptional.get()))
.map(deletedVersionIds -> {
Schema deletedSchema = subjectOptional.get();

sendEventLog(
deletedSchema,
ApplyStatus.DELETED,
deletedSchema.getSpec(),
null,
versionOptional
.map(_ -> String.valueOf(deletedVersionIds))
.orElse(EMPTY_STRING));

return HttpResponse.noContent();
});
});
}

/**
* Update the subject config.
* Update the compatibility of a subject.
*
* @param namespace The namespace
* @param subject The subject config to update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,6 @@ List<KafkaStream> list(String namespace, @QueryValue(defaultValue = "*") String
return streamService.findByWildcardName(getNamespace(namespace), name);
}

/**
* Get a Kafka Streams by namespace and name.
*
* @param namespace The name
* @param stream The Kafka Streams name
* @return The Kafka Streams
* @deprecated Use {@link #list(String, String)}
*/
@Get("/{stream}")
@Deprecated(since = "1.12.0")
Optional<KafkaStream> get(String namespace, String stream) {
return streamService.findByName(getNamespace(namespace), stream);
}

/**
* Create a Kafka Streams.
*
Expand Down Expand Up @@ -145,42 +131,6 @@ HttpResponse<KafkaStream> apply(
return formatHttpResponse(streamService.create(stream), status);
}

/**
* Delete a Kafka Streams.
*
* @param namespace The namespace
* @param stream The Kafka Streams
* @param dryrun Is dry run mode or not?
* @return An HTTP response
* @deprecated use {@link #bulkDelete(String, String, boolean)} instead.
*/
@Delete("/{stream}{?dryrun}")
@Deprecated(since = "1.13.0")
HttpResponse<Void> delete(String namespace, String stream, @QueryValue(defaultValue = "false") boolean dryrun)
throws ExecutionException, InterruptedException, TimeoutException {
Namespace ns = getNamespace(namespace);
if (!streamService.isNamespaceOwnerOfKafkaStream(ns, stream)) {
throw new ResourceValidationException(KAFKA_STREAM, stream, invalidOwner(stream));
}

Optional<KafkaStream> optionalStream = streamService.findByName(ns, stream);

if (optionalStream.isEmpty()) {
return HttpResponse.notFound();
}

if (dryrun) {
return HttpResponse.noContent();
}

KafkaStream streamToDelete = optionalStream.get();

sendEventLog(streamToDelete, ApplyStatus.DELETED, streamToDelete.getMetadata(), null, EMPTY_STRING);

streamService.delete(ns, optionalStream.get());
return HttpResponse.noContent();
}

/**
* Delete a Kafka Streams.
*
Expand All @@ -190,7 +140,7 @@ HttpResponse<Void> delete(String namespace, String stream, @QueryValue(defaultVa
* @return An HTTP response
*/
@Delete
HttpResponse<List<KafkaStream>> bulkDelete(
HttpResponse<List<KafkaStream>> delete(
String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/
package com.michelin.ns4kafka.controller.acl;

import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidAclDeleteOnlyAdmin;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidImmutableField;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidNotFound;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidSelfAssignedAclDelete;
import static com.michelin.ns4kafka.util.enumation.Kind.ACCESS_CONTROL_ENTRY;
import static io.micronaut.core.util.StringUtils.EMPTY_STRING;
Expand Down Expand Up @@ -106,23 +104,6 @@ public List<AccessControlEntry> list(
};
}

/**
* Get an ACL by namespace and name.
*
* @param namespace The name
* @param acl The ACL name
* @return The ACL
* @deprecated use {@link #list(String, Optional, String)} instead.
*/
@Get("/{acl}")
@Deprecated(since = "1.12.0")
public Optional<AccessControlEntry> get(String namespace, String acl) {
return aclService.findAllRelatedToNamespace(getNamespace(namespace)).stream()
.filter(accessControlEntry ->
accessControlEntry.getMetadata().getName().equals(acl))
.findFirst();
}

/**
* Create an ACL.
*
Expand Down Expand Up @@ -195,7 +176,7 @@ public HttpResponse<AccessControlEntry> apply(
* @return An HTTP response
*/
@Delete
public HttpResponse<List<AccessControlEntry>> bulkDelete(
public HttpResponse<List<AccessControlEntry>> delete(
Authentication authentication,
String namespace,
@QueryValue(defaultValue = "*") String name,
Expand Down Expand Up @@ -235,45 +216,6 @@ public HttpResponse<List<AccessControlEntry>> bulkDelete(
return HttpResponse.ok(acls);
}

/**
* Delete an ACL.
*
* @param authentication The authentication entity
* @param namespace The namespace
* @param name The ACL name
* @param dryrun Is dry run mode or not?
* @return An HTTP response
* @deprecated use {@link #bulkDelete(Authentication, String, String, boolean)} instead.
*/
@Delete("/{name}{?dryrun}")
@Deprecated(since = "1.13.0")
public HttpResponse<Void> delete(
Authentication authentication,
String namespace,
String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
AccessControlEntry accessControlEntry = aclService
.findByName(namespace, name)
.orElseThrow(() -> new ResourceValidationException(ACCESS_CONTROL_ENTRY, name, invalidNotFound(name)));

boolean isAdmin = authentication.getRoles().contains(ResourceBasedSecurityRule.IS_ADMIN);
boolean isSelfAssignedAcl =
namespace.equals(accessControlEntry.getSpec().getGrantedTo());

if (isSelfAssignedAcl && !isAdmin) {
throw new ResourceValidationException(ACCESS_CONTROL_ENTRY, name, invalidAclDeleteOnlyAdmin(name));
}

if (dryrun) {
return HttpResponse.noContent();
}

sendEventLog(accessControlEntry, ApplyStatus.DELETED, accessControlEntry.getSpec(), null, EMPTY_STRING);

aclService.delete(accessControlEntry);
return HttpResponse.noContent();
}

/** ACL scope. */
public enum AclLimit {
/** Returns all ACL scopes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ public Flux<ConnectCluster> list(String namespace, @QueryValue(defaultValue = "*
return connectClusterService.findByWildcardNameWithOwnerPermissionAndStatus(getNamespace(namespace), name);
}

/**
* Get a Kafka Connect clusters by namespace and name.
*
* @param namespace The namespace
* @param connectCluster The name
* @return A Kafka Connect cluster
* @deprecated use list(String, String name) instead.
*/
@Get("/{connectCluster}")
@Deprecated(since = "1.12.0")
public Optional<ConnectCluster> get(String namespace, String connectCluster) {
return connectClusterService.findByNameWithOwnerPermission(getNamespace(namespace), connectCluster);
}

/**
* Create a Kafka Connect cluster.
*
Expand Down Expand Up @@ -179,58 +165,6 @@ public Mono<HttpResponse<ConnectCluster>> apply(
});
}

/**
* Delete a Kafka Connect cluster.
*
* @param namespace The current namespace
* @param connectCluster The current connect cluster name to delete
* @param dryrun Run in dry mode or not
* @return A HTTP response
* @deprecated use {@link #bulkDelete(String, String, boolean, boolean, boolean)} instead.
*/
@Delete("/{connectCluster}{?dryrun}")
@Deprecated(since = "1.13.0")
public HttpResponse<Void> delete(
String namespace, String connectCluster, @QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

List<String> validationErrors = new ArrayList<>();
if (!connectClusterService.isNamespaceOwnerOfConnectCluster(ns, connectCluster)) {
validationErrors.add(invalidOwner(connectCluster));
}

List<Connector> connectors = connectorService.findAllByConnectCluster(ns, connectCluster);
if (!connectors.isEmpty()) {
validationErrors.add(invalidConnectClusterDeleteOperation(connectCluster, connectors));
}

if (!validationErrors.isEmpty()) {
throw new ResourceValidationException(CONNECT_CLUSTER, connectCluster, validationErrors);
}

Optional<ConnectCluster> optionalConnectCluster =
connectClusterService.findByNameWithOwnerPermission(ns, connectCluster);

if (optionalConnectCluster.isEmpty()) {
return HttpResponse.notFound();
}

if (dryrun) {
return HttpResponse.noContent();
}

sendEventLog(
optionalConnectCluster.get(),
ApplyStatus.DELETED,
optionalConnectCluster.get().getSpec(),
null,
EMPTY_STRING);

connectClusterService.delete(optionalConnectCluster.get());

return HttpResponse.noContent();
}

/**
* Delete Kafka Connect clusters.
*
Expand All @@ -242,7 +176,7 @@ public HttpResponse<Void> delete(
* @return A reactive HTTP response
*/
@Delete
public Mono<HttpResponse<List<ConnectCluster>>> bulkDelete(
public Mono<HttpResponse<List<ConnectCluster>>> delete(
String namespace,
@QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun,
Expand Down
Loading