Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitse hostname URL with regex validation #363

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions plugins/module_utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__metaclass__ = type

import json
import re
from urllib.error import HTTPError, URLError
from urllib.parse import ParseResult, urlencode, urlparse

Expand Down Expand Up @@ -50,18 +51,17 @@
timeout: Optional[Any] = None,
validate_certs: Optional[Any] = None,
) -> None:
if not (host or "").startswith(("https://", "http://")):
raise EDAHTTPError(
f"Invalid instance host value: '{host}'. "
"Value must start with 'https://' or 'http://'"
)

self.host = host
self.username = username
self.password = password
self.timeout = timeout
self.validate_certs = validate_certs

# Perform some basic validation
if not re.match("^https{0,1}://", self.host):
self.host = f"https://{0}"

Check warning on line 63 in plugins/module_utils/client.py

View check run for this annotation

Codecov / codecov/patch

plugins/module_utils/client.py#L63

Added line #L63 was not covered by tests

# Try to parse the hostname as a url
try:
self.url = urlparse(self.host)
Expand Down
Loading