-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add optional parameter domain to HttpNtlmAuth __init__ #86
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,25 +13,34 @@ class HttpNtlmAuth(AuthBase): | |
Supports pass-the-hash. | ||
""" | ||
|
||
def __init__(self, username, password, session=None): | ||
def __init__(self, username, password, session=None, domain=None): | ||
"""Create an authentication handler for NTLM over HTTP. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefacing this with |
||
|
||
:param str username: Username in 'domain\\username' format | ||
:param str username: Username. If in either 'domain\\\\username' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks ugly in code but 4 slashes are necessary for doc gen (at least that's how PyCharm works). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, you need four backslashes for PyCharm to render one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I guess that's because both Python and reStructuredText treat backslash as an escape character. If HTML docs aren't generated anywhere I'm happy to leave two backslashes. This way printing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we don't render HTML docs, so it might be better to just leave it in the double form. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I also made docstring raw as suggested by @nitzmahone. |
||
format or 'username@domain' format, username and domain will be | ||
parsed out of it. Otherwise, domain is set to '.' and username | ||
is left intact. If the domain parameter is set no parsing is done | ||
regardless of the username format. | ||
:param str password: Password | ||
:param str session: Unused. Kept for backwards-compatibility. | ||
:param str domain: Domain. If None will be parsed out of username. | ||
""" | ||
if ntlm is None: | ||
raise Exception("NTLM libraries unavailable") | ||
|
||
# parse the username | ||
try: | ||
self.domain, self.username = username.split('\\', 1) | ||
except ValueError: | ||
if domain is not None: | ||
self.username = username | ||
self.domain = domain | ||
else: | ||
# parse the username | ||
try: | ||
self.username, self.domain = username.split('@', 1) | ||
self.domain, self.username = username.split('\\', 1) | ||
except ValueError: | ||
self.username = username | ||
self.domain = '.' | ||
try: | ||
self.username, self.domain = username.split('@', 1) | ||
except ValueError: | ||
self.username = username | ||
self.domain = '.' | ||
|
||
self.domain = self.domain.upper() | ||
self.password = password | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have
domain
beforesession
but I'm not sure if that would break backwards compatibility and how important that is in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can't do that really. Sadly, positional arguments are still a thing.