Skip to content

Commit

Permalink
Merge pull request #258 from kit-data-manager/development
Browse files Browse the repository at this point in the history
Prepare next release
  • Loading branch information
VolkerHartmann authored Apr 12, 2024
2 parents 7390374 + a2175b9 commit 7c3eb01
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 170 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
* Additional Elastic proxy endpoint added which reflects the correct Elastic API, i.e., is available via /api/v1/{index}/_search

### Changed

Expand All @@ -17,7 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [1.3.0] - 2024-04-12

### Added
* Additional Elastic proxy endpoint added which reflects the correct Elastic API, i.e., is available via /api/v1/{index}/_search
* ADMINISTRATOR role is now properly evaluated in search requests by @github-actions in https://github.com/kit-data-manager/service-base/pull/254

### Security
* Bump commons-io:commons-io from 2.16.0 to 2.16.1
* Bump io.github.gradle-nexus.publish-plugin from 2.0.0-rc-2 to 2.0.0

## [1.2.1] - 2024-04-02

Expand Down Expand Up @@ -277,7 +284,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- none

[Unreleased]: https://github.com/kit-data-manager/service-base/compare/v1.2.1...HEAD
[Unreleased]: https://github.com/kit-data-manager/service-base/compare/v1.3.0...HEAD
[1.3.0]: https://github.com/kit-data-manager/service-base/compare/v1.2.1...v1.3.0
[1.2.1]: https://github.com/kit-data-manager/service-base/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/kit-data-manager/service-base/compare/v1.1.1...v1.2.0
[1.1.1]: https://github.com/kit-data-manager/service-base/compare/v1.1.0...v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
// plugins for release and publishing to maven repo
id "signing"
id "net.researchgate.release" version "3.0.2"
id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-2"
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
id 'maven-publish'
}

Expand Down Expand Up @@ -83,7 +83,7 @@ dependencies {

implementation "org.apache.commons:commons-lang3:3.14.0"
implementation "commons-validator:commons-validator:1.8.0"
implementation "commons-io:commons-io:2.16.0"
implementation "commons-io:commons-io:2.16.1"
// http client uses commons-codec
implementation 'org.apache.httpcomponents:httpclient:4.5.14'

Expand Down
92 changes: 46 additions & 46 deletions src/main/java/edu/kit/datamanager/controller/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,55 +52,55 @@
@ConditionalOnExpression("${repo.search.enabled:false}")
public class SearchController {

static final Logger LOG = LoggerFactory.getLogger(SearchController.class);
static final Logger LOG = LoggerFactory.getLogger(SearchController.class);

@Autowired
private SearchConfiguration searchConfiguration;
@Autowired
private SearchConfiguration searchConfiguration;

public static final String POST_FILTER = "post_filter";
public static final String POST_FILTER = "post_filter";

@Operation(operationId = "search",
summary = "Search for resources.",
description = "Search for resources using the configured Elastic backend. This endpoint serves as direct proxy to the RESTful endpoint of Elastic. "
+ "In the body, a query document following the Elastic query format has to be provided. Format errors are returned directly from Elastic. "
+ "This endpoint also supports authentication and authorization. User information obtained via JWT is applied to the provided query as "
+ "post filter. If a post filter was already provided with the query it will be replaced. Furthermore, this endpoint supports pagination. "
+ "'page' and 'size' query parameters are translated into the Elastic attributes 'from' and 'size' automatically, "
+ "if not already provided within the query by the caller.", security = {
@SecurityRequirement(name = "bearer-jwt")})
@RequestMapping(value = "/{index}/_search", method = RequestMethod.POST)
@ResponseBody
@PageableAsQueryParam
public ResponseEntity<?> proxy(
@PathVariable("index") final String index,
@RequestBody JsonNode body,
ProxyExchange<JsonNode> proxy,
@Parameter(hidden = true) final Pageable pgbl) throws Exception {
LOG.trace("Provided Elastic query: '{}'", body.toString());
@Operation(operationId = "search",
summary = "Search for resources.",
description = "Search for resources using the configured Elastic backend. This endpoint serves as direct proxy to the RESTful endpoint of Elastic. "
+ "In the body, a query document following the Elastic query format has to be provided. Format errors are returned directly from Elastic. "
+ "This endpoint also supports authentication and authorization. User information obtained via JWT is applied to the provided query as "
+ "post filter. If a post filter was already provided with the query it will be replaced. Furthermore, this endpoint supports pagination. "
+ "'page' and 'size' query parameters are translated into the Elastic attributes 'from' and 'size' automatically, "
+ "if not already provided within the query by the caller.", security = {
@SecurityRequirement(name = "bearer-jwt")})
@RequestMapping(value = "/{index}/_search", method = RequestMethod.POST)
@ResponseBody
@PageableAsQueryParam
public ResponseEntity<?> proxy(
@PathVariable("index") final String index,
@RequestBody JsonNode body,
ProxyExchange<JsonNode> proxy,
@Parameter(hidden = true) final Pageable pgbl) throws Exception {
LOG.trace("Provided Elastic query: '{}'", body.toString());

// Set or replace post-filter
ObjectNode on = (ObjectNode) body;
ElasticSearchUtil.addPaginationInformation(on, pgbl.getPageNumber(), pgbl.getPageSize());
ElasticSearchUtil.buildPostFilter(on);
// Set or replace post-filter
ObjectNode on = (ObjectNode) body;
ElasticSearchUtil.addPaginationInformation(on, pgbl.getPageNumber(), pgbl.getPageSize());
ElasticSearchUtil.buildPostFilter(on);

LOG.trace("Forwarding Elastic query to {}.", searchConfiguration.getUrl() + "/" + index + "/_search");
return proxy.uri(searchConfiguration.getUrl() + "/" + index + "/_search").post();
}
@Operation(operationId = "search",
summary = "Search for resources.",
description = "This endpoint is identical to _search but kept for "
+ "legacy reasons. In future implementations _search should "
+ "be used as Elatic also offers _search and some libraries "
+ "expect _search as default endpoint.", security = {
@SecurityRequirement(name = "bearer-jwt")})
@RequestMapping(value = "/search", method = RequestMethod.POST)
@ResponseBody
@PageableAsQueryParam
public ResponseEntity<?> proxy_legacy(
@RequestBody JsonNode body,
ProxyExchange<JsonNode> proxy,
@Parameter(hidden = true) final Pageable pgbl) throws Exception {
return proxy(searchConfiguration.getIndex(), body, proxy, pgbl);
}
LOG.trace("Forwarding Elastic query to {}.", searchConfiguration.getUrl() + "/" + index + "/_search");
return proxy.uri(searchConfiguration.getUrl() + "/" + index + "/_search").post();
}

@Operation(operationId = "search",
summary = "Search for resources.",
description = "This endpoint is identical to _search but kept for "
+ "legacy reasons. In future implementations _search should "
+ "be used as Elatic also offers _search and some libraries "
+ "expect _search as default endpoint.", security = {
@SecurityRequirement(name = "bearer-jwt")})
@RequestMapping(value = "/search", method = RequestMethod.POST)
@ResponseBody
@PageableAsQueryParam
public ResponseEntity<?> proxy_legacy(
@RequestBody JsonNode body,
ProxyExchange<JsonNode> proxy,
@Parameter(hidden = true) final Pageable pgbl) throws Exception {
return proxy(searchConfiguration.getIndex(), body, proxy, pgbl);
}
}
Loading

0 comments on commit 7c3eb01

Please # to comment.