def wrapper(*args, **kwargs): try: return method(*args, **kwargs) except db_exception.DBDuplicateEntry as e: # LOG the exception for debug purposes, do not send the # exception details out with the raised Conflict exception # as it can contain raw SQL. LOG.debug(_conflict_msg, {'conflict_type': conflict_type, 'details': six.text_type(e)}) raise exception.Conflict(type=conflict_type, details=_('Duplicate Entry')) except db_exception.DBError as e: # TODO(blk-u): inspecting inner_exception breaks encapsulation; # oslo_db should provide exception we need. if isinstance(e.inner_exception, IntegrityError): # LOG the exception for debug purposes, do not send the # exception details out with the raised Conflict exception # as it can contain raw SQL. LOG.debug(_conflict_msg, {'conflict_type': conflict_type, 'details': six.text_type(e)}) # NOTE(morganfainberg): This is really a case where the SQL # failed to store the data. This is not something that the # user has done wrong. Example would be a ForeignKey is # missing; the code that is executed before reaching the # SQL writing to the DB should catch the issue. raise exception.UnexpectedError( _('An unexpected error occurred when trying to ' 'store %s') % conflict_type) raise
def wrapper(*args, **kwargs): try: return method(*args, **kwargs) except db_exception.DBDuplicateEntry as e: # LOG the exception for debug purposes, do not send the # exception details out with the raised Conflict exception # as it can contain raw SQL. LOG.debug(_conflict_msg, { 'conflict_type': conflict_type, 'details': six.text_type(e) }) raise exception.Conflict(type=conflict_type, details=_('Duplicate Entry')) except db_exception.DBError as e: # TODO(blk-u): inspecting inner_exception breaks encapsulation; # oslo_db should provide exception we need. if isinstance(e.inner_exception, IntegrityError): # LOG the exception for debug purposes, do not send the # exception details out with the raised Conflict exception # as it can contain raw SQL. LOG.debug( _conflict_msg, { 'conflict_type': conflict_type, 'details': six.text_type(e) }) # NOTE(morganfainberg): This is really a case where the SQL # failed to store the data. This is not something that the # user has done wrong. Example would be a ForeignKey is # missing; the code that is executed before reaching the # SQL writing to the DB should catch the issue. raise exception.UnexpectedError( _('An unexpected error occurred when trying to ' 'store %s') % conflict_type) raise
def _sync_extension_repo(extension, version): init_version = 0 engine = sql.get_engine() try: package_name = '.'.join((extension)) package = importutils.import_module(package_name) except ImportError: raise ImportError(_("%s extension does not exist.") % package_name) try: abs_path = find_migrate_repo(package) try: migration.db_version_control(sql.get_engine(), abs_path) # Register the repo with the version control API # If it already knows about the repo, it will throw # an exception that we can safely ignore except exceptions.DatabaseAlreadyControlledError: pass except exception.MigrationNotProvided as e: print(e) sys.exit(1) _assert_not_schema_downgrade(extension=extension, version=version) migration.db_sync(engine, abs_path, version=version, init_version=init_version, sanity_check=False)
def get_relationship(self, req, body): try: return self.Relation.get_relationship_by_sourcefilename(str(body['sourcefilename'])) except exception.NotFound as e: msg = _("The Specified Relationship [%s] is Not Found") % e.message LOG.info(msg) return null;
def get_object_acl(self, req, body): try: ref = self.ACL.get_acl_by_name(str(body['sourcefilename'])) return ref except exception.NotFound as e: msg = _("The Specified ACL [%s] is Not Found") % e.message LOG.info(msg) return False
def get_relationship(self, req, body): try: return self.Relation.get_relationship_by_sourcefilename( str(body['sourcefilename'])) except exception.NotFound as e: msg = _("The Specified Relationship [%s] is Not Found") % e.message LOG.info(msg) return null
def get_object_acl(self, req, body): try: ref= self.ACL.get_acl_by_name(str(body['sourcefilename'])) return ref except exception.NotFound as e: msg = _("The Specified ACL [%s] is Not Found") % e.message LOG.info(msg) return False;
def _allowAccessThroughACL(self, userName, fileName): try: ref = self.ACL.get_acl_by_name(fileName) except exception.NotFound as e: msg = _("The Specified ACL [%s] is Not Found") % e.message LOG.info(msg) return False if userName in ref['userlist']: return True else: return False
def _allowAccessThroughACL(self, userName, fileName): try: ref = self.ACL.get_acl_by_name(fileName) except exception.NotFound as e: msg = _("The Specified ACL [%s] is Not Found") % e.message LOG.info(msg) return False; if userName in ref['userlist']: return True else: return False
def get_db_version(extension=None): if not extension: return migration.db_version(sql.get_engine(), find_migrate_repo(), migrate_repo.DB_INIT_VERSION) try: package_name = '.'.join((extension)) package = importutils.import_module(package_name) except ImportError: raise ImportError(_("%s extension does not exist.") % package_name) return migration.db_version(sql.get_engine(), find_migrate_repo(package), 0)
def get_db_version(extension=None): if not extension: return migration.db_version(sql.get_engine(), find_migrate_repo(), migrate_repo.DB_INIT_VERSION) try: package_name = '.'.join((extension)) package = importutils.import_module(package_name) except ImportError: raise ImportError(_("%s extension does not exist.") % package_name) return migration.db_version( sql.get_engine(), find_migrate_repo(package), 0)
def fix_greendns_ipv6(): if dnspython_installed: # All of this is because if dnspython is present in your environment # then eventlet monkeypatches socket.getaddrinfo() with an # implementation which doesn't work for IPv6. What we're checking here # is that the magic environment variable was set when the import # happened. nogreendns = 'EVENTLET_NO_GREENDNS' flag = os.environ.get(nogreendns, '') if 'eventlet' in sys.modules and not strutils.bool_from_string(flag): msg = i18n._("It appears that the eventlet module has been " "imported prior to setting %s='yes'. It is currently " "necessary to disable eventlet.greendns " "if using ipv6 since eventlet.greendns currently " "breaks with ipv6 addresses. Please ensure that " "eventlet is not imported prior to this being set.") raise ImportError(msg % (nogreendns)) os.environ[nogreendns] = 'yes'
def _allowAccessThroughRelationship(self, userName, fileName): try: ref = self.Relation.get_relationship_by_sourcefilename(fileName) except exception.NotFound as e: msg = _("The Specified Relationship [%s] is Not Found") % e.message LOG.info(msg) return False; FileList= ref['targetfilelist'].split(',') print(FileList) for linkedFile in FileList: print('Linked File:'+ linkedFile) if linkedFile in FileAlreadyVisited: continue else: FileAlreadyVisited.append(linkedFile) if allowAccessThroughACL(userName, linkedFile): return True else: return allowAccessThroughRelationship(userName, linkedFile) return False
def _allowAccessThroughRelationship(self, userName, fileName): try: ref = self.Relation.get_relationship_by_sourcefilename(fileName) except exception.NotFound as e: msg = _("The Specified Relationship [%s] is Not Found") % e.message LOG.info(msg) return False FileList = ref['targetfilelist'].split(',') print(FileList) for linkedFile in FileList: print('Linked File:' + linkedFile) if linkedFile in FileAlreadyVisited: continue else: FileAlreadyVisited.append(linkedFile) if allowAccessThroughACL(userName, linkedFile): return True else: return allowAccessThroughRelationship(userName, linkedFile) return False
def wrapper(self, hints, *args, **kwargs): if not hasattr(hints, 'limit'): raise exception.UnexpectedError( _('Cannot truncate a driver call without hints list as ' 'first parameter after self ')) if hints.limit is None: return f(self, hints, *args, **kwargs) # A limit is set, so ask for one more entry than we need list_limit = hints.limit['limit'] hints.set_limit(list_limit + 1) ref_list = f(self, hints, *args, **kwargs) # If we got more than the original limit then trim back the list and # mark it truncated. In both cases, make sure we set the limit back # to its original value. if len(ref_list) > list_limit: hints.set_limit(list_limit, truncated=True) return ref_list[:list_limit] else: hints.set_limit(list_limit) return ref_list