Skip to content

Commit

Permalink
make the HTTP method of a REST connector editable
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilWun committed Aug 8, 2023
1 parent 4325073 commit d636022
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions plugins/rest_connector/api/edit_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/rest_connector/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion plugins/rest_connector/api/templates/rest_connector_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,28 @@ <h3>{{name}} (WIP)</h3>
</form>
</details>

<!-- FIXME add endpoint method and support variables in endpoint -->
<!-- FIXME add support for variables in endpoint -->

<details class="step" open>
<summary class="step-head">Endpoint method</summary>

<form action="{{process}}" method="post" class="qhana-form" data-step="endpoint-method" enctype="application/json">
<div class="qhana-form-field">
<label class="qhana-form-label" for="endpoint_method">Endpoint URL</label>
<div class="qhana-input-wrapper">
<select class="qhana-form-input" name="value" id="endpoint_method">
{% for method in http_methods %}
<option value="{{ method }}" {% if connector['endpointMethod'] == method %} selected {% endif %}>{{ method }}</option>
{% endfor %}
</select>
</div>
</div>

<div class="qhana-form-buttons">
<button class="qhana-form-submit" type="submit" data-target="api" >set endpoint method</button>
</div>
</form>
</details>

<details class="step" open>
<summary class="step-head">Variables</summary>
Expand Down

0 comments on commit d636022

Please sign in to comment.