Skip to content

Commit

Permalink
Add an unleash feature flag to enable Kessel in recipients-resolver m…
Browse files Browse the repository at this point in the history
…odule (#3214)
  • Loading branch information
g-duval authored Dec 17, 2024
1 parent fed8da9 commit 1cd013d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redhat.cloud.notifications.recipients.config;

import com.redhat.cloud.notifications.unleash.ToggleRegistry;
import com.redhat.cloud.notifications.unleash.UnleashContextBuilder;
import io.getunleash.Unleash;
import io.quarkus.logging.Log;
import jakarta.annotation.PostConstruct;
Expand Down Expand Up @@ -33,7 +34,6 @@ public class RecipientsResolverConfig {
public static final String MBOP_APITOKEN = "notifications.recipients-resolver.mbop.api_token";
public static final String MBOP_CLIENT_ID = "notifications.recipients-resolver.mbop.client_id";
private static final String MBOP_ENV = "notifications.recipients-resolver.mbop.env";
private static final String NOTIFICATIONS_RECIPIENTS_RESOLVER_USE_KESSEL_ENABLED = "notifications.recipients-resolver.use.kessel.enabled";
private static final String KESSEL_TARGET_URL = "notifications.recipients-resolver.kessel.target-url";
private static final String KESSEL_USE_SECURE_CLIENT = "relations-api.is-secure-clients";

Expand Down Expand Up @@ -80,9 +80,6 @@ public class RecipientsResolverConfig {
@ConfigProperty(name = MBOP_ENV, defaultValue = "na")
String mbopEnv;

@ConfigProperty(name = NOTIFICATIONS_RECIPIENTS_RESOLVER_USE_KESSEL_ENABLED, defaultValue = "false")
boolean useKesselEnabled;

@ConfigProperty(name = KESSEL_TARGET_URL, defaultValue = "localhost:9000")
String kesselTargetUrl;

Expand Down Expand Up @@ -123,7 +120,7 @@ void logConfigAtStartup(@Observes Startup event) {
config.put(RETRY_MAX_BACKOFF, getMaxRetryBackoff());
config.put(WARN_IF_DURATION_EXCEEDS, getLogTooLongRequestLimit());
config.put(UNLEASH, unleashEnabled);
config.put(NOTIFICATIONS_RECIPIENTS_RESOLVER_USE_KESSEL_ENABLED, isUseKesselEnabled());
config.put(useKesselToggle, isUseKesselEnabled(null));
config.put(KESSEL_TARGET_URL, getKesselTargetUrl());
config.put(KESSEL_USE_SECURE_CLIENT, isKesselUseSecureClient());

Expand All @@ -149,9 +146,12 @@ public boolean isFetchUsersWithRbacEnabled() {
}
}

public boolean isUseKesselEnabled() {
// TODO read this toggle from unleash when Kessel will be available on stage
return useKesselEnabled;
public boolean isUseKesselEnabled(String orgId) {
if (unleashEnabled) {
return unleash.isEnabled(useKesselToggle, UnleashContextBuilder.buildUnleashContextWithOrgId(orgId), false);
} else {
return false;
}
}

public int getMaxResultsPerPage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Set<User> recipientUsers(String orgId, RecipientSettings request, Option
}

final Set<String> authorizedUsers = new HashSet<>();
if (recipientsResolverConfig.isUseKesselEnabled() && !fetchedUsers.isEmpty() && null != recipientsAuthorizationCriterion) {
if (recipientsResolverConfig.isUseKesselEnabled(orgId) && !fetchedUsers.isEmpty() && null != recipientsAuthorizationCriterion) {
authorizedUsers.addAll(findAuthorizedUsersWithCriterion(recipientsAuthorizationCriterion));
}

Expand All @@ -86,7 +86,7 @@ private Set<User> recipientUsers(String orgId, RecipientSettings request, Option
return true;
}

if (recipientsResolverConfig.isUseKesselEnabled() && null != recipientsAuthorizationCriterion && !authorizedUsers.contains(lowerCaseUsername)) {
if (recipientsResolverConfig.isUseKesselEnabled(orgId) && null != recipientsAuthorizationCriterion && !authorizedUsers.contains(lowerCaseUsername)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -135,7 +136,7 @@ void testNotSubscribedByDefaultAndAdminsOnlyWithOrWithoutKessel(boolean useKesse
RecipientsAuthorizationCriterion externalAuthorizationCriteria = null;
// update Kessel feature flag only if use Kessel is true, to keep check on default behaviour
if (useKessel) {
when(recipientsResolverConfig.isUseKesselEnabled()).thenReturn(useKessel);
when(recipientsResolverConfig.isUseKesselEnabled(anyString())).thenReturn(useKessel);
}
if (useJsonObjectAsAuthData) {
Type kesselAssetType = new Type();
Expand Down

0 comments on commit 1cd013d

Please sign in to comment.