def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(itertools.chain(six.iteritems(CONF), six.iteritems(CONF.eventlet_server))) d.update({"tenant_id": tenant_id, "user_id": user_id}) session = sql.get_session() services = ( session.query(Service).filter(Service.enabled == true()).options(sql.joinedload(Service.endpoints)).all() ) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint["service_id"] del endpoint["legacy_endpoint_id"] del endpoint["enabled"] endpoint["region"] = endpoint["region_id"] try: endpoint["url"] = core.format_url(endpoint["url"], d) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {"endpoints": eps, "id": svc.id, "type": svc.type} service["name"] = svc.extra.get("name", "") return service return [make_v3_service(svc) for svc in services]
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. services = (session.query(Service).filter( Service.enabled == t).options(sql.joinedload( Service.endpoints)).all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] try: endpoint['url'] = core.format_url(endpoint['url'], d) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} name = svc.extra.get('name') if name: service['name'] = name return service return [make_v3_service(svc) for svc in services]
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. services = (session.query(Service).filter(Service.enabled == t). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoint(endpoint): endpoint = endpoint.to_dict() del endpoint['service_id'] endpoint['url'] = core.format_url(endpoint['url'], d) return endpoint def make_v3_service(svc): eps = [make_v3_endpoint(ep) for ep in svc.endpoints if ep.enabled] service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} name = svc.extra.get('name') if name: service['name'] = name return service return [make_v3_service(svc) for svc in services]
def get_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = db_session.get_session() endpoints = (session.query(Endpoint).options( sql.joinedload(Endpoint.service)).all()) catalog = {} for endpoint in endpoints: region = endpoint['region'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service['name'], 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) url = core.format_url(endpoint['url'], d) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() services = (session.query(Service).filter( Service.enabled == True).options(sql.joinedload( Service.endpoints)).all()) def make_v3_endpoint(endpoint): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['url'] = core.format_url(endpoint['url'], d) return endpoint catalog = [{ 'endpoints': [ make_v3_endpoint(ep.to_dict()) for ep in svc.endpoints if ep.enabled ], 'id': svc.id, 'type': svc.type } for svc in services] return catalog
def get_catalog(self, user_id, tenant_id, metadata=None): substitutions = dict(six.iteritems(CONF)) substitutions.update({"tenant_id": tenant_id, "user_id": user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. endpoints = ( session.query(Endpoint).options(sql.joinedload(Endpoint.service)).filter(Endpoint.enabled == t).all() ) catalog = {} for endpoint in endpoints: if not endpoint.service["enabled"]: continue try: url = core.format_url(endpoint["url"], substitutions) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() region = endpoint["region"] service_type = endpoint.service["type"] default_service = {"id": endpoint["id"], "name": endpoint.service["name"], "publicURL": ""} catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) interface_url = "%sURL" % endpoint["interface"] catalog[region][service_type][interface_url] = url return catalog
def get_catalog(self, user_id, tenant_id, metadata=None): substitutions = dict(six.iteritems(CONF)) substitutions.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. endpoints = (session.query(Endpoint).options( sql.joinedload( Endpoint.service)).filter(Endpoint.enabled == t).all()) catalog = {} for endpoint in endpoints: if not endpoint.service['enabled']: continue try: url = core.format_url(endpoint['url'], substitutions) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() region = endpoint['region'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service['name'], 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({"tenant_id": tenant_id, "user_id": user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. services = session.query(Service).filter(Service.enabled == t).options(sql.joinedload(Service.endpoints)).all() def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint["service_id"] del endpoint["legacy_endpoint_id"] del endpoint["enabled"] try: endpoint["url"] = core.format_url(endpoint["url"], d) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {"endpoints": eps, "id": svc.id, "type": svc.type} name = svc.extra.get("name") if name: service["name"] = name return service return [make_v3_service(svc) for svc in services]
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. services = (session.query(Service).filter(Service.enabled == t). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoint(endpoint): endpoint = endpoint.to_dict() del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['url'] = core.format_url(endpoint['url'], d) return endpoint def make_v3_service(svc): eps = [make_v3_endpoint(ep) for ep in svc.endpoints if ep.enabled] service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} name = svc.extra.get('name') if name: service['name'] = name return service return [make_v3_service(svc) for svc in services]
def get_catalog(self, user_id, tenant_id, metadata=None): d = dict(CONF.iteritems()) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = self.get_session() endpoints = (session.query(Endpoint). options(sql.joinedload(Endpoint.service)). all()) catalog = {} for endpoint in endpoints: region = endpoint['region'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service['name'], 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) url = core.format_url(endpoint['url'], d) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() services = (session.query(Service).filter(Service.enabled == true()). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: endpoint['url'] = core.format_url(endpoint['url'], d) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service return [make_v3_service(svc) for svc in services]
def get_catalog(self, user_id, tenant_id, metadata=None): substitutions = dict(six.iteritems(CONF)) substitutions.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() endpoints = (session.query(Endpoint). options(sql.joinedload(Endpoint.service)). filter(Endpoint.enabled == true()).all()) catalog = {} for endpoint in endpoints: if not endpoint.service['enabled']: continue try: url = core.format_url(endpoint['url'], substitutions) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() region = endpoint['region_id'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service.extra.get('name', ''), 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict( itertools.chain(six.iteritems(CONF), six.iteritems(CONF.eventlet_server))) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() services = (session.query(Service).filter( Service.enabled == true()).options( sql.joinedload(Service.endpoints)).all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: endpoint['url'] = core.format_url(endpoint['url'], d) except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service return [make_v3_service(svc) for svc in services]
def get_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. endpoints = (session.query(Endpoint). options(sql.joinedload(Endpoint.service)). filter(Endpoint.enabled == t).all()) catalog = {} for endpoint in endpoints: if not endpoint.service['enabled']: continue region = endpoint['region'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service['name'], 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) url = core.format_url(endpoint['url'], d) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_catalog(self, user_id, tenant_id): """Retrieve and format the V2 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param tenant_id: The id of the project. 'tenant_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a tenant_id as part of their URL will be skipped (as would a whole service if, as a consequence, it has no valid endpoints). :returns: A nested dict representing the service catalog or an empty dict. """ substitutions = dict( itertools.chain(six.iteritems(CONF), six.iteritems(CONF.eventlet_server))) substitutions.update({'user_id': user_id}) silent_keyerror_failures = [] if tenant_id: substitutions.update({'tenant_id': tenant_id}) else: silent_keyerror_failures = ['tenant_id'] session = sql.get_session() endpoints = (session.query(Endpoint). options(sql.joinedload(Endpoint.service)). filter(Endpoint.enabled == true()).all()) catalog = {} for endpoint in endpoints: if not endpoint.service['enabled']: continue try: formatted_url = core.format_url( endpoint['url'], substitutions, silent_keyerror_failures=silent_keyerror_failures) if formatted_url is not None: url = formatted_url else: continue except exception.MalformedEndpoint: continue # this failure is already logged in format_url() region = endpoint['region_id'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service.extra.get('name', ''), 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_catalog(self, user_id, tenant_id): """Retrieve and format the V2 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param tenant_id: The id of the project. 'tenant_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a tenant_id as part of their URL will be skipped (as would a whole service if, as a consequence, it has no valid endpoints). :returns: A nested dict representing the service catalog or an empty dict. """ substitutions = dict( itertools.chain(CONF.items(), CONF.eventlet_server.items())) substitutions.update({'user_id': user_id}) silent_keyerror_failures = [] if tenant_id: substitutions.update({'tenant_id': tenant_id}) else: silent_keyerror_failures = ['tenant_id'] session = sql.get_session() endpoints = (session.query(Endpoint). options(sql.joinedload(Endpoint.service)). filter(Endpoint.enabled == true()).all()) catalog = {} for endpoint in endpoints: if not endpoint.service['enabled']: continue try: formatted_url = core.format_url( endpoint['url'], substitutions, silent_keyerror_failures=silent_keyerror_failures) if formatted_url is not None: url = formatted_url else: continue except exception.MalformedEndpoint: continue # this failure is already logged in format_url() region = endpoint['region_id'] service_type = endpoint.service['type'] default_service = { 'id': endpoint['id'], 'name': endpoint.service.extra.get('name', ''), 'publicURL': '' } catalog.setdefault(region, {}) catalog[region].setdefault(service_type, default_service) interface_url = '%sURL' % endpoint['interface'] catalog[region][service_type][interface_url] = url return catalog
def get_v3_catalog(self, user_id, tenant_id): """Retrieve and format the current V3 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param tenant_id: The id of the project. 'tenant_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a tenant_id as part of their URL will be skipped. :returns: A list representing the service catalog or an empty list """ d = dict( itertools.chain(CONF.items(), CONF.eventlet_server.items())) d.update({'user_id': user_id}) silent_keyerror_failures = [] if tenant_id: d.update({ 'tenant_id': tenant_id, 'project_id': tenant_id, }) else: silent_keyerror_failures = ['tenant_id', 'project_id', ] session = sql.get_session() services = (session.query(Service).filter(Service.enabled == true()). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: formatted_url = core.format_url( endpoint['url'], d, silent_keyerror_failures=silent_keyerror_failures) if formatted_url: endpoint['url'] = formatted_url else: continue except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint # TODO(davechen): If there is service with no endpoints, we should skip # the service instead of keeping it in the catalog, see bug #1436704. def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service return [make_v3_service(svc) for svc in services]
def get_v3_catalog(self, user_id, tenant_id): """Retrieve and format the current V3 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param tenant_id: The id of the project. 'tenant_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a tenant_id as part of their URL will be skipped. :returns: A list representing the service catalog or an empty list """ d = dict( itertools.chain(six.iteritems(CONF), six.iteritems(CONF.eventlet_server))) d.update({'user_id': user_id}) silent_keyerror_failures = [] if tenant_id: d.update({'tenant_id': tenant_id}) else: silent_keyerror_failures = ['tenant_id'] session = sql.get_session() services = (session.query(Service).filter(Service.enabled == true()). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: formatted_url = core.format_url( endpoint['url'], d, silent_keyerror_failures=silent_keyerror_failures) if formatted_url: endpoint['url'] = formatted_url else: continue except exception.MalformedEndpoint: continue # this failure is already logged in format_url() yield endpoint # TODO(davechen): If there is service with no endpoints, we should skip # the service instead of keeping it in the catalog, see bug #1436704. def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service return [make_v3_service(svc) for svc in services]
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(CONF.iteritems()) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = self.get_session() services = (session.query(Service). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoint(endpoint): del endpoint['service_id'] endpoint['url'] = core.format_url(endpoint['url'], d) return endpoint catalog = [{'endpoints': [make_v3_endpoint(ep.to_dict()) for ep in svc.endpoints], 'id': svc.id, 'type': svc.type} for svc in services] return catalog
def get_v3_catalog(self, user_id, tenant_id, metadata=None): d = dict(six.iteritems(CONF)) d.update({'tenant_id': tenant_id, 'user_id': user_id}) session = sql.get_session() t = True # variable for singleton for PEP8, E712. services = (session.query(Service).filter(Service.enabled == t). options(sql.joinedload(Service.endpoints)). all()) def make_v3_endpoint(endpoint): del endpoint['service_id'] endpoint['url'] = core.format_url(endpoint['url'], d) return endpoint catalog = [{'endpoints': [make_v3_endpoint(ep.to_dict()) for ep in svc.endpoints if ep.enabled], 'id': svc.id, 'type': svc.type} for svc in services] return catalog
def get_v3_catalog(self, user_id, project_id): """Retrieve and format the current V3 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param project_id: The id of the project. 'project_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a project_id as part of their URL will be skipped. :returns: A list representing the service catalog or an empty list """ d = dict(itertools.chain(CONF.items(), CONF.eventlet_server.items())) d.update({'user_id': user_id}) silent_keyerror_failures = [] if project_id: d.update({ 'tenant_id': project_id, 'project_id': project_id, }) else: silent_keyerror_failures = ['tenant_id', 'project_id'] with sql.session_for_read() as session: services = (session.query(Service).filter( Service.enabled == true()).options( sql.joinedload(Service.endpoints)).all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: formatted_url = utils.format_url( endpoint['url'], d, silent_keyerror_failures=silent_keyerror_failures) if formatted_url: endpoint['url'] = formatted_url else: continue except exception.MalformedEndpoint: # nosec(tkelsey) # this failure is already logged in format_url() continue yield endpoint # TODO(davechen): If there is service with no endpoints, we should # skip the service instead of keeping it in the catalog, # see bug #1436704. def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service # Build the unfiltered catalog, this is the catalog that is # returned if endpoint filtering is not performed and the # option of `return_all_endpoints_if_no_filter` is set to true. catalog_ref = [make_v3_service(svc) for svc in services] # Filter the `catalog_ref` above by any project-endpoint # association configured by endpoint filter. filtered_endpoints = {} if project_id: filtered_endpoints = ( self.catalog_api.list_endpoints_for_project(project_id)) # endpoint filter is enabled, only return the filtered endpoints. if filtered_endpoints: filtered_ids = list(filtered_endpoints.keys()) # This is actually working on the copy of `catalog_ref` since # the index will be shifted if remove/add any entry for the # original one. for service in catalog_ref[:]: endpoints = service['endpoints'] for endpoint in endpoints[:]: endpoint_id = endpoint['id'] # remove the endpoint that is not associated with # the project. if endpoint_id not in filtered_ids: service['endpoints'].remove(endpoint) continue # remove the disabled endpoint from the list. if not filtered_endpoints[endpoint_id]['enabled']: service['endpoints'].remove(endpoint) # NOTE(davechen): The service will not be included in the # catalog if the service doesn't have any endpoint when # endpoint filter is enabled, this is inconsistent with # full catalog that is returned when endpoint filter is # disabled. if not service.get('endpoints'): catalog_ref.remove(service) # When it arrives here it means it's domain scoped token ( # `project_id` is not set) or it's a project scoped token # but the endpoint filtering is not performed. # Both of them tell us the endpoint filtering is not enabled, so # check the option of `return_all_endpoints_if_no_filter`, it will # judge whether a full unfiltered catalog or a empty service # catalog will be returned. elif not CONF.endpoint_filter.return_all_endpoints_if_no_filter: return [] return catalog_ref
def get_v3_catalog(self, user_id, project_id): """Retrieve and format the current V3 service catalog. :param user_id: The id of the user who has been authenticated for creating service catalog. :param project_id: The id of the project. 'project_id' will be None in the case this being called to create a catalog to go in a domain scoped token. In this case, any endpoint that requires a project_id as part of their URL will be skipped. :returns: A list representing the service catalog or an empty list """ d = dict( itertools.chain(CONF.items(), CONF.eventlet_server.items())) d.update({'user_id': user_id}) silent_keyerror_failures = [] if project_id: d.update({ 'tenant_id': project_id, 'project_id': project_id, }) else: silent_keyerror_failures = ['tenant_id', 'project_id'] with sql.session_for_read() as session: services = (session.query(Service).filter( Service.enabled == true()).options( sql.joinedload(Service.endpoints)).all()) def make_v3_endpoints(endpoints): for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled): del endpoint['service_id'] del endpoint['legacy_endpoint_id'] del endpoint['enabled'] endpoint['region'] = endpoint['region_id'] try: formatted_url = utils.format_url( endpoint['url'], d, silent_keyerror_failures=silent_keyerror_failures) if formatted_url: endpoint['url'] = formatted_url else: continue except exception.MalformedEndpoint: # nosec(tkelsey) # this failure is already logged in format_url() continue yield endpoint # TODO(davechen): If there is service with no endpoints, we should # skip the service instead of keeping it in the catalog, # see bug #1436704. def make_v3_service(svc): eps = list(make_v3_endpoints(svc.endpoints)) service = {'endpoints': eps, 'id': svc.id, 'type': svc.type} service['name'] = svc.extra.get('name', '') return service # Build the unfiltered catalog, this is the catalog that is # returned if endpoint filtering is not performed and the # option of `return_all_endpoints_if_no_filter` is set to true. catalog_ref = [make_v3_service(svc) for svc in services] # Filter the `catalog_ref` above by any project-endpoint # association configured by endpoint filter. filtered_endpoints = {} if project_id: filtered_endpoints = ( self.catalog_api.list_endpoints_for_project(project_id)) # endpoint filter is enabled, only return the filtered endpoints. if filtered_endpoints: filtered_ids = list(filtered_endpoints.keys()) # This is actually working on the copy of `catalog_ref` since # the index will be shifted if remove/add any entry for the # original one. for service in catalog_ref[:]: endpoints = service['endpoints'] for endpoint in endpoints[:]: endpoint_id = endpoint['id'] # remove the endpoint that is not associated with # the project. if endpoint_id not in filtered_ids: service['endpoints'].remove(endpoint) continue # remove the disabled endpoint from the list. if not filtered_endpoints[endpoint_id]['enabled']: service['endpoints'].remove(endpoint) # NOTE(davechen): The service will not be included in the # catalog if the service doesn't have any endpoint when # endpoint filter is enabled, this is inconsistent with # full catalog that is returned when endpoint filter is # disabled. if not service.get('endpoints'): catalog_ref.remove(service) # When it arrives here it means it's domain scoped token ( # `project_id` is not set) or it's a project scoped token # but the endpoint filtering is not performed. # Both of them tell us the endpoint filtering is not enabled, so # check the option of `return_all_endpoints_if_no_filter`, it will # judge whether a full unfiltered catalog or a empty service # catalog will be returned. elif not CONF.endpoint_filter.return_all_endpoints_if_no_filter: return [] return catalog_ref