Skip to content

Commit 8a7b968

Browse files
committed
Enable StatementSwitchToExpressionSwitch rule
1 parent 89bbae8 commit 8a7b968

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/resource/EntityEditorResource.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import com.fasterxml.jackson.databind.ObjectMapper;
1717
import com.google.common.base.Strings;
18-
import com.google.common.collect.ImmutableList;
1918
import com.google.inject.Inject;
2019
import io.airlift.log.Logger;
2120
import io.trino.gateway.ha.clustermonitor.ClusterStats;
@@ -90,7 +89,7 @@ public Response updateEntity(
9089
EntityType entityType = EntityType.valueOf(entityTypeStr);
9190
try {
9291
switch (entityType) {
93-
case GATEWAY_BACKEND:
92+
case GATEWAY_BACKEND -> {
9493
//TODO: make the gateway backend database sensitive
9594
ProxyBackendConfiguration backend =
9695
OBJECT_MAPPER.readValue(jsonPayload, ProxyBackendConfiguration.class);
@@ -105,13 +104,13 @@ public Response updateEntity(
105104
ClusterStats.builder(backend.getName())
106105
.trinoStatus(trinoStatus)
107106
.build());
108-
break;
109-
case RESOURCE_GROUP:
107+
}
108+
case RESOURCE_GROUP -> {
110109
ResourceGroupsDetail resourceGroupDetails = OBJECT_MAPPER.readValue(jsonPayload,
111110
ResourceGroupsDetail.class);
112111
resourceGroupsManager.updateResourceGroup(resourceGroupDetails, database);
113-
break;
114-
case SELECTOR:
112+
}
113+
case SELECTOR -> {
115114
SelectorsDetail selectorDetails = OBJECT_MAPPER.readValue(jsonPayload,
116115
SelectorsDetail.class);
117116
List<SelectorsDetail> oldSelectorDetails =
@@ -123,8 +122,7 @@ public Response updateEntity(
123122
else {
124123
resourceGroupsManager.createSelector(selectorDetails, database);
125124
}
126-
break;
127-
default:
125+
}
128126
}
129127
}
130128
catch (IOException e) {
@@ -143,15 +141,10 @@ public Response getAllEntitiesForType(
143141
{
144142
EntityType entityType = EntityType.valueOf(entityTypeStr);
145143

146-
switch (entityType) {
147-
case GATEWAY_BACKEND:
148-
return Response.ok(gatewayBackendManager.getAllBackends()).build();
149-
case RESOURCE_GROUP:
150-
return Response.ok(resourceGroupsManager.readAllResourceGroups(database)).build();
151-
case SELECTOR:
152-
return Response.ok(resourceGroupsManager.readAllSelectors(database)).build();
153-
default:
154-
}
155-
return Response.ok(ImmutableList.of()).build();
144+
return switch (entityType) {
145+
case GATEWAY_BACKEND -> Response.ok(gatewayBackendManager.getAllBackends()).build();
146+
case RESOURCE_GROUP -> Response.ok(resourceGroupsManager.readAllResourceGroups(database)).build();
147+
case SELECTOR -> Response.ok(resourceGroupsManager.readAllSelectors(database)).build();
148+
};
156149
}
157150
}

gateway-ha/src/main/java/io/trino/gateway/ha/security/LbAuthorizer.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ public boolean authorize(LbPrincipal principal,
3535
String role,
3636
@Nullable ContainerRequestContext ctx)
3737
{
38-
switch (role) {
39-
case "ADMIN":
40-
return hasRole(principal, role, configuration.getAdmin());
41-
case "USER":
42-
return hasRole(principal, role, configuration.getUser());
43-
case "API":
44-
return hasRole(principal, role, configuration.getApi());
45-
default:
46-
log.warn("User '%s' with role %s has no regex match based on ldap search",
47-
principal.getName(), role);
48-
return false;
49-
}
38+
return switch (role) {
39+
case "ADMIN" -> hasRole(principal, role, configuration.getAdmin());
40+
case "USER" -> hasRole(principal, role, configuration.getUser());
41+
case "API" -> hasRole(principal, role, configuration.getApi());
42+
default -> {
43+
log.warn("User '%s' with role %s has no regex match based on ldap search", principal.getName(), role);
44+
yield false;
45+
}
46+
};
5047
}
5148

5249
private static boolean hasRole(LbPrincipal principal, String role, String regex)

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
-Xep:InvalidThrows:ERROR \
107107
-Xep:JavaTimeDefaultTimeZone:ERROR \
108108
-Xep:MissingOverride:ERROR \
109+
-Xep:StatementSwitchToExpressionSwitch:ERROR \
109110
-Xep:StringCaseLocaleUsage:ERROR \
110111
-Xep:TraditionalSwitchExpression:ERROR \
111112
-Xep:TypeParameterUnusedInFormals:ERROR \

0 commit comments

Comments
 (0)