From 9d1cad700f1f260999a606cba4264ca5c5808e89 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 23 Nov 2022 19:18:40 +0000 Subject: [PATCH] Move monkey-patching to dedicated file --- main.py | 32 ++------------------------------ sshim_patch.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 sshim_patch.py diff --git a/main.py b/main.py index 1c2f433..8f26d36 100644 --- a/main.py +++ b/main.py @@ -1,38 +1,10 @@ import logging import paramiko -import sshim -import pylxd +import sshim_patch as sshim +import lxd_interface import os import re -# monkey patching - - -def check_auth_none(self, username): - return paramiko.AUTH_PARTIALLY_SUCCESSFUL - - -def check_auth_password(self, username, password): - if username == os.environ["ssh-username"] and password == os.environ["ssh-password"]: - return paramiko.AUTH_SUCCESSFUL - return paramiko.AUTH_FAILED - - -def check_auth_publickey(self, username, key): - return paramiko.AUTH_FAILED - - -def enable_auth_gssapi(self): - return paramiko.AUTH_FAILED - - -sshim.Handler.check_auth_none = check_auth_none -sshim.Handler.check_auth_password = check_auth_password -sshim.Handler.check_auth_publickey = check_auth_publickey -sshim.Handler.enable_auth_gssapi = enable_auth_gssapi - -# monkey patching complete - logging.basicConfig(level='DEBUG') logger = logging.getLogger() diff --git a/sshim_patch.py b/sshim_patch.py new file mode 100644 index 0000000..a6ef77f --- /dev/null +++ b/sshim_patch.py @@ -0,0 +1,28 @@ +from sshim import * +import paramiko +import os + + +def check_auth_none(self, username): + return paramiko.AUTH_PARTIALLY_SUCCESSFUL + + +def check_auth_password(self, username, password): + if username == os.environ["ssh-username"] and password == os.environ["ssh-password"]: + return paramiko.AUTH_SUCCESSFUL + return paramiko.AUTH_FAILED + + +def check_auth_publickey(self, username, key): + return paramiko.AUTH_FAILED + + +def enable_auth_gssapi(self): + return paramiko.AUTH_FAILED + + +Handler.check_auth_none = check_auth_none +Handler.check_auth_password = check_auth_password +Handler.check_auth_publickey = check_auth_publickey +Handler.enable_auth_gssapi = enable_auth_gssapi +