update ssh get config value: tabs instead of spaces, ssh port can return None

This commit is contained in:
KiekerJan 2024-03-10 14:16:56 +01:00
parent 4e64518881
commit bdda55413c
1 changed files with 23 additions and 18 deletions

View File

@ -180,28 +180,33 @@ def wait_for_service(port, public, env, timeout):
time.sleep(min(timeout/4, 1))
def get_ssh_port():
return int(get_ssh_config_value("port"))
port_value = get_ssh_config_value("port")
if port_value:
return int(port_value)
return None
def get_ssh_config_value(parameter_name):
# Returns ssh port
try:
output = shell('check_output', ['sshd', '-T'])
except FileNotFoundError:
# sshd is not installed. That's ok.
return None
except subprocess.CalledProcessError:
# error while calling shell command
return None
# Returns ssh configuration value for the provided parameter
try:
output = shell('check_output', ['sshd', '-T'])
except FileNotFoundError:
# sshd is not installed. That's ok.
return None
except subprocess.CalledProcessError:
# error while calling shell command
return None
returnNext = False
for e in output.split():
if returnNext:
return e
if e == parameter_name:
returnNext = True
returnNext = False
for e in output.split():
if returnNext:
return e
if e == parameter_name:
returnNext = True
# Did not find port!
return None
# Did not find the parameter!
return None
if __name__ == "__main__":
from web_update import get_web_domains