Skip to content

Commit

Permalink
Added get_password method
Browse files Browse the repository at this point in the history
  • Loading branch information
huashengdun committed Aug 25, 2018
1 parent 48acf09 commit 9fd8d13
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions webssh/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def parse_encoding(data):

class MixinHandler(object):

arguments_required = {} # agruments must be deliverd
empty_allowed = {} # emtpy value alllowed

def get_value(self, name):
is_required = name in self.arguments_required

Expand All @@ -52,7 +49,7 @@ def get_value(self, name):
if is_required:
raise
else:
if not value and is_required and name not in self.empty_allowed:
if not value and is_required:
raise ValueError('The {} field is required.'.format(name))
return value

Expand All @@ -79,7 +76,6 @@ def get_real_client_addr(self):
class IndexHandler(MixinHandler, tornado.web.RequestHandler):

arguments_required = {'hostname', 'port', 'username', 'password'}
empty_allowed = {'password'}

def initialize(self, loop, policy, host_keys_settings):
self.loop = loop
Expand Down Expand Up @@ -152,11 +148,17 @@ def get_port(self):

raise ValueError('Invalid port: {}'.format(value))

def get_password(self):
try:
return self.get_value('password')
except ValueError:
return ''

def get_args(self):
hostname = self.get_hostname()
port = self.get_port()
username = self.get_value('username')
password = self.get_value('password')
password = self.get_password()
privatekey = self.get_privatekey()
pkey = self.get_pkey_obj(privatekey, password, self.filename) \
if privatekey else None
Expand Down

0 comments on commit 9fd8d13

Please sign in to comment.