Skip to content

Commit

Permalink
remove spotless on/off
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Pleskach <ples@aiven.io>
  • Loading branch information
willyborankin committed Aug 19, 2023
1 parent 30a8dd1 commit dedbd64
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 122 deletions.
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ spotbugsTest {
enabled = false
}

spotless {
java {
toggleOffOn()
}
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,36 @@ protected CType getConfigType() {
}

private void accountApiRequestHandlers(RequestHandler.RequestHandlersBuilder requestHandlersBuilder) {
// spotless:off
requestHandlersBuilder.allMethodsNotImplemented()
.override(Method.GET, (channel, request, client) ->
withUserAndRemoteAddress().map(
userAndRemoteAddress ->
loadConfiguration(getConfigType(), false, false)
.map(configuration ->
ValidationResult.success(
Triple.of(
userAndRemoteAddress.getLeft(),
userAndRemoteAddress.getRight(), configuration
)
)
)
).valid(userRemoteAddressAndConfig -> {
final var user = userRemoteAddressAndConfig.getLeft();
final var remoteAddress = userRemoteAddressAndConfig.getMiddle();
final var configuration = userRemoteAddressAndConfig.getRight();
userAccount(channel, user, remoteAddress, configuration);
}).error((status, toXContent) -> Responses.response(channel, status, toXContent))
).onChangeRequest(Method.PUT, request ->
withUserAndRemoteAddress()
.map(userAndRemoteAddress ->
loadConfigurationWithRequestContent(
userAndRemoteAddress.getLeft().getName(),
request,
endpointValidator.createRequestContentValidator()
)
)
.map(endpointValidator::entityExists)
.map(endpointValidator::onConfigChange)
.map(this::passwordCanBeValidated)
.map(this::updateUserPassword)
);
// spotless:on
.override(
Method.GET,
(channel, request, client) -> withUserAndRemoteAddress().map(
userAndRemoteAddress -> loadConfiguration(getConfigType(), false, false).map(
configuration -> ValidationResult.success(
Triple.of(userAndRemoteAddress.getLeft(), userAndRemoteAddress.getRight(), configuration)
)
)
).valid(userRemoteAddressAndConfig -> {
final var user = userRemoteAddressAndConfig.getLeft();
final var remoteAddress = userRemoteAddressAndConfig.getMiddle();
final var configuration = userRemoteAddressAndConfig.getRight();
userAccount(channel, user, remoteAddress, configuration);
}).error((status, toXContent) -> Responses.response(channel, status, toXContent))
)
.onChangeRequest(
Method.PUT,
request -> withUserAndRemoteAddress().map(
userAndRemoteAddress -> loadConfigurationWithRequestContent(
userAndRemoteAddress.getLeft().getName(),
request,
endpointValidator.createRequestContentValidator()
)
)
.map(endpointValidator::entityExists)
.map(endpointValidator::onConfigChange)
.map(this::passwordCanBeValidated)
.map(this::updateUserPassword)
);
}

private void userAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,31 @@ protected CType getConfigType() {
}

private void internalUsersApiRequestHandlers(RequestHandler.RequestHandlersBuilder requestHandlersBuilder) {
// spotless:off
requestHandlersBuilder
// Overrides the GET request functionality to allow for the special case of requesting an auth token.
.override(Method.POST, (channel, request, client) ->
withAuthTokenPath(request)
.map(username ->
loadConfiguration(getConfigType(), true, false)
.map(configuration -> ValidationResult.success(SecurityConfiguration.of(username, configuration)))
)
.map(endpointValidator::entityExists)
.valid(securityConfiguration -> generateAuthToken(channel, securityConfiguration))
.error((status, toXContent) -> Responses.response(channel, status, toXContent)))
.onChangeRequest(Method.PATCH, this::processPatchRequest)
.onChangeRequest(Method.PUT, request ->
withRequiredResourceName(request)
.map(username -> loadConfigurationWithRequestContent(username, request, endpointValidator.createRequestContentValidator()))
.map(endpointValidator::hasRightsToChangeEntity)
.map(this::validateSecurityRoles)
.map(securityConfiguration -> createOrUpdateAccount(request, securityConfiguration))
.map(this::validateAndUpdatePassword)
.map(this::addEntityToConfig)
);
// spotless:on
// Overrides the GET request functionality to allow for the special case of requesting an auth token.
.override(
Method.POST,
(channel, request, client) -> withAuthTokenPath(request).map(
username -> loadConfiguration(getConfigType(), true, false).map(
configuration -> ValidationResult.success(SecurityConfiguration.of(username, configuration))
)
)
.map(endpointValidator::entityExists)
.valid(securityConfiguration -> generateAuthToken(channel, securityConfiguration))
.error((status, toXContent) -> Responses.response(channel, status, toXContent))
)
.onChangeRequest(Method.PATCH, this::processPatchRequest)
.onChangeRequest(
Method.PUT,
request -> withRequiredResourceName(request).map(
username -> loadConfigurationWithRequestContent(username, request, endpointValidator.createRequestContentValidator())
)
.map(endpointValidator::hasRightsToChangeEntity)
.map(this::validateSecurityRoles)
.map(securityConfiguration -> createOrUpdateAccount(request, securityConfiguration))
.map(this::validateAndUpdatePassword)
.map(this::addEntityToConfig)
);
}

private ValidationResult<String> withAuthTokenPath(final RestRequest request) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,70 +150,69 @@ public RequestHandlersBuilder onChangeRequest(
if (!ON_CHANGE_REQUEST.contains(method)) {
throw new IllegalArgumentException("Unsupported HTTP method " + method + ". Supported are: " + ON_CHANGE_REQUEST);
}
// spotless:off
switch (method) {
case PATCH:
add(method, (channel, request, client) ->
mapper.apply(request)
.valid(securityConfiguration ->
saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse indexResponse) {
if (securityConfiguration.maybeEntityName().isPresent()) {
ok(channel, "'" + securityConfiguration.entityName() + "' updated.");
} else {
ok(channel, "Resource updated.");
}
}
}
)
).error((status, toXContent) -> response(channel, status, toXContent))
add(
method,
(channel, request, client) -> mapper.apply(request)
.valid(
securityConfiguration -> saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse indexResponse) {
if (securityConfiguration.maybeEntityName().isPresent()) {
ok(channel, "'" + securityConfiguration.entityName() + "' updated.");
} else {
ok(channel, "Resource updated.");
}
}
}
)
)
.error((status, toXContent) -> response(channel, status, toXContent))
);
break;
case PUT:
add(method, (channel, request, client) ->
mapper.apply(request)
.valid(securityConfiguration -> {
saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse response) {
if (securityConfiguration.entityExists()) {
ok(channel, "'" + securityConfiguration.entityName() + "' updated.");
} else {
created(channel, "'" + securityConfiguration.entityName() + "' created.");
}
}
}
);
}).error((status, toXContent) -> response(channel, status, toXContent)));
add(method, (channel, request, client) -> mapper.apply(request).valid(securityConfiguration -> {
saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse response) {
if (securityConfiguration.entityExists()) {
ok(channel, "'" + securityConfiguration.entityName() + "' updated.");
} else {
created(channel, "'" + securityConfiguration.entityName() + "' created.");
}
}
}
);
}).error((status, toXContent) -> response(channel, status, toXContent)));
break;
case DELETE:
Objects.requireNonNull(mapper, "onDeleteRequest request handler can't be null");
add(RestRequest.Method.DELETE, (channel, request, client) ->
mapper.apply(request)
.valid(securityConfiguration ->
saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse response) {
ok(channel, "'" + securityConfiguration.entityName() + "' deleted.");
}
}
)
)
.error((status, toXContent) -> response(channel, status, toXContent))
add(
RestRequest.Method.DELETE,
(channel, request, client) -> mapper.apply(request)
.valid(
securityConfiguration -> saveOrUpdateConfigurationHandler.apply(
client,
securityConfiguration.configuration(),
new AbstractApiAction.OnSucessActionListener<>(channel) {
@Override
public void onResponse(IndexResponse response) {
ok(channel, "'" + securityConfiguration.entityName() + "' deleted.");
}
}
)
)
.error((status, toXContent) -> response(channel, status, toXContent))
);
break;
}
// spotless:on
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ protected CType getConfigType() {
}

private void securitySSLCertsRequestHandlers(RequestHandler.RequestHandlersBuilder requestHandlersBuilder) {
// spotless:off
requestHandlersBuilder.withAccessHandler(this::accessHandler)
.allMethodsNotImplemented()
.verifyAccessForAllMethods()
.override(Method.GET, (channel, request, client) ->
withSecurityKeyStore()
.valid(keyStore -> loadCertificates(channel, keyStore))
.error((status, toXContent) -> Responses.response(channel, status, toXContent)))
.override(
Method.GET,
(channel, request, client) -> withSecurityKeyStore().valid(keyStore -> loadCertificates(channel, keyStore))
.error((status, toXContent) -> Responses.response(channel, status, toXContent))
)
.override(Method.PUT, (channel, request, client) -> withSecurityKeyStore().valid(keyStore -> {
if (!certificatesReloadEnabled) {
badRequest(
Expand All @@ -136,7 +136,6 @@ private void securitySSLCertsRequestHandlers(RequestHandler.RequestHandlersBuild
reloadCertificates(channel, request, keyStore);
}
}).error((status, toXContent) -> Responses.response(channel, status, toXContent)));
// spotless:on
}

private boolean accessHandler(final RestRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void checkGetAndPutWhitelistPermissions(final int expectedStatus, final
}
// FORBIDDEN FOR NON SUPER ADMIN
if (expectedStatus == HttpStatus.SC_FORBIDDEN) {
assertTrue(response.getBody().contains("API allowed only for super admin."));
assertTrue(response.getBody().contains("Access denied"));
}
// CHECK PUT REQUEST
response = rh.executePutRequest(
Expand Down

0 comments on commit dedbd64

Please sign in to comment.