Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
243 stars 76 forks source link

Cannot get parameter-context by ID. #296

Closed yoshiya8 closed 2 years ago

yoshiya8 commented 2 years ago

Description

Encountered HTTP 500 (server error) when attempting:

policies_api.get_access_policy_for_resource(
    action="read",
    resource="parameter-contexts/156c43ae-017d-1000-b070-8588032f859b"
)

What I Did

policies_api.get_access_policy_for_resource(
    action="read",
    resource="parameter-contexts/156c43ae-017d-1000-b070-8588032f859b"
)

Error/Stacktrace:

Traceback (most recent call last):
  File "/home/jhaftel/git/asiasetl-ansible-nifi/ansible_collections/asias_etl/nifi/plugins/modules_utils/nifi.py", line 424, in <module>
    ['test', 'NiFi Admin']
  File "/home/jhaftel/git/asiasetl-ansible-nifi/ansible_collections/asias_etl/nifi/plugins/modules_utils/nifi.py", line 389, in ensure_parameter_context
    self._ensure_access_policy("read", "parameter-contexts", name, parameter_context.id, groups)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/ansible_collections/asias_etl/nifi/plugins/modules_utils/nifi.py", line 195, in _ensure_access_policy
    action=action, resource=f"{resource_type}/{resource_id}"
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/apis/policies_api.py", line 279, in get_access_policy_for_resource
    (data) = self.get_access_policy_for_resource_with_http_info(action, resource, **kwargs)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/apis/policies_api.py", line 368, in get_access_policy_for_resource_with_http_info
    collection_formats=collection_formats)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 333, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 154, in __call_api
    _request_timeout=_request_timeout)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/api_client.py", line 356, in request
    headers=headers)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/rest.py", line 244, in GET
    query_params=query_params)
  File "/home/jhaftel/git/asiasetl-ansible-nifi/.venv/lib/python3.7/site-packages/nipyapi/nifi/rest.py", line 235, in request
    raise ApiException(http_resp=r)
nipyapi.nifi.rest.ApiException: (500)
Reason: Server Error
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 15 Nov 2021 19:05:29 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': "frame-ancestors 'self'", 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Strict-Transport-Security': 'max-age=31540000', 'Content-Length': '87', 'Server': 'Jetty(9.4.42.v20210604)'})
HTTP response body: The request was rejected because the URL contained a potentially malicious String "%2F"

Urgency

I need this as part of my NiFi deployment capability. It is a critical enough that I will be making a pull request. The problem occurs because both the resource path parameter has the value parameter-contexts/156c43ae-017d-1000-b070-8588032f859b" The call_api method then URL encodes the / in there to %2F - the server does not like this, because the / must be preserved as a path separator. image

Chaffelson commented 2 years ago

You may be able to bypass this issue by setting '/' as a bypass char during usage. https://github.com/Chaffelson/nipyapi/blob/bf25635caedb30a25adb39a8cba21dd286a38dd1/nipyapi/config.py#L157

yoshiya8 commented 2 years ago

That is an intriguing workaround - I think it will work - thanks!

yoshiya8 commented 2 years ago

BTW it appears this is an issue with the swagger.json that does not specify a distinction between resource type and resource ID. I think the "fix" is a matter of an updated/correct API definition used to generate this code.

yoshiya8 commented 2 years ago

This above approach resolves the issue for me. Thank you, @Chaffelson