Move monkey-patching to dedicated file

os-repl
root 2022-11-23 19:18:40 +00:00
parent 73116d39d5
commit 9d1cad700f
2 changed files with 30 additions and 30 deletions

32
main.py
View File

@ -1,38 +1,10 @@
import logging import logging
import paramiko import paramiko
import sshim import sshim_patch as sshim
import pylxd import lxd_interface
import os import os
import re 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') logging.basicConfig(level='DEBUG')
logger = logging.getLogger() logger = logging.getLogger()

28
sshim_patch.py Normal file
View File

@ -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