예제 #1
0
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id, 'user_id': user_id})
        catalog = {}

        endpoints = self.list_endpoints()
        for ep in endpoints:
            service = self.get_service(ep['service_id'])
            srv_type = service['type']
            srv_name = service['name']
            region = ep['region']

            if region not in catalog:
                catalog[region] = {}

            catalog[region][srv_type] = {}

            srv_type = catalog[region][srv_type]
            srv_type['id'] = ep['id']
            srv_type['name'] = srv_name
            srv_type['publicURL'] = core.format_url(ep.get('publicurl', ''), d)
            srv_type['internalURL'] = core.format_url(ep.get('internalurl'), d)
            srv_type['adminURL'] = core.format_url(ep.get('adminurl'), d)

        return catalog
예제 #2
0
파일: sql.py 프로젝트: a3linux/keystone
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id,
                  'user_id': user_id})
        catalog = {}

        endpoints = [self.get_endpoint(e)
                     for e in self.list_endpoints()]
        for ep in endpoints:
            service = self.get_service(ep['service_id'])
            srv_type = service['type']
            srv_name = service['name']
            region = ep['region']

            if region not in catalog:
                catalog[region] = {}

            catalog[region][srv_type] = {}

            srv_type = catalog[region][srv_type]
            srv_type['id'] = ep['id']
            srv_type['name'] = srv_name
            srv_type['publicURL'] = core.format_url(ep.get('publicurl', ''), d)
            srv_type['internalURL'] = core.format_url(ep.get('internalurl'), d)
            srv_type['adminURL'] = core.format_url(ep.get('adminurl'), d)

        return catalog
예제 #3
0
    def test_successful_formatting(self):
        url_template = 'http://%(host)s:%(port)d/%(part1)s/%(part2)s'
        values = {'host': 'server', 'port': 9090, 'part1': 'A', 'part2': 'B'}
        actual_url = core.format_url(url_template, values)

        expected_url = 'http://server:9090/A/B'
        self.assertEqual(actual_url, expected_url)
예제 #4
0
    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
예제 #5
0
파일: sql.py 프로젝트: AsherBond/keystone
    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
예제 #6
0
파일: sql.py 프로젝트: craigtracey/keystone
    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
예제 #7
0
파일: sql.py 프로젝트: wputra/MOS-centos
        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
예제 #8
0
        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
예제 #9
0
    def test_successful_formatting(self):
        url_template = 'http://%(host)s:%(port)d/%(part1)s/%(part2)s'
        values = {'host': 'server', 'port': 9090, 'part1': 'A', 'part2': 'B'}
        actual_url = core.format_url(url_template, values)

        expected_url = 'http://server:9090/A/B'
        self.assertEqual(actual_url, expected_url)
예제 #10
0
파일: sql.py 프로젝트: CiscoAS/keystone
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id,
                  'user_id': user_id})

        catalog = {}
        services = {}
        for endpoint in self.list_endpoints():
            # look up the service
            services.setdefault(
                endpoint['service_id'],
                self.get_service(endpoint['service_id']))
            service = services[endpoint['service_id']]

            # add the endpoint to the catalog if it's not already there
            catalog.setdefault(endpoint['region'], {})
            catalog[endpoint['region']].setdefault(
                service['type'], {
                    'id': endpoint['id'],
                    'name': service['name'],
                    'publicURL': '',  # this may be overridden, but must exist
                })

            # add the interface's url
            url = core.format_url(endpoint.get('url'), d)
            interface_url = '%sURL' % endpoint['interface']
            catalog[endpoint['region']][service['type']][interface_url] = url

        return catalog
예제 #11
0
파일: sql.py 프로젝트: k4veri/keystone
    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
예제 #12
0
파일: sql.py 프로젝트: CiscoAS/keystone
    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})

        services = {}
        for endpoint in self.list_endpoints():
            # look up the service
            service_id = endpoint['service_id']
            services.setdefault(
                service_id,
                self.get_service(service_id))
            service = services[service_id]
            del endpoint['service_id']
            endpoint['url'] = core.format_url(endpoint['url'], d)
            if 'endpoints' in services[service_id]:
                services[service_id]['endpoints'].append(endpoint)
            else:
                services[service_id]['endpoints'] = [endpoint]

        catalog = []
        for service_id, service in services.iteritems():
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #13
0
    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})

        services = {}
        for endpoint in self.list_endpoints():
            # look up the service
            service_id = endpoint['service_id']
            services.setdefault(service_id, self.get_service(service_id))
            service = services[service_id]
            del endpoint['service_id']
            endpoint['url'] = core.format_url(endpoint['url'], d)
            if 'endpoints' in services[service_id]:
                services[service_id]['endpoints'].append(endpoint)
            else:
                services[service_id]['endpoints'] = [endpoint]

        catalog = []
        for service_id, service in services.iteritems():
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #14
0
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id, 'user_id': user_id})

        catalog = {}
        services = {}
        for endpoint in self.list_endpoints():
            # look up the service
            services.setdefault(endpoint['service_id'],
                                self.get_service(endpoint['service_id']))
            service = services[endpoint['service_id']]

            # add the endpoint to the catalog if it's not already there
            catalog.setdefault(endpoint['region'], {})
            catalog[endpoint['region']].setdefault(
                service['type'],
                {
                    'id': endpoint['id'],
                    'name': service['name'],
                    'publicURL': '',  # this may be overridden, but must exist
                })

            # add the interface's url
            url = core.format_url(endpoint.get('url'), d)
            interface_url = '%sURL' % endpoint['interface']
            catalog[endpoint['region']][service['type']][interface_url] = url

        return catalog
예제 #15
0
    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
예제 #16
0
    def test_successful_formatting(self):
        url_template = ('http://$(public_bind_host)s:$(admin_port)d/'
                        '$(tenant_id)s/$(user_id)s')
        values = {'public_bind_host': 'server', 'admin_port': 9090,
                  'tenant_id': 'A', 'user_id': 'B'}
        actual_url = core.format_url(url_template, values)

        expected_url = 'http://server:9090/A/B'
        self.assertEqual(actual_url, expected_url)
예제 #17
0
    def get_v3_catalog(self, user_id, project_id, metadata=None):
        substitutions = dict(six.iteritems(CONF))
        substitutions.update({'tenant_id': project_id, 'user_id': user_id})

        services = {}

        refs = self.endpoint_filter_api.list_filtered_endpoints_for_project(
            project_id)

        if (not refs and
                CONF.endpoint_filter.return_all_endpoints_if_no_filter):
            return super(EndpointFilterCatalog, self).get_v3_catalog(
                user_id, project_id, metadata=metadata)

        for endpoint in refs:
            try:
                endpoint = self.get_endpoint(endpoint['id'])
                if not endpoint['enabled']:
                    # Skip disabled endpoints.
                    continue
                service_id = endpoint['service_id']
                services.setdefault(
                    service_id,
                    self.get_service(service_id))
                service = services[service_id]
                del endpoint['service_id']
                del endpoint['enabled']
                del endpoint['legacy_endpoint_id']
                endpoint['url'] = catalog_core.format_url(
                    endpoint['url'], substitutions)
                # populate filtered endpoints
                if 'endpoints' in services[service_id]:
                    service['endpoints'].append(endpoint)
                else:
                    service['endpoints'] = [endpoint]
            except exception.EndpointNotFound:
                # remove bad reference from association
                self.endpoint_filter_api.remove_endpoint_from_project(
                    endpoint['id'], project_id)

        # format catalog
        catalog = []
        for service_id, service in six.iteritems(services):
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            for endpoint in service['endpoints']:
                # NOTE(garcianavalon) change region_id for region
                # like old catalog services!
                region = endpoint.pop('region_id', None)
                if region:
                    endpoint['region'] = region

            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #18
0
    def test_successful_formatting(self):
        url_template = ('http://$(public_bind_host)s:$(admin_port)d/'
                        '$(tenant_id)s/$(user_id)s/$(project_id)s')
        project_id = uuid.uuid4().hex
        values = {'public_bind_host': 'server', 'admin_port': 9090,
                  'tenant_id': 'A', 'user_id': 'B', 'project_id': project_id}
        actual_url = core.format_url(url_template, values)

        expected_url = 'http://server:9090/A/B/%s' % (project_id,)
        self.assertEqual(expected_url, actual_url)
예제 #19
0
파일: sql.py 프로젝트: AsherBond/keystone
        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
예제 #20
0
파일: sql.py 프로젝트: k4veri/keystone
        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
예제 #21
0
 def test_substitution_with_allowed_keyerror(self):
     # No value of 'tenant_id' is passed into url_template.
     # mod: format_url will return None instead of raising
     # "MalformedEndpoint" exception.
     # This is intentional behavior since we don't want to skip
     # all the later endpoints once there is an URL of endpoint
     # trying to replace 'tenant_id' with None.
     url_template = ('http://$(public_bind_host)s:$(admin_port)d/'
                     '$(tenant_id)s/$(user_id)s')
     values = {'public_bind_host': 'server', 'admin_port': 9090,
               'user_id': 'B'}
     self.assertIsNone(core.format_url(url_template, values,
                       silent_keyerror_failures=['tenant_id']))
예제 #22
0
 def test_substitution_with_allowed_project_keyerror(self):
     # No value of 'project_id' is passed into url_template.
     # mod: format_url will return None instead of raising
     # "MalformedEndpoint" exception.
     # This is intentional behavior since we don't want to skip
     # all the later endpoints once there is an URL of endpoint
     # trying to replace 'project_id' with None.
     url_template = ('http://$(public_bind_host)s:$(admin_port)d/'
                     '$(project_id)s/$(user_id)s')
     values = {'public_bind_host': 'server', 'admin_port': 9090,
               'user_id': 'B'}
     self.assertIsNone(core.format_url(url_template, values,
                       silent_keyerror_failures=['project_id']))
예제 #23
0
    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})

        o = {}
        for region, region_ref in six.iteritems(self.templates):
            o[region] = {}
            for service, service_ref in six.iteritems(region_ref):
                o[region][service] = {}
                for k, v in six.iteritems(service_ref):
                    o[region][service][k] = core.format_url(v, d)

        return o
예제 #24
0
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id, 'user_id': user_id})

        o = {}
        for region, region_ref in self.templates.iteritems():
            o[region] = {}
            for service, service_ref in region_ref.iteritems():
                o[region][service] = {}
                for k, v in service_ref.iteritems():
                    o[region][service][k] = core.format_url(v, d)

        return o
예제 #25
0
    def test_successful_formatting(self):
        url_template = ('http://$(public_bind_host)s:$(admin_port)d/'
                        '$(tenant_id)s/$(user_id)s')
        values = {
            'public_bind_host': 'server',
            'admin_port': 9090,
            'tenant_id': 'A',
            'user_id': 'B'
        }
        actual_url = core.format_url(url_template, values)

        expected_url = 'http://server:9090/A/B'
        self.assertEqual(actual_url, expected_url)
예제 #26
0
    def get_v3_catalog(self, user_id, project_id):
        substitutions = dict(CONF.items())
        substitutions.update({
            'tenant_id': project_id,
            'project_id': project_id,
            'user_id': user_id,
        })

        services = {}

        dict_of_endpoint_refs = (self.catalog_api.
                                 list_endpoints_for_project(project_id))

        if (not dict_of_endpoint_refs and
                CONF.endpoint_filter.return_all_endpoints_if_no_filter):
            return super(EndpointFilterCatalog, self).get_v3_catalog(
                user_id, project_id)

        for endpoint_id, endpoint in dict_of_endpoint_refs.items():
            if not endpoint['enabled']:
                # Skip disabled endpoints.
                continue
            service_id = endpoint['service_id']
            services.setdefault(
                service_id,
                self.get_service(service_id))
            service = services[service_id]
            del endpoint['service_id']
            del endpoint['enabled']
            del endpoint['legacy_endpoint_id']
            # Include deprecated region for backwards compatibility
            endpoint['region'] = endpoint['region_id']
            endpoint['url'] = catalog_core.format_url(
                endpoint['url'], substitutions)
            # populate filtered endpoints
            if 'endpoints' in services[service_id]:
                service['endpoints'].append(endpoint)
            else:
                service['endpoints'] = [endpoint]

        # format catalog
        catalog = []
        for service_id, service in services.items():
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['name'] = service['name']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #27
0
    def get_catalog(self, user_id, tenant_id, metadata=None):
        d = dict(CONF.iteritems())
        d.update({'tenant_id': tenant_id,
                  'user_id': user_id})

        o = {}
        for region, region_ref in self.templates.iteritems():
            o[region] = {}
            for service, service_ref in region_ref.iteritems():
                o[region][service] = {}
                for k, v in service_ref.iteritems():
                    o[region][service][k] = core.format_url(v, d)

        return o
예제 #28
0
    def get_v3_catalog(self, user_id, project_id):
        substitutions = dict(CONF.items())
        substitutions.update({
            'tenant_id': project_id,
            'project_id': project_id,
            'user_id': user_id,
        })

        services = {}

        dict_of_endpoint_refs = (
            self.catalog_api.list_endpoints_for_project(project_id))

        if (not dict_of_endpoint_refs
                and CONF.endpoint_filter.return_all_endpoints_if_no_filter):
            return super(EndpointFilterCatalog,
                         self).get_v3_catalog(user_id, project_id)

        for endpoint_id, endpoint in dict_of_endpoint_refs.items():
            if not endpoint['enabled']:
                # Skip disabled endpoints.
                continue
            service_id = endpoint['service_id']
            services.setdefault(service_id, self.get_service(service_id))
            service = services[service_id]
            del endpoint['service_id']
            del endpoint['enabled']
            del endpoint['legacy_endpoint_id']
            # Include deprecated region for backwards compatibility
            endpoint['region'] = endpoint['region_id']
            endpoint['url'] = catalog_core.format_url(endpoint['url'],
                                                      substitutions)
            # populate filtered endpoints
            if 'endpoints' in services[service_id]:
                service['endpoints'].append(endpoint)
            else:
                service['endpoints'] = [endpoint]

        # format catalog
        catalog = []
        for service_id, service in services.items():
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['name'] = service['name']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #29
0
    def get_v3_catalog(self, user_id, project_id, metadata=None):
        substitutions = dict(six.iteritems(CONF))
        substitutions.update({'tenant_id': project_id, 'user_id': user_id})

        services = {}

        refs = self.endpoint_filter_api.list_endpoints_for_project(project_id)

        if (not refs
                and CONF.endpoint_filter.return_all_endpoints_if_no_filter):
            return super(EndpointFilterCatalog,
                         self).get_v3_catalog(user_id,
                                              project_id,
                                              metadata=metadata)

        for entry in refs:
            try:
                endpoint = self.get_endpoint(entry['endpoint_id'])
                if not endpoint['enabled']:
                    # Skip disabled endpoints.
                    continue
                service_id = endpoint['service_id']
                services.setdefault(service_id, self.get_service(service_id))
                service = services[service_id]
                del endpoint['service_id']
                del endpoint['enabled']
                del endpoint['legacy_endpoint_id']
                endpoint['url'] = catalog_core.format_url(
                    endpoint['url'], substitutions)
                # populate filtered endpoints
                if 'endpoints' in services[service_id]:
                    service['endpoints'].append(endpoint)
                else:
                    service['endpoints'] = [endpoint]
            except exception.EndpointNotFound:
                # remove bad reference from association
                self.endpoint_filter_api.remove_endpoint_from_project(
                    entry['endpoint_id'], project_id)

        # format catalog
        catalog = []
        for service_id, service in six.iteritems(services):
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #30
0
    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})

        catalog = {}
        for region, region_ref in six.iteritems(self.templates):
            catalog[region] = {}
            for service, service_ref in six.iteritems(region_ref):
                service_data = {}
                try:
                    for k, v in six.iteritems(service_ref):
                        service_data[k] = core.format_url(v, substitutions)
                except exception.MalformedEndpoint:
                    continue  # this failure is already logged in format_url()
                catalog[region][service] = service_data

        return catalog
예제 #31
0
파일: sql.py 프로젝트: darren-wang/ks3
        def make_v3_endpoints(endpoints):
            for endpoint in (ep.to_dict() for ep in endpoints if ep.enabled):
                del endpoint['service_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
예제 #32
0
    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.

        :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,
                'project_id': tenant_id,
            })
        else:
            silent_keyerror_failures = ['tenant_id', 'project_id', ]

        catalog = {}
        # TODO(davechen): If there is service with no endpoints, we should
        # skip the service instead of keeping it in the catalog.
        # see bug #1436704.
        for region, region_ref in self.templates.items():
            catalog[region] = {}
            for service, service_ref in region_ref.items():
                service_data = {}
                try:
                    for k, v in service_ref.items():
                        formatted_value = core.format_url(
                            v, substitutions,
                            silent_keyerror_failures=silent_keyerror_failures)
                        if formatted_value:
                            service_data[k] = formatted_value
                except exception.MalformedEndpoint:
                    continue  # this failure is already logged in format_url()
                catalog[region][service] = service_data

        return catalog
예제 #33
0
    def get_v3_catalog(self, user_id, project_id, metadata=None):
        d = dict(six.iteritems(CONF))
        d.update({'tenant_id': project_id, 'user_id': user_id})

        services = {}

        refs = self.endpoint_filter_api.list_endpoints_for_project(project_id)

        if (not refs and
                CONF.endpoint_filter.return_all_endpoints_if_no_filter):
            return super(EndpointFilterCatalog, self).get_v3_catalog(
                user_id, project_id, metadata=metadata)

        for entry in refs:
            try:
                endpoint = self.get_endpoint(entry.endpoint_id)
                service_id = endpoint['service_id']
                services.setdefault(
                    service_id,
                    self.get_service(service_id))
                service = services[service_id]
                del endpoint['service_id']
                endpoint['url'] = catalog_core.format_url(
                    endpoint['url'], d)
                # populate filtered endpoints
                if 'endpoints' in services[service_id]:
                    service['endpoints'].append(endpoint)
                else:
                    service['endpoints'] = [endpoint]
            except exception.EndpointNotFound:
                # remove bad reference from association
                self.endpoint_filter_api.remove_endpoint_from_project(
                    entry.endpoint_id, project_id)

        # format catalog
        catalog = []
        for service_id, service in six.iteritems(services):
            formatted_service = {}
            formatted_service['id'] = service['id']
            formatted_service['type'] = service['type']
            formatted_service['endpoints'] = service['endpoints']
            catalog.append(formatted_service)

        return catalog
예제 #34
0
    def get_v3_catalog(self, user_id, project_id):
        substitutions = dict(six.iteritems(CONF))
        substitutions.update({"tenant_id": project_id, "user_id": user_id})

        services = {}

        refs = self.endpoint_filter_api.list_endpoints_for_project(project_id)

        if not refs and CONF.endpoint_filter.return_all_endpoints_if_no_filter:
            return super(EndpointFilterCatalog, self).get_v3_catalog(user_id, project_id)

        for entry in refs:
            try:
                endpoint = self.get_endpoint(entry["endpoint_id"])
                if not endpoint["enabled"]:
                    # Skip disabled endpoints.
                    continue
                service_id = endpoint["service_id"]
                services.setdefault(service_id, self.get_service(service_id))
                service = services[service_id]
                del endpoint["service_id"]
                del endpoint["enabled"]
                del endpoint["legacy_endpoint_id"]
                endpoint["url"] = catalog_core.format_url(endpoint["url"], substitutions)
                # populate filtered endpoints
                if "endpoints" in services[service_id]:
                    service["endpoints"].append(endpoint)
                else:
                    service["endpoints"] = [endpoint]
            except exception.EndpointNotFound:
                # remove bad reference from association
                self.endpoint_filter_api.remove_endpoint_from_project(entry["endpoint_id"], project_id)

        # format catalog
        catalog = []
        for service_id, service in six.iteritems(services):
            formatted_service = {}
            formatted_service["id"] = service["id"]
            formatted_service["type"] = service["type"]
            formatted_service["endpoints"] = service["endpoints"]
            catalog.append(formatted_service)

        return catalog
예제 #35
0
파일: sql.py 프로젝트: craigtracey/keystone
 def make_v3_endpoint(endpoint):
     del endpoint['service_id']
     endpoint['url'] = core.format_url(endpoint['url'], d)
     return endpoint
예제 #36
0
 def test_format_helper_raises_malformed_on_wrong_type(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%foo%s", {"foo": "1"})
예제 #37
0
 def test_format_helper_raises_malformed_on_missing_key(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%(foo)s/%(bar)s", {"foo": "1"})
예제 #38
0
 def test_format_helper_raises_malformed_on_incomplete_format(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%(foo)", {"foo": "1"})
예제 #39
0
 def make_v3_endpoint(endpoint):
     endpoint = endpoint.to_dict()
     del endpoint['service_id']
     endpoint['url'] = core.format_url(endpoint['url'], d)
     return endpoint
예제 #40
0
 def test_format_helper_raises_malformed_on_missing_key(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%(foo)s/%(bar)s", {"foo": "1"})
예제 #41
0
 def test_format_helper_raises_malformed_on_incomplete_format(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%(foo)", {"foo": "1"})
예제 #42
0
 def test_format_helper_raises_malformed_on_wrong_type(self):
     with self.assertRaises(exception.MalformedEndpoint):
         core.format_url("http://%foo%s", {"foo": "1"})