def get_username_and_password(device, cmdline_username, config): """Get a username and a password for device. The username and password are selected from user input, config files and device information. """ username_list = get_username_list(cmdline_username, config) service_list = get_username_service_list(config) password = select_device_password(device, username_list, service_list) username = None if password and password.attributes.get('username'): username = password.attributes.get('username') password = password.password if not username: if len(username_list) == 0: username = None while not username: username = utils.read_response('Enter username') elif len(username_list) == 1: username = username_list[0] else: options = [utils.PicklistOption(u) for u in username_list] username = utils.pick_from_list(options, 'Select username').option if not password: password = utils.read_password(verify=False) return username, password
def _getPassword(self): password = self.config.get("password") if not password: password_file = self.config.get("password-file") if password_file and os.path.isfile(password_file): password = open(password_file).read().rstrip() if not password and self.interactive: prompt = "Password for %s@%s" % (self.config.get("username"), self.config.get("server")) password = utils.read_password(prompt, verify=False) if not password: raise errors.InvalidPasswordError("invalid or missing password") return password
def _getPassword(self): password = self.config.get('password') if not password: password_file = self.config.get('password-file') if password_file and os.path.isfile(password_file): password = open(password_file).read().rstrip() if not password and self.interactive: prompt = 'Password for %s@%s' % (self.config.get('username'), self.config.get('server')) password = utils.read_password(prompt, verify = False) if not password: raise errors.InvalidPasswordError('invalid or missing password') return password
def _getPassword(self): password = self.config.get('password') if not password: password_file = self.config.get('password-file') if password_file and os.path.isfile(password_file): password = open(password_file).read().rstrip() if not password and self.interactive: prompt = 'Password for %s@%s' % (self.config.get('username'), self.config.get('server')) password = utils.read_password(prompt, verify=False) if not password: raise errors.InvalidPasswordError('invalid or missing password') return password