def _get_element_and_cache(request, role, function): if not cache.get(role): try: role = function(request, role) pickle_role = PickleObject(name=role.name, id=role.id) cache.set(role, pickle_role, DEFAULT_OBJECTS_CACHE_TIME) except Exception as e: ks_exceptions.handle(request) return cache.get(role)
def action(self, request, obj_id): domain = self.table.get_object_by_id(obj_id) if not domain.enabled: LOG.info('Enabling domain "%s".' % obj_id) try: api.keystone.domain_update( request, domain_id=domain.id, name=domain.name, description=domain.description, enabled=True ) except Exception: exceptions.handle(request, ignore=True) return False
def action(self, request, obj_id): domain = self.table.get_object_by_id(obj_id) if not domain.enabled: LOG.info('Enabling domain "%s".' % obj_id) try: api.keystone.domain_update(request, domain_id=domain.id, name=domain.name, description=domain.description, enabled=True) except Exception: exceptions.handle(request, ignore=True) return False
def get_idm_admin_app(request): idm_admin = getattr(settings, "FIWARE_IDM_ADMIN_APP", None) if idm_admin and cache.get('idm_admin') is None: try: apps = internal_keystoneclient(request).oauth2.consumers.list() except Exception: apps = [] ks_exceptions.handle(request) for app in apps: if app.id == idm_admin or app.name == idm_admin: pickle_app = PickleObject(name=app.name, id=app.id) cache.set('idm_admin', pickle_app, DEFAULT_OBJECTS_CACHE_TIME) break return cache.get('idm_admin')
def get_fiware_default_app(request, app_name, use_idm_account=True): if cache.get(app_name) is None: try: if use_idm_account: manager = internal_keystoneclient(request) else: manager = keystone.keystoneclient(request, admin=True) apps = manager.oauth2.consumers.list() except Exception: apps = [] ks_exceptions.handle(request) for app in apps: if app.name == app_name: pickle_app = PickleObject(name=app.name, id=app.id) cache.set(app_name, pickle_app, DEFAULT_OBJECTS_CACHE_TIME) break return cache.get(app_name)
def get_fiware_cloud_app(request, use_idm_account=True): cloud_app = getattr(settings, "FIWARE_CLOUD_APP", None) if cloud_app and cache.get('cloud_app') is None: try: if use_idm_account: manager = internal_keystoneclient(request) else: manager = keystone.keystoneclient(request, admin=True) apps = manager.oauth2.consumers.list() except Exception: apps = [] ks_exceptions.handle(request) for app in apps: if app.id == cloud_app or app.name == cloud_app: pickle_app = PickleObject(name=app.name, id=app.id) cache.set('cloud_app', pickle_app, DEFAULT_OBJECTS_CACHE_TIME) break return cache.get('cloud_app')