Skip to content

Commit

Permalink
fix: error message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasBousselin committed Dec 4, 2024
1 parent e362720 commit cd692da
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion search-service/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ID>Filename:V0_29__JsonLd_migration.kt$db.migration.V0_29__JsonLd_migration.kt</ID>
<ID>LongMethod:AttributeInstanceService.kt$AttributeInstanceService$@Transactional suspend fun create(attributeInstance: AttributeInstance): Either&lt;APIException, Unit&gt;</ID>
<ID>LongMethod:EnabledAuthorizationServiceTests.kt$EnabledAuthorizationServiceTests$@Test fun `it should return serialized access control entities with other rigths if user is owner`()</ID>
<ID>LongMethod:EntityAccessControlHandler.kt$EntityAccessControlHandler$@PostMapping("/{subjectId}/attrs", consumes = [MediaType.APPLICATION_JSON_VALUE, JSON_LD_CONTENT_TYPE]) suspend fun addRightsOnEntities( @RequestHeader httpHeaders: HttpHeaders, @PathVariable subjectId: String, @RequestBody requestBody: Mono&lt;String&gt; ): ResponseEntity&lt;*&gt;</ID>
<ID>LongMethod:EntityAccessControlHandler.kt$EntityAccessControlHandler$@PostMapping("/{subjectId}/attrs", consumes = [MediaType.APPLICATION_JSON_VALUE, JSON_LD_CONTENT_TYPE]) suspend fun addRightsOnEntities( @RequestHeader httpHeaders: HttpHeaders, @PathVariable subjectId: String, @RequestBody requestBody: Mono&lt;String&gt;, @AllowedParameters @RequestParam queryParams: MultiValueMap&lt;String, String&gt; ): ResponseEntity&lt;*&gt;</ID>
<ID>LongMethod:LinkedEntityServiceTests.kt$LinkedEntityServiceTests$@Test fun `it should inline entities up to the asked 2nd level`()</ID>
<ID>LongMethod:PatchAttributeTests.kt$PatchAttributeTests.Companion$@JvmStatic fun mergePatchProvider(): Stream&lt;Arguments&gt;</ID>
<ID>LongMethod:PatchAttributeTests.kt$PatchAttributeTests.Companion$@JvmStatic fun partialUpdatePatchProvider(): Stream&lt;Arguments&gt;</ID>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.egm.stellio.search.authorization.web

import arrow.core.computations.ResultEffect.bind
import arrow.core.left
import arrow.core.raise.either
import com.egm.stellio.search.authorization.service.AuthorizationService
Expand All @@ -17,6 +18,8 @@ import com.egm.stellio.shared.model.NgsiLdRelationship
import com.egm.stellio.shared.model.toFinalRepresentation
import com.egm.stellio.shared.model.toNgsiLdAttribute
import com.egm.stellio.shared.model.toNgsiLdAttributes
import com.egm.stellio.shared.queryparameter.AllowedParameters
import com.egm.stellio.shared.queryparameter.QP
import com.egm.stellio.shared.util.AccessRight
import com.egm.stellio.shared.util.AuthContextModel.ALL_ASSIGNABLE_IAM_RIGHTS
import com.egm.stellio.shared.util.AuthContextModel.ALL_IAM_RIGHTS
Expand Down Expand Up @@ -56,7 +59,7 @@ import reactor.core.publisher.Mono
import java.net.URI

@RestController
@RequestMapping("/ngsi-ld/v1/entityAccessControl") // todo
@RequestMapping("/ngsi-ld/v1/entityAccessControl")
class EntityAccessControlHandler(
private val applicationProperties: ApplicationProperties,
private val entityAccessRightsService: EntityAccessRightsService,
Expand All @@ -66,7 +69,15 @@ class EntityAccessControlHandler(
@GetMapping("/entities", produces = [MediaType.APPLICATION_JSON_VALUE, JSON_LD_CONTENT_TYPE])
suspend fun getAuthorizedEntities(
@RequestHeader httpHeaders: HttpHeaders,
@RequestParam params: MultiValueMap<String, String>
@AllowedParameters(
implemented = [
QP.OPTIONS, QP.FORMAT, QP.COUNT, QP.OFFSET, QP.LIMIT, QP.ID, QP.TYPE, QP.ID_PATTERN, QP.ATTRS, QP.Q,
QP.GEOMETRY, QP.GEOREL, QP.COORDINATES, QP.GEOPROPERTY, QP.GEOMETRY_PROPERTY,
QP.LANG, QP.SCOPEQ, QP.CONTAINED_BY, QP.JOIN, QP.JOIN_LEVEL, QP.DATASET_ID,
],
notImplemented = [QP.PICK, QP.OMIT, QP.EXPAND_VALUES, QP.CSF, QP.ENTITY_MAP, QP.LOCAL, QP.VIA]
)
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()

Expand All @@ -75,7 +86,7 @@ class EntityAccessControlHandler(

val entitiesQuery = composeEntitiesQueryFromGet(
applicationProperties.pagination,
params,
queryParams,
contexts
).bind()

Expand All @@ -96,13 +107,13 @@ class EntityAccessControlHandler(

val compactedEntities = compactEntities(entities, contexts)

val ngsiLdDataRepresentation = parseRepresentations(params, mediaType)
val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType)
buildQueryResponse(
compactedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
count,
"/ngsi-ld/v1/entityAccessControl/entities",
entitiesQuery.paginationQuery,
params,
queryParams,
mediaType,
contexts
)
Expand All @@ -114,6 +125,14 @@ class EntityAccessControlHandler(
@GetMapping("/groups", produces = [MediaType.APPLICATION_JSON_VALUE, JSON_LD_CONTENT_TYPE])
suspend fun getGroupsMemberships(
@RequestHeader httpHeaders: HttpHeaders,
@AllowedParameters(
implemented = [
QP.OPTIONS, QP.FORMAT, QP.COUNT, QP.OFFSET, QP.LIMIT, QP.ID, QP.TYPE, QP.ID_PATTERN, QP.ATTRS, QP.Q,
QP.GEOMETRY, QP.GEOREL, QP.COORDINATES, QP.GEOPROPERTY, QP.GEOMETRY_PROPERTY,
QP.LANG, QP.SCOPEQ, QP.CONTAINED_BY, QP.JOIN, QP.JOIN_LEVEL, QP.DATASET_ID,
],
notImplemented = [QP.PICK, QP.OMIT, QP.EXPAND_VALUES, QP.CSF, QP.ENTITY_MAP, QP.LOCAL, QP.VIA]
)
@RequestParam params: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()
Expand Down Expand Up @@ -158,6 +177,14 @@ class EntityAccessControlHandler(
@GetMapping("/users", produces = [MediaType.APPLICATION_JSON_VALUE, JSON_LD_CONTENT_TYPE])
suspend fun getUsers(
@RequestHeader httpHeaders: HttpHeaders,
@AllowedParameters(
implemented = [
QP.OPTIONS, QP.FORMAT, QP.COUNT, QP.OFFSET, QP.LIMIT, QP.ID, QP.TYPE, QP.ID_PATTERN, QP.ATTRS, QP.Q,
QP.GEOMETRY, QP.GEOREL, QP.COORDINATES, QP.GEOPROPERTY, QP.GEOMETRY_PROPERTY,
QP.LANG, QP.SCOPEQ, QP.CONTAINED_BY, QP.JOIN, QP.JOIN_LEVEL, QP.DATASET_ID,
],
notImplemented = [QP.PICK, QP.OMIT, QP.EXPAND_VALUES, QP.CSF, QP.ENTITY_MAP, QP.LOCAL, QP.VIA]
)
@RequestParam params: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()
Expand Down Expand Up @@ -204,7 +231,9 @@ class EntityAccessControlHandler(
suspend fun addRightsOnEntities(
@RequestHeader httpHeaders: HttpHeaders,
@PathVariable subjectId: String,
@RequestBody requestBody: Mono<String>
@RequestBody requestBody: Mono<String>,
@AllowedParameters
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()

Expand Down Expand Up @@ -282,7 +311,9 @@ class EntityAccessControlHandler(
@DeleteMapping("/{subjectId}/attrs/{entityId}")
suspend fun removeRightsOnEntity(
@PathVariable subjectId: String,
@PathVariable entityId: URI
@PathVariable entityId: URI,
@AllowedParameters
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()

Expand All @@ -305,7 +336,9 @@ class EntityAccessControlHandler(
suspend fun updateSpecificAccessPolicy(
@RequestHeader httpHeaders: HttpHeaders,
@PathVariable entityId: URI,
@RequestBody requestBody: Mono<String>
@RequestBody requestBody: Mono<String>,
@AllowedParameters
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()

Expand All @@ -331,7 +364,9 @@ class EntityAccessControlHandler(

@DeleteMapping("/{entityId}/attrs/specificAccessPolicy")
suspend fun deleteSpecificAccessPolicy(
@PathVariable entityId: URI
@PathVariable entityId: URI,
@AllowedParameters
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object TemporalApiResponses {
lang: String? = null,
): ResponseEntity<String> {
val baseRepresentation = parseRepresentations(requestParams, mediaType)
// this is needed for queryEntitiesViaPost where the properties are not in the query parameters
val representation = lang?.let {
baseRepresentation.copy(languageFilter = it, timeproperty = query.temporalQuery.timeproperty.propertyName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class EntityHandlerTests {
"""
{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"title": "The 'invalid' parameter(s) is/are not allowed on this endpoint. This endpoint does not accept any query parameters. ",
"title": "The ['invalid'] parameters are not allowed on this endpoint. This endpoint does not accept any query parameters. ",
"detail": "$DEFAULT_DETAIL"
}
""".trimIndent()
Expand All @@ -344,7 +344,7 @@ class EntityHandlerTests {
"""
{
"type": "https://uri.etsi.org/ngsi-ld/errors/NotImplemented",
"title": "The 'local' parameter(s) has/have not been implemented yet. This endpoint does not accept any query parameters. ",
"title": "The ['local'] parameters have not been implemented yet. This endpoint does not accept any query parameters. ",
"detail": "$DEFAULT_DETAIL"
}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ annotation class AllowedParameters(
val message = StringBuilder().apply {
if (notImplementedKeys.isNotEmpty()) {
append(
"The ['${
notImplementedKeys.joinToString("', '")
}'] parameters have not been implemented yet. "
"The ['${notImplementedKeys.joinToString("', '")}'] parameters have not been implemented yet. "
)
}
if (invalidKeys.isNotEmpty()) {
append(
"The ['${
invalidKeys.joinToString("', '")
}'] parameters are not allowed on this endpoint. "
"The ['${invalidKeys.joinToString("', '")}'] parameters are not allowed on this endpoint. "
)
}
if (implemented.isNotEmpty())
Expand Down

0 comments on commit cd692da

Please sign in to comment.