def login(self, app_name, args): """Get credentials if found else prompt GUI to login.""" self.ref_count += 1 obj = Credentials(app_name, **self._parse_args(args)) d = obj.login() d.addCallback(lambda creds: self.CredentialsFound(app_name, creds)) d.addErrback(self._process_failures, app_name)
def login(self, app_name, args): """Get credentials if found else prompt GUI to login.""" self.ref_count += 1 obj = Credentials(app_name, **self._parse_args(args)) d = obj.login() d.addCallback(lambda creds: self.CredentialsFound(app_name, creds)) d.addErrback(self._process_failures, app_name)
def clear_token(self, app_name, callback=NO_OP, errback=NO_OP): """Clear the token for an application from the keyring. 'app_name' is the name of the application. """ d = Credentials(app_name=app_name).clear_credentials() # pylint: disable=E1101 d.addCallbacks(lambda _: callback(), errback)
def login_email_password(self, app_name, args): """Get credentials if found else try to login. Login will be done by inspecting 'args' and expecting to find two keys: 'email' and 'password'. """ self.ref_count += 1 email = args.pop('email') password = args.pop('password') obj = Credentials(app_name, **self._parse_args(args)) obj.login_email_password(email=email, password=password)
def find_credentials(self, app_name, callback=NO_OP, errback=NO_OP): """Get the credentials from the keyring or {} if not there.""" def log_result(result): """Log the result and continue.""" logger.info('find_credentials: app_name "%s", result is {}? %s', app_name, result == {}) return result d = Credentials(app_name=app_name).find_credentials() # pylint: disable=E1101 d.addCallback(log_result) d.addCallbacks(callback, errback)
def clear_credentials(self, app_name, args): """Clear the credentials for an application. - 'app_name': the name of the application which credentials are going to be removed. - 'args' is a dictionary, currently not used. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.clear_credentials() d.addCallback(lambda _: self.CredentialsCleared(app_name)) d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
def login_email_password(self, app_name, args): """Get credentials if found else try to login. Login will be done by inspecting 'args' and expecting to find two keys: 'email' and 'password'. """ self.ref_count += 1 email = args.pop('email') password = args.pop('password') obj = Credentials(app_name, **self._parse_args(args)) d = obj.login(email=email, password=password) d.addCallback(lambda creds: self.CredentialsFound(app_name, creds)) d.addErrback(self._process_failures, app_name)
def login_email_password(self, app_name, args): """Get credentials if found else try to login. Login will be done by inspecting 'args' and expecting to find two keys: 'email' and 'password'. """ self.ref_count += 1 email = args.pop('email') password = args.pop('password') obj = Credentials(app_name, **self._parse_args(args)) d = obj.login(email=email, password=password) d.addCallback(lambda creds: self.CredentialsFound(app_name, creds)) d.addErrback(self._process_failures, app_name)
def clear_credentials(self, app_name, args): """Clear the credentials for an application. - 'app_name': the name of the application which credentials are going to be removed. - 'args' is a dictionary, currently not used. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.clear_credentials() d.addCallback(lambda _: self.CredentialsCleared(app_name)) d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
def store_credentials(self, app_name, args): """Store the token for an application. - 'app_name': the name of the application which credentials are going to be stored. - 'args' is the dictionary holding the credentials. Needs to provide the following mandatory keys: 'token', 'token_key', 'consumer_key', 'consumer_secret'. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.store_credentials(args) d.addCallback(lambda _: self.CredentialsStored(app_name)) d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
def store_credentials(self, app_name, args): """Store the token for an application. - 'app_name': the name of the application which credentials are going to be stored. - 'args' is the dictionary holding the credentials. Needs to provide the following mandatory keys: 'token', 'token_key', 'consumer_key', 'consumer_secret'. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.store_credentials(args) d.addCallback(lambda _: self.CredentialsStored(app_name)) d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
def find_credentials(self, app_name, args, success_cb=None, error_cb=None): """Look for the credentials for an application. - 'app_name': the name of the application which credentials are going to be removed. - 'args' is a dictionary, currently not used. - 'success_cb', if not None, will be executed if the operation was a success. - 'error_cb', if not None, will be executed if the operation had an error. """ def _analize_creds(credentials): """Find credentials and notify using signals.""" if credentials is not None and len(credentials) > 0: self.CredentialsFound(app_name, credentials) else: self.CredentialsNotFound(app_name) def _tweaked_success_cb(creds): """Decrease ref counter and call 'success_cb'.""" self.ref_count -= 1 success_cb(creds) if success_cb is None: _success_cb = _analize_creds else: _success_cb = _tweaked_success_cb def _tweaked_error_cb(error, app): """Decrease ref counter and call 'error_cb', modifying the dict.""" self.ref_count -= 1 error_cb(except_to_errdict(error.value)) if error_cb is None: _error_cb = lambda f, _: self.CredentialsError(app_name, f.value) else: _error_cb = _tweaked_error_cb self.ref_count += 1 obj = Credentials(app_name) d = obj.find_credentials() d.addCallback(_success_cb) d.addErrback(_error_cb, app_name)
def find_credentials(self, app_name, args, success_cb=None, error_cb=None): """Look for the credentials for an application. - 'app_name': the name of the application which credentials are going to be removed. - 'args' is a dictionary, currently not used. - 'success_cb', if not None, will be executed if the operation was a success. - 'error_cb', if not None, will be executed if the operation had an error. """ def _analize_creds(credentials): """Find credentials and notify using signals.""" if credentials is not None and len(credentials) > 0: self.CredentialsFound(app_name, credentials) else: self.CredentialsNotFound(app_name) def _tweaked_success_cb(creds): """Decrease ref counter and call 'success_cb'.""" self.ref_count -= 1 success_cb(creds) if success_cb is None: _success_cb = _analize_creds else: _success_cb = _tweaked_success_cb def _tweaked_error_cb(error, app): """Decrease ref counter and call 'error_cb', modifying the dict.""" self.ref_count -= 1 error_cb(except_to_errdict(error.value)) if error_cb is None: _error_cb = lambda f, _: self.CredentialsError(app_name, f.value) else: _error_cb = _tweaked_error_cb self.ref_count += 1 obj = Credentials(app_name) d = obj.find_credentials() d.addCallback(_success_cb) d.addErrback(_error_cb, app_name)
def login_to_get_credentials(self, app_name, help_text, window_id, success_cb, error_cb, denial_cb, ui_module='ubuntu_sso.gtk.gui'): """Get credentials if found else prompt GUI just to login 'app_name' will be displayed in the GUI. 'help_text' is an explanatory text for the end-users, will be shown before the login fields. 'window_id' is the id of the window which will be set as a parent of the GUI. If 0, no parent will be set. """ ping_url = self.ping_url if app_name == U1_APP_NAME else None obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=None, help_text=help_text, window_id=window_id, success_cb=success_cb, error_cb=error_cb, denial_cb=denial_cb, ui_module=ui_module) obj.login()
def clear_credentials(self, app_name, args, success_cb, error_cb): """Clear the credentials for an application. - 'app_name': the name of the application which credentials are going to be removed. - 'args' is a dictionary, currently not used. - 'success_cb' is a callback that will be execute if the operation was a success. - 'error_cb' is a callback that will be executed if the operation had an error. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.clear_credentials() # pylint: disable=E1101 d.addCallback(success_cb) d.addErrback(error_cb, app_name)
def store_credentials(self, app_name, args, success_cb, error_cb): """Store the token for an application. - 'app_name': the name of the application which credentials are going to be stored. - 'args' is the dictionary holding the credentials. Needs to provide the following mandatory keys: 'token', 'token_key', 'consumer_key', 'consumer_secret'. - 'success_cb' is a callback that will be execute if the operation was a success. - 'error_cb' is a callback that will be executed if the operation had an error. """ self.ref_count += 1 obj = Credentials(app_name) d = obj.store_credentials(args) # pylint: disable=E1101 d.addCallback(success_cb) d.addErrback(error_cb, app_name)
def login_or_register_to_get_credentials(self, app_name, terms_and_conditions_url, help_text, window_id, success_cb, error_cb, denial_cb, ui_module='ubuntu_sso.gtk.gui'): """Get credentials if found else prompt GUI to login or register. 'app_name' will be displayed in the GUI. 'terms_and_conditions_url' will be the URL pointing to T&C. 'help_text' is an explanatory text for the end-users, will be shown below the headers. 'window_id' is the id of the window which will be set as a parent of the GUI. If 0, no parent will be set. """ ping_url = self.ping_url if app_name == U1_APP_NAME else None obj = Credentials(app_name=app_name, ping_url=ping_url, tc_url=terms_and_conditions_url, help_text=help_text, window_id=window_id, success_cb=success_cb, error_cb=error_cb, denial_cb=denial_cb, ui_module=ui_module) obj.register()
def login(self, app_name, args): """Get credentials if found else prompt GUI to login.""" self.ref_count += 1 obj = Credentials(app_name, **self._parse_args(args)) obj.login()
def register(self, app_name, args): """Get credentials if found else prompt GUI to register.""" self.ref_count += 1 obj = Credentials(app_name, **self._parse_args(args)) obj.register()