Skip to content

Commit

Permalink
Revert "Handle wildcard parameter in RoleBinding deletion API (#457)"
Browse files Browse the repository at this point in the history
This reverts commit a376b8a.
  • Loading branch information
ThomasCAI-mlv authored Oct 8, 2024
1 parent a376b8a commit a67dd11
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<RoleBinding> list(String namespace, @QueryValue(defaultValue = "*")
* @param namespace The namespace
* @param name The role binding name
* @return A role binding
* @deprecated use {@link #list(String, String)} instead.
* @deprecated use list(String, String name) instead.
*/
@Get("/{name}")
@Deprecated(since = "1.12.0")
Expand Down Expand Up @@ -107,13 +107,11 @@ public HttpResponse<RoleBinding> apply(String namespace, @Valid @Body RoleBindin
*
* @param namespace The namespace
* @param name The role binding
* @param dryrun Is dry run mode or not?
* @param dryrun Is dry run mode or not ?
* @return An HTTP response
* @deprecated use {@link #bulkDelete(String, String, boolean)} instead.
*/
@Delete("/{name}{?dryrun}")
@Status(HttpStatus.NO_CONTENT)
@Deprecated(since = "1.13.0")
public HttpResponse<Void> delete(String namespace, String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
Optional<RoleBinding> roleBinding = roleBindingService.findByName(namespace, name);
Expand All @@ -138,39 +136,4 @@ public HttpResponse<Void> delete(String namespace, String name,
roleBindingService.delete(roleBindingToDelete);
return HttpResponse.noContent();
}

/**
* Delete role bindings.
*
* @param namespace The namespace
* @param name The name parameter
* @param dryrun Is dry run mode or not?
* @return An HTTP response
*/
@Status(HttpStatus.NO_CONTENT)
@Delete
public HttpResponse<Void> bulkDelete(String namespace, @QueryValue(defaultValue = "*") String name,
@QueryValue(defaultValue = "false") boolean dryrun) {
List<RoleBinding> roleBindings = roleBindingService.findByWildcardName(namespace, name);
if (roleBindings.isEmpty()) {
return HttpResponse.notFound();
}

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

roleBindings.forEach(roleBinding -> {
sendEventLog(
roleBinding,
ApplyStatus.deleted,
roleBinding.getSpec(),
null,
EMPTY_STRING
);
roleBindingService.delete(roleBinding);
});

return HttpResponse.noContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.michelin.ns4kafka.service.NamespaceService;
import com.michelin.ns4kafka.service.RoleBindingService;
import io.micronaut.context.event.ApplicationEventPublisher;
import io.micronaut.http.HttpStatus;
import io.micronaut.security.utils.SecurityService;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -163,7 +162,6 @@ void shouldCreateRoleBindingInDryRunMode() {
}

@Test
@SuppressWarnings("deprecation")
void shouldDeleteRoleBinding() {
RoleBinding rolebinding = RoleBinding.builder()
.metadata(Metadata.builder()
Expand All @@ -185,7 +183,6 @@ void shouldDeleteRoleBinding() {
}

@Test
@SuppressWarnings("deprecation")
void shouldDeleteRoleBindingInDryRunMode() {
RoleBinding rolebinding = RoleBinding.builder()
.metadata(Metadata.builder()
Expand All @@ -200,62 +197,6 @@ void shouldDeleteRoleBindingInDryRunMode() {
verify(roleBindingService, never()).delete(any());
}

@Test
void shouldDeleteRoleBindings() {
RoleBinding rolebinding1 = RoleBinding.builder()
.metadata(Metadata.builder()
.name("test.rolebinding1")
.build())
.build();
RoleBinding rolebinding2 = RoleBinding.builder()
.metadata(Metadata.builder()
.name("test.rolebinding2")
.build())
.build();

when(roleBindingService.findByWildcardName(any(), any()))
.thenReturn(List.of(rolebinding1, rolebinding2));
when(securityService.username())
.thenReturn(Optional.of("test-user"));
when(securityService.hasRole(ResourceBasedSecurityRule.IS_ADMIN))
.thenReturn(false);
doNothing().when(applicationEventPublisher).publishEvent(any());

assertDoesNotThrow(
() -> roleBindingController.bulkDelete("test", "test.rolebinding*", false)
);
}

@Test
void shouldDeleteRoleBindingsInDryRunMode() {
RoleBinding rolebinding1 = RoleBinding.builder()
.metadata(Metadata.builder()
.name("test.rolebinding1")
.build())
.build();
RoleBinding rolebinding2 = RoleBinding.builder()
.metadata(Metadata.builder()
.name("test.rolebinding2")
.build())
.build();

when(roleBindingService.findByWildcardName(any(), any()))
.thenReturn(List.of(rolebinding1, rolebinding2));

roleBindingController.bulkDelete("test", "test.rolebinding*", true);
verify(roleBindingService, never()).delete(any());
}

@Test
void shouldNotDeleteRoleBindingsWhenNotFound() {
when(roleBindingService.findByWildcardName(any(), any()))
.thenReturn(List.of());

var response = roleBindingController.bulkDelete("test", "test.rolebinding*", false);
verify(roleBindingService, never()).delete(any());
assertEquals(HttpStatus.NOT_FOUND, response.getStatus());
}

@Test
void shouldListRoleBindingsWithNameParameter() {
RoleBinding rb1 = RoleBinding.builder()
Expand Down

0 comments on commit a67dd11

Please sign in to comment.