From 604099f1b0e2dc8dcbceafe654b253f59021e81f Mon Sep 17 00:00:00 2001 From: XiaoliChan <2209553467@qq.com> Date: Mon, 11 Sep 2023 15:46:38 +0800 Subject: [PATCH] [winrm] less ugly if condition Signed-off-by: XiaoliChan <2209553467@qq.com> --- cme/protocols/winrm.py | 66 ++++++++++-------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/cme/protocols/winrm.py b/cme/protocols/winrm.py index 1c460bc3..5fea95e3 100644 --- a/cme/protocols/winrm.py +++ b/cme/protocols/winrm.py @@ -231,31 +231,14 @@ class winrm(connection): self.password = password self.username = username self.domain = domain - if self.args.ssl and self.args.ignore_ssl_cert: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{domain}\\{self.username}", - password=self.password, - ssl=True, - cert_validation=False, - ) - elif self.args.ssl: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{domain}\\{self.username}", - password=self.password, - ssl=True, - ) - else: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{domain}\\{self.username}", - password=self.password, - ssl=False, - ) + self.conn = Client( + self.host, + auth="ntlm", + username=f"{domain}\\{self.username}", + password=self.password, + ssl=True if self.args.ssl else False, + cert_validation=False if self.args.ignore_ssl_cert else True, + ) # TO DO: right now we're just running the hostname command to make the winrm library auth to the server # we could just authenticate without running a command :) (probably) @@ -308,31 +291,14 @@ class winrm(connection): nthash = self.hash self.domain = domain - if self.args.ssl and self.args.ignore_ssl_cert: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{self.domain}\\{self.username}", - password=lmhash + nthash, - ssl=True, - cert_validation=False, - ) - elif self.args.ssl: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{self.domain}\\{self.username}", - password=lmhash + nthash, - ssl=True, - ) - else: - self.conn = Client( - self.host, - auth="ntlm", - username=f"{self.domain}\\{self.username}", - password=lmhash + nthash, - ssl=False, - ) + self.conn = Client( + self.host, + auth="ntlm", + username=f"{self.domain}\\{self.username}", + password=lmhash + nthash, + ssl=True if self.args.ssl else False, + cert_validation=False if self.args.ignore_ssl_cert else True, + ) # TO DO: right now we're just running the hostname command to make the winrm library auth to the server # we could just authenticate without running a command :) (probably)