Isilon / isilon_sdk_python

Official generated source of the Isilon SDK Python language bindings.
35 stars 34 forks source link

Error in validating the path for custom_template field while creating the Event channel #71

Open sachin-apa opened 6 months ago

sachin-apa commented 6 months ago

While creating a event channel, when a path is specified for custom template field it fails with an error as regex is not matching.

Run the script with a below code where custom_template field is given an input as "/ifs/data"

parameters = isilon_sdk.v9_5_0.EventChannelParameters(
    address="my.email.com",
    custom_template="/ifs/data"
)

event_channel = isilon_sdk.v9_5_0.EventChannelCreateParams(
    enabled=enabled,
    name=name,
    type=type,
    allowed_nodes=allowed_nodes,
    excluded_nodes=excluded_nodes,
    parameters=parameters
)

try:
      api_response = api_instance.create_event_channel(event_channel)
      pprint(api_response)
except ApiException as e:
      print("Exception when calling EventApi->create_event_channel: %s\n" % e)

Actual Fails with an error as below

Traceback (most recent call last):
  File "/home/sachin/collections/tryout/powerscale_scripts/event_channel.py", line 159, in <module>
    parameters = isilon_sdk.v9_5_0.EventChannelParameters(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sachin/.local/lib/python3.11/site-packages/isilon_sdk/v9_5_0/models/event_channel_parameters.py", line 87, in __init__
    self.custom_template = custom_template
    ^^^^^^^^^^^^^^^^^^^^
  File "/home/sachin/.local/lib/python3.11/site-packages/isilon_sdk/v9_5_0/models/event_channel_parameters.py", line 209, in custom_template
    raise ValueError("Invalid value for `custom_template`, must be a follow pattern or equal to `/^((\/[^\/[:cntrl:]]+)(\/?))*$/`")  # noqa: E501
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid value for `custom_template`, must be a follow pattern or equal to `/^((\/[^\/[:cntrl:]]+)(\/?))*$/`

Expected

Create event channel as the input "/ifs/data/" is a correct input for the field "custom_template".

sachin-apa commented 6 months ago

The Issue is because of the regex used'^((\/[^\/[:cntrl:]]+)(\/?))*$' Python regex library is not recognising [:cntrl:] as control parameters, but is just considering as a regular text matching c t r l and hence the SDK is throwing error.

>>> import re
>>> re.search('^((\/[^\/[:cntrl:]]+)(\/?))*$', "/ifs/data" )
>>> re.search('^((\/[^\/[:cntrl:]]+)(\/?))*$', "/]]]]]]/" )
<re.Match object; span=(0, 8), match='/]]]]]]/'>

Alternative to [:cntrl:] in python is to use [\x00-\x1F\x7F] so the regular expression would be ^((\/[^\x00-\x1F\x7F]+)(\/?))*$

>>> re.search('^((\/[^\x00-\x1F\x7F]+)(\/?))*$', "/]]]]]]/" )
<re.Match object; span=(0, 8), match='/]]]]]]/'>
>>> re.search('^((\/[^\x00-\x1F\x7F]+)(\/?))*$', "/ifs/data" )
<re.Match object; span=(0, 9), match='/ifs/data'>
Bhavneet-Sharma commented 5 days ago

I encountered the same error while attempting to retrieve the details of the ADS provider using this method: Isilon SDK v0.3.0.1 AuthApi. The call fails with the following error:

ValueError: Invalid value for home_directory_template, must follow a pattern or be equal to /^((\/[^\/[:cntrl:]]+)(\/?))*$/.

However, this method works in SDK version 9.1, as referenced here.