Skip to content

Curl Rewrite#41

Open
jrzmurray wants to merge 9 commits into
bentleymi:cloud-versionfrom
deductiv:deductiv_curl
Open

Curl Rewrite#41
jrzmurray wants to merge 9 commits into
bentleymi:cloud-versionfrom
deductiv:deductiv_curl

Conversation

@jrzmurray
Copy link
Copy Markdown

Pull Request Type

Rewrite/refactor/bugfixes

Release Notes

  • Feature: Forcing HTTPS checks only for Splunk Cloud environments, and not for loopback interfaces.
  • Feature: Added option: clean to clean HTML output.
  • Feature: Added option: methodfield to use the HTTP method defined in the events.
  • Feature: Added option: dryrun to run the code without sending the HTTP request.
  • Feature: Added debug output fields curl_headers_response, curl_redirect.
  • Feature: Type conversion for argument parsing.
  • Refactor: Consolidated functions for different HTTP methods.
  • Refactor: http_request function arguments use required parameters and optional kwargs.
  • Fix: Updated app.conf/author stanza to pass checks.
  • Fix: Added support for multivalue fields, to prevent concatenation with line breaks.
  • QOL: Added .vscode, .pylintrc, and .gitignore files.
  • QOL: Extensive code docs.

Copy link
Copy Markdown
Owner

@bentleymi bentleymi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution looks pretty solid.

Noticed the uri vs url diff shows the code body wasn’t fully updated in places (e.g., if not isinstance(uri, str)).

bentleymi
bentleymi previously approved these changes Mar 29, 2026
@bentleymi bentleymi dismissed their stale review March 29, 2026 14:48

Working from my phone, pressed the wrong button, still reviewing.

@jrzmurray
Copy link
Copy Markdown
Author

Any updates on getting this in?

@bentleymi
Copy link
Copy Markdown
Owner

Please correct the uri vs url change:

diff shows the code body wasn’t fully updated in places (e.g., if not isinstance(uri, str)).

Comment thread TA-webtools/bin/curl.py
# Set the authentication header for the Splunk session key
sessionKey = settings.get('sessionKey')
if sessionKey:
headers = headers.update(build_auth_headers(sessionKey=sessionKey))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dict.update() mutates in place and returns None, so headers becomes None.

Should be:
headers.update(build_auth_headers(sessionKey=sessionKey))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, not sure if/how this worked.

Comment thread TA-webtools/bin/curl.py
payload_field = 'params'
elif payload is not None:
payload_field = 'data'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need a payload_field = None upfront

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - would cover get/head with payload set to None.

Comment thread TA-webtools/bin/curl.py

sleepCounter = 0
sleep: Optional[float] = float(options['sleep']) if 'sleep' in options else None # type: ignore[reportArgumentType]
clean_result: Optional[bool] = bool(options.get('clean', False))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type annotation says Optional[bool] but bool(...) always returns a bool, never None.

Minor, but misleading.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove the Optional[]

Comment thread TA-webtools/bin/curl.py
try:
proxy_user, proxy_pass = str(proxy_auth).split(':')
if 'http' in proxies and isinstance(proxies['http'], str):
proxies['http'] = proxies['http'].replace('://', f'://{proxy_user}:{proxy_pass}@')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could leak in logs or tracebacks. The requests library supports ab auth parameter on the Session object for proxy auth which is safer.

Comment thread TA-webtools/bin/curl.py
Comment thread TA-webtools/bin/curl.py
# Remove multiple newlines
clean_html = re.sub(r'(?<=\n)[\r\n]*', '', clean_html)
# Remove extra whitespace
clean_html = re.sub(r'([\t ])\1+', '\1', clean_html)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'\1' in a plain string is a literal backslash-1, not a backreference. Should be r'\1' i think? double check please.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cleans up either extra tabs or extra spaces and replaces it with the first one. The \1 is a backreference in both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants