From 59fee5e0f417e838a73332b21104057925a8fb7d Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Thu, 19 Dec 2024 10:14:44 +0100 Subject: [PATCH] Add conditions on endpoints for testing parameters and headers --- appinfo/info.xml | 2 +- lib/Db/Endpoint.php | 7 ++++--- lib/Migration/Version1Date20241218122932.php | 6 +++++- lib/Service/EndpointService.php | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index f04f76a4..1e6ce6bb 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -13,7 +13,7 @@ The OpenConnector Nextcloud app provides a ESB-framework to work together in an - 🆓 Map and translate API calls ]]> - 0.1.26 + 0.1.27 agpl integration Conduction diff --git a/lib/Db/Endpoint.php b/lib/Db/Endpoint.php index 8333009f..6f95cd72 100644 --- a/lib/Db/Endpoint.php +++ b/lib/Db/Endpoint.php @@ -19,6 +19,8 @@ class Endpoint extends Entity implements JsonSerializable protected ?string $method = null; // One of GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD. method and endpoint combination should be unique protected ?string $targetType = null; // The target to attach this endpoint to, should be one of source (to create a proxy endpoint) or register/schema (to create an object endpoint) or job (to fire an event) or synchronization (to create a synchronization endpoint) protected ?string $targetId = null; // The target id to attach this endpoint to + + protected array $conditions = []; protected ?DateTime $created = null; protected ?DateTime $updated = null; @@ -34,9 +36,7 @@ public function __construct() { $this->addType(fieldName:'method', type: 'string'); $this->addType(fieldName:'targetType', type: 'string'); $this->addType(fieldName:'targetId', type: 'string'); - $this->addType(fieldName:'schema', type: 'int'); - $this->addType(fieldName:'register', type: 'int'); - $this->addType(fieldName:'source', type: 'int'); + $this->addType(fieldName:'conditions', type: 'json'); $this->addType(fieldName:'created', type: 'datetime'); $this->addType(fieldName:'updated', type: 'datetime'); } @@ -86,6 +86,7 @@ public function jsonSerialize(): array 'method' => $this->method, 'targetType' => $this->targetType, 'targetId' => $this->targetId, + 'conditions' => $this->conditions, 'created' => isset($this->created) ? $this->created->format('c') : null, 'updated' => isset($this->updated) ? $this->updated->format('c') : null, diff --git a/lib/Migration/Version1Date20241218122932.php b/lib/Migration/Version1Date20241218122932.php index 7c66532e..0da96f8b 100644 --- a/lib/Migration/Version1Date20241218122932.php +++ b/lib/Migration/Version1Date20241218122932.php @@ -43,7 +43,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if($schema->hasTable(tableName: 'openconnector_consumers') === true) { $table = $schema->getTable(tableName: 'openconnector_consumers'); $table->addColumn('authorization_configuration', Types::JSON); - $table->addColumn('user_id', Types::STRING); + $table->addColumn('user_id', Types::STRING)->setNotnull(false); + } + if($schema->hasTable(tableName: 'openconnector_endpoints') === true) { + $table = $schema->getTable(tableName: 'openconnector_endpoints'); + $table->addColumn('conditions', Types::JSON); } return $schema; diff --git a/lib/Service/EndpointService.php b/lib/Service/EndpointService.php index a8a41aee..1ba784e6 100644 --- a/lib/Service/EndpointService.php +++ b/lib/Service/EndpointService.php @@ -238,10 +238,12 @@ private function handleSchemaRequest(Endpoint $endpoint, IRequest $request, stri $status = 200; + $headers = $request->getHeader('Accept-Crs') === '' ? [] : ['Content-Crs' => $request->getHeader('Accept-Crs')]; + // Route to appropriate ObjectService method based on HTTP method return match ($method) { 'GET' => new JSONResponse( - $this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status), statusCode: $status + $this->getObjects(mapper: $mapper, parameters: $parameters, pathParams: $pathParams, status: $status), statusCode: $status, headers: $headers ), 'POST' => new JSONResponse( $mapper->createFromArray(object: $parameters)