diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/resource/EntityEditorResource.java b/gateway-ha/src/main/java/io/trino/gateway/ha/resource/EntityEditorResource.java index 7fffaa26d..c7cc65f86 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/resource/EntityEditorResource.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/resource/EntityEditorResource.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.inject.Inject; import io.airlift.log.Logger; import io.trino.gateway.ha.clustermonitor.ClusterStats; @@ -90,7 +89,7 @@ public Response updateEntity( EntityType entityType = EntityType.valueOf(entityTypeStr); try { switch (entityType) { - case GATEWAY_BACKEND: + case GATEWAY_BACKEND -> { //TODO: make the gateway backend database sensitive ProxyBackendConfiguration backend = OBJECT_MAPPER.readValue(jsonPayload, ProxyBackendConfiguration.class); @@ -105,13 +104,13 @@ public Response updateEntity( ClusterStats.builder(backend.getName()) .trinoStatus(trinoStatus) .build()); - break; - case RESOURCE_GROUP: + } + case RESOURCE_GROUP -> { ResourceGroupsDetail resourceGroupDetails = OBJECT_MAPPER.readValue(jsonPayload, ResourceGroupsDetail.class); resourceGroupsManager.updateResourceGroup(resourceGroupDetails, database); - break; - case SELECTOR: + } + case SELECTOR -> { SelectorsDetail selectorDetails = OBJECT_MAPPER.readValue(jsonPayload, SelectorsDetail.class); List oldSelectorDetails = @@ -123,8 +122,7 @@ public Response updateEntity( else { resourceGroupsManager.createSelector(selectorDetails, database); } - break; - default: + } } } catch (IOException e) { @@ -143,15 +141,10 @@ public Response getAllEntitiesForType( { EntityType entityType = EntityType.valueOf(entityTypeStr); - switch (entityType) { - case GATEWAY_BACKEND: - return Response.ok(gatewayBackendManager.getAllBackends()).build(); - case RESOURCE_GROUP: - return Response.ok(resourceGroupsManager.readAllResourceGroups(database)).build(); - case SELECTOR: - return Response.ok(resourceGroupsManager.readAllSelectors(database)).build(); - default: - } - return Response.ok(ImmutableList.of()).build(); + return switch (entityType) { + case GATEWAY_BACKEND -> Response.ok(gatewayBackendManager.getAllBackends()).build(); + case RESOURCE_GROUP -> Response.ok(resourceGroupsManager.readAllResourceGroups(database)).build(); + case SELECTOR -> Response.ok(resourceGroupsManager.readAllSelectors(database)).build(); + }; } } diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/security/LbAuthorizer.java b/gateway-ha/src/main/java/io/trino/gateway/ha/security/LbAuthorizer.java index 456971560..c415f1b55 100644 --- a/gateway-ha/src/main/java/io/trino/gateway/ha/security/LbAuthorizer.java +++ b/gateway-ha/src/main/java/io/trino/gateway/ha/security/LbAuthorizer.java @@ -35,18 +35,15 @@ public boolean authorize(LbPrincipal principal, String role, @Nullable ContainerRequestContext ctx) { - switch (role) { - case "ADMIN": - return hasRole(principal, role, configuration.getAdmin()); - case "USER": - return hasRole(principal, role, configuration.getUser()); - case "API": - return hasRole(principal, role, configuration.getApi()); - default: - log.warn("User '%s' with role %s has no regex match based on ldap search", - principal.getName(), role); - return false; - } + return switch (role) { + case "ADMIN" -> hasRole(principal, role, configuration.getAdmin()); + case "USER" -> hasRole(principal, role, configuration.getUser()); + case "API" -> hasRole(principal, role, configuration.getApi()); + default -> { + log.warn("User '%s' with role %s has no regex match based on ldap search", principal.getName(), role); + yield false; + } + }; } private static boolean hasRole(LbPrincipal principal, String role, String regex) diff --git a/pom.xml b/pom.xml index 9140802d1..a5e8ce18c 100644 --- a/pom.xml +++ b/pom.xml @@ -106,6 +106,7 @@ -Xep:InvalidThrows:ERROR \ -Xep:JavaTimeDefaultTimeZone:ERROR \ -Xep:MissingOverride:ERROR \ + -Xep:StatementSwitchToExpressionSwitch:ERROR \ -Xep:StringCaseLocaleUsage:ERROR \ -Xep:TraditionalSwitchExpression:ERROR \ -Xep:TypeParameterUnusedInFormals:ERROR \