def __init__(self, *args, **kwargs):
for key, value in kwargs.items():
if (key == 'user') and not isinstance(value, str):
raise ConfigurationException('value of "user" must be a string')
elif (key == 'password') and not isinstance(value, str):
raise ConfigurationException('value of "password" must be a string')
elif (key == 'upstream_host') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_host" must be a string')
elif (key == 'upstream_user') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_user" must be a string')
elif (key == 'upstream_password') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_password" must be a string')
elif (key == 'upstream_key') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_key" must be a string')
elif (key == 'upstream_authorized_keys') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_authorized_keys" must be a string')
elif (key == 'upstream_port') and not isinstance(value, int):
raise ConfigurationException('value of "upstream_port" must be an integer')
elif (key == 'upstream_root_path') and not isinstance(value, str):
raise ConfigurationException('value of "upstream_root_path" must be a string')
elif (key == 'allow_ssh') and not isinstance(value, bool):
raise ConfigurationException('value of "allow_ssh" must be a boolean')
elif (key == 'allow_sftp') and not isinstance(value, bool):
raise ConfigurationException('value of "allow_sftp" must be a boolean')
setattr(self, key, value)
# Additional configuration
if not self.user:
raise pysshrp.PysshrpException('"user" is mandatory in "servers"')
if not self.upstream_host:
raise pysshrp.PysshrpException('"upstream_host" is mandatory in "servers"')
if self.upstream_key:
try:
self.upstream_key = paramiko.RSAKey.from_private_key_file(self.upstream_key)
except IOError:
raise pysshrp.PysshrpException('failed to open SSH key file "%s"' % self.upstream_key)
except paramiko.SSHException:
raise pysshrp.PysshrpException('invalid SSH key from "%s"' % self.upstream_key)
评论列表
文章目录