Skip to content

Commit

Permalink
Remove inspect method for Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jborean93 committed Apr 14, 2022
1 parent 9fe56fd commit c214689
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Version 0.4.3
- Fix invalid regex escape sequences.
- Decoding CLIXML failures for `run_ps` will create a `UserWarning` rather than printing the warning.
- Remove usage of deprecated Python API to support Python 3.11

### Version 0.4.2
- Dropped Python 3.5 from support matrix as it is EOL.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
license='MIT license',
packages=find_packages(),
package_data={'winrm.tests': ['*.ps1']},
install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=0.3.0', 'six'],
install_requires=['xmltodict', 'requests>=2.9.1', 'requests_ntlm>=1.1.0', 'six'],
extras_require={
'credssp': ['requests-credssp>=1.0.0'],
'kerberos:sys_platform=="win32"': ['winkerberos>=0.5.0'],
Expand All @@ -44,6 +44,7 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Clustering',
Expand Down
49 changes: 8 additions & 41 deletions winrm/transport.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import unicode_literals
import sys
import os
import inspect
import requests
import requests.auth
import warnings
Expand Down Expand Up @@ -228,12 +227,10 @@ def build_session(self):

if self.auth_method == 'kerberos':
if not HAVE_KERBEROS:
raise WinRMError("requested auth method is kerberos, but requests_kerberos is not installed")
raise WinRMError("requested auth method is kerberos, but pykerberos is not installed")

man_args = dict(
session.auth = HTTPKerberosAuth(
mutual_authentication=REQUIRED,
)
opt_args = dict(
delegate=self.kerberos_delegation,
force_preemptive=True,
principal=self.username,
Expand All @@ -242,8 +239,6 @@ def build_session(self):
service=self.service,
send_cbt=self.send_cbt
)
kerb_args = self._get_args(man_args, opt_args, HTTPKerberosAuth.__init__)
session.auth = HTTPKerberosAuth(**kerb_args)
encryption_available = hasattr(session.auth, 'winrm_encryption_available') and session.auth.winrm_encryption_available
elif self.auth_method in ['certificate', 'ssl']:
if self.auth_method == 'ssl' and not self.cert_pem and not self.cert_key_pem:
Expand All @@ -257,15 +252,12 @@ def build_session(self):
elif self.auth_method == 'ntlm':
if not HAVE_NTLM:
raise WinRMError("requested auth method is ntlm, but requests_ntlm is not installed")
man_args = dict(

session.auth = HttpNtlmAuth(
username=self.username,
password=self.password
password=self.password,
send_cbt=self.send_cbt,
)
opt_args = dict(
send_cbt=self.send_cbt
)
ntlm_args = self._get_args(man_args, opt_args, HttpNtlmAuth.__init__)
session.auth = HttpNtlmAuth(**ntlm_args)
# check if requests_ntlm has the session_security attribute available for encryption
encryption_available = hasattr(session.auth, 'session_security')
# TODO: ssl is not exactly right here- should really be client_cert
Expand All @@ -275,17 +267,13 @@ def build_session(self):
if not HAVE_CREDSSP:
raise WinRMError("requests auth method is credssp, but requests-credssp is not installed")

man_args = dict(
session.auth = HttpCredSSPAuth(
username=self.username,
password=self.password
)
opt_args = dict(
password=self.password,
disable_tlsv1_2=self.credssp_disable_tlsv1_2,
auth_mechanism=self.credssp_auth_mechanism,
minimum_version=self.credssp_minimum_version
)
credssp_args = self._get_args(man_args, opt_args, HttpCredSSPAuth.__init__)
session.auth = HttpCredSSPAuth(**credssp_args)
encryption_available = True
else:
raise WinRMError("unsupported auth method: %s" % self.auth_method)
Expand Down Expand Up @@ -355,24 +343,3 @@ def _get_message_response_text(self, response):
else:
response_text = response.content
return response_text

def _get_args(self, mandatory_args, optional_args, function):
argspec = set(inspect.getargspec(function).args)
function_args = dict()
for name, value in mandatory_args.items():
if name in argspec:
function_args[name] = value
else:
raise Exception("Function %s does not contain mandatory arg "
"%s, check installed version with pip list"
% (str(function), name))

for name, value in optional_args.items():
if name in argspec:
function_args[name] = value
else:
warnings.warn("Function %s does not contain optional arg %s, "
"check installed version with pip list"
% (str(function), name))

return function_args

0 comments on commit c214689

Please sign in to comment.