def create_client(server, params, *, logger=None): logger = logger or Logger() if params['type'] not in server['login_types']: raise ValueError("Unsupported login type") # If type is cosigncookie, but we only know ais_cookie, skip REST login. if (params['type'] == 'cosigncookie' and 'rest_cookie' in server and not (params.get('rest_cookie') or '').strip()): logger.log('login', 'Skipping REST login because rest_cookie is empty') server = server.copy() server.pop('rest_url', None) server.pop('rest_cookie', None) # Do the cosign login if required. cookies = get_cosign_cookies(server, params, logger) ctx = Context(cookies, ais_url=server.get('ais_url'), rest_url=server.get('rest_url'), ais_logout_path=server.get('ais_logout_path'), logger=logger) # Request ais_login_path to start the AIS session. if 'ais_url' in server: data = {} if params['type'] == 'plainpassword': data['login'] = params['username'] data['password'] = params['password'] soup = ctx.request_html(server['ais_login_path'], method='POST', data=data) username_element = soup.find(class_='user-name') if not (username_element and username_element.get_text().strip()): raise Exception('AIS login unsuccessful.') # Create the client. if 'ais_url' in server and 'rest_url' in server: client = HybridClient(ctx) elif 'ais_url' in server: client = WebuiClient(ctx) elif 'rest_url' in server: client = RestClient(ctx) else: raise Exception('Demo client is not supported') # Check that login was successful. client.check_connection() return client
def create_client(server, params): if params['type'] not in server['login_types']: raise ValueError("Unsupported login type") # Do the cosign login if required. cookies = get_cosign_cookies(server, params) # TODO: Refactor Context arguments for REST and demo. ctx = Context(cookies, ais_url=server.get('ais_url'), rest_url=server.get('rest_url')) # Request login.do to start the AIS session. if 'ais_url' in server: data = {} if params['type'] == 'plainpassword': data['login'] = params['username'] data['password'] = params['password'] soup = ctx.request_html('/ais/login.do', method='POST', data=data) username_element = soup.find(class_='user-name') if not (username_element and username_element.get_text()): raise Exception('AIS login unsuccessful.') # Create the client. if 'ais_url' in server and 'rest_url' in server: client = HybridClient(ctx) elif 'ais_url' in server: client = WebuiClient(ctx) elif 'rest_url' in server: client = RestClient(ctx) else: raise Exception('Demo client is not supported') # Check that login was successful. client.check_connection() return client
def check_connection(self): RestClient.check_connection(self) WebuiClient.check_connection(self)
def logout(self): RestClient.logout(self) WebuiClient.logout(self)