From d6360224c2c146f96a0ba72aba21bb7b1a455955 Mon Sep 17 00:00:00 2001 From: Philipp Wundrack Date: Tue, 8 Aug 2023 14:38:26 +0200 Subject: [PATCH] make the HTTP method of a REST connector editable --- plugins/rest_connector/api/edit_routes.py | 8 +++++++ plugins/rest_connector/api/tasks.py | 2 +- .../api/templates/rest_connector_edit.html | 23 ++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/plugins/rest_connector/api/edit_routes.py b/plugins/rest_connector/api/edit_routes.py index d73e0f3f8..81c362cb1 100644 --- a/plugins/rest_connector/api/edit_routes.py +++ b/plugins/rest_connector/api/edit_routes.py @@ -55,6 +55,7 @@ def get(self, connector_id: str): "rest_connector_edit.html", name=name, connector=ConnectorSchema().dump(connector), + http_methods=["GET", "PUT", "POST", "DELETE", "PATCH"], process=url_for( f"{REST_CONN_BLP.name}.{WipConnectorView.__name__}", connector_id=connector_id, @@ -123,6 +124,8 @@ def post(self, data, connector_id: str): connector = self.update_openapi_spec(connector, update_value) elif update_key == ConnectorKey.ENDPOINT_URL: connector = self.update_endpoint_url(connector, update_value) + elif update_key == ConnectorKey.ENDPOINT_METHOD: + connector = self.update_endpoint_method(connector, update_value) elif update_key == ConnectorKey.VARIABLES: connector = self.update_variables(connector, update_value) elif update_key == ConnectorKey.REQUEST_HEADERS: @@ -175,6 +178,11 @@ def update_endpoint_url(self, connector: dict, new_endpoint_url: str) -> dict: # TODO: discover headers/body from openapi spec? return connector + def update_endpoint_method(self, connector: dict, new_endpoint_method: str) -> dict: + connector["endpoint_method"] = new_endpoint_method + # TODO: discover method from openapi spec? + return connector + def update_variables(self, connector: dict, new_variables: str) -> dict: print(new_variables) parsed_variables = ConnectorVariableSchema(many=True).loads(new_variables) diff --git a/plugins/rest_connector/api/tasks.py b/plugins/rest_connector/api/tasks.py index d991eb963..144c28bf0 100644 --- a/plugins/rest_connector/api/tasks.py +++ b/plugins/rest_connector/api/tasks.py @@ -69,7 +69,7 @@ def perform_request(self, connector_id: str, db_id: int) -> None: parsed_headers = parse_headers(BytesIO(headers.encode())) response = request( - method="post", # FIXME read from connector definition + method=connector["endpoint_method"], url=urljoin( connector["base_url"], connector["endpoint_url"] ), # FIXME allow variables in endpoint diff --git a/plugins/rest_connector/api/templates/rest_connector_edit.html b/plugins/rest_connector/api/templates/rest_connector_edit.html index e7326ac73..4416641de 100644 --- a/plugins/rest_connector/api/templates/rest_connector_edit.html +++ b/plugins/rest_connector/api/templates/rest_connector_edit.html @@ -62,7 +62,28 @@

{{name}} (WIP)

- + + +
+ Endpoint method + +
+
+ +
+ +
+
+ +
+ +
+
+
Variables