Example #1
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start certificate_authorities on_get')

        plugin_name = kw.get('plugin_name')
        if plugin_name is not None:
            plugin_name = urllib.unquote_plus(plugin_name)

        plugin_ca_id = kw.get('plugin_ca_id', None)
        if plugin_ca_id is not None:
            plugin_ca_id = urllib.unquote_plus(plugin_ca_id)

        result = self.ca_repo.get_by_create_date(
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            plugin_name=plugin_name,
            plugin_ca_id=plugin_ca_id,
            suppress_exception=True)

        cas, offset, limit, total = result

        if not cas:
            cas_resp_overall = {'cas': [], 'total': total}
        else:
            cas_resp = [
                hrefs.convert_certificate_authority_to_href(s.id) for s in cas
            ]
            cas_resp_overall = hrefs.add_nav_hrefs('cas', offset, limit, total,
                                                   {'cas': cas_resp})
            cas_resp_overall.update({'total': total})

        return cas_resp_overall
Example #2
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start transport_keys on_get')

        plugin_name = kw.get('plugin_name', None)
        if plugin_name is not None:
            plugin_name = urllib.unquote_plus(plugin_name)

        result = self.repo.get_by_create_date(
            plugin_name=plugin_name,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True
        )

        transport_keys, offset, limit, total = result

        if not transport_keys:
            transport_keys_resp_overall = {'transport_keys': [],
                                           'total': total}
        else:
            transport_keys_resp = [
                hrefs.convert_transport_key_to_href(s.id)
                for s in transport_keys
            ]
            transport_keys_resp_overall = hrefs.add_nav_hrefs(
                'transport_keys', offset, limit, total,
                {'transport_keys': transport_keys_resp}
            )
            transport_keys_resp_overall.update({'total': total})

        return transport_keys_resp_overall
Example #3
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start consumers on_get '
                  'for secret-ID %s:', self.secret_id)
        result = self.consumer_repo.get_by_secret_id(self.secret_id,
                                                     offset_arg=kw.get(
                                                         'offset', 0),
                                                     limit_arg=kw.get('limit'),
                                                     suppress_exception=True)

        consumers, offset, limit, total = result

        if not consumers:
            resp_ctrs_overall = {'consumers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields()) for c in consumers
            ]
            consumer_path = "secrets/{secret_id}/consumers".format(
                secret_id=self.secret_id)

            resp_ctrs_overall = hrefs.add_nav_hrefs(consumer_path, offset,
                                                    limit, total,
                                                    {'consumers': resp_ctrs})
            resp_ctrs_overall.update({'total': total})

        LOG.info('Retrieved a consumer list for project: %s',
                 external_project_id)
        return resp_ctrs_overall
Example #4
0
    def on_get(self, project_id, **kw):
        LOG.debug('Start containers on_get for project-ID %s:', project_id)

        result = self.container_repo.get_by_create_date(
            project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True
        )

        containers, offset, limit, total = result

        if not containers:
            resp_ctrs_overall = {'containers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields())
                for c in containers
            ]

            for ctr in resp_ctrs:
                for secret_ref in ctr.get('secret_refs', []):
                    hrefs.convert_to_hrefs(secret_ref)

            resp_ctrs_overall = hrefs.add_nav_hrefs(
                'containers',
                offset,
                limit,
                total,
                {'containers': resp_ctrs}
            )
            resp_ctrs_overall.update({'total': total})

        return resp_ctrs_overall
Example #5
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start consumers on_get '
                  'for container-ID %s:', self.container_id)
        result = self.consumer_repo.get_by_container_id(
            self.container_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit'),
            suppress_exception=True
        )

        consumers, offset, limit, total = result

        if not consumers:
            resp_ctrs_overall = {'consumers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields())
                for c in consumers
            ]
            consumer_path = "containers/{container_id}/consumers".format(
                container_id=self.container_id)

            resp_ctrs_overall = hrefs.add_nav_hrefs(
                consumer_path,
                offset,
                limit,
                total,
                {'consumers': resp_ctrs}
            )
            resp_ctrs_overall.update({'total': total})

        LOG.info('Retrieved a consumer list for project: %s',
                 external_project_id)
        return resp_ctrs_overall
Example #6
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start consumers on_get '
                  'for container-ID %s:', self.container_id)

        try:
            self.container_repo.get(self.container_id, external_project_id)
        except exception.NotFound:
            controllers.containers.container_not_found()

        result = self.consumer_repo.get_by_container_id(
            self.container_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True
        )

        consumers, offset, limit, total = result

        if not consumers:
            resp_ctrs_overall = {'consumers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields())
                for c in consumers
            ]
            resp_ctrs_overall = hrefs.add_nav_hrefs(
                'consumers',
                offset,
                limit,
                total,
                {'consumers': resp_ctrs}
            )
            resp_ctrs_overall.update({'total': total})

        return resp_ctrs_overall
Example #7
0
    def on_get(self, project_id, **kw):
        LOG.debug('Start containers on_get for project-ID %s:', project_id)

        result = self.container_repo.get_by_create_date(
            project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            name_arg=kw.get('name', None),
            suppress_exception=True)

        containers, offset, limit, total = result

        if not containers:
            resp_ctrs_overall = {'containers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields()) for c in containers
            ]

            for ctr in resp_ctrs:
                for secret_ref in ctr.get('secret_refs', []):
                    hrefs.convert_to_hrefs(secret_ref)

            resp_ctrs_overall = hrefs.add_nav_hrefs('containers', offset,
                                                    limit, total,
                                                    {'containers': resp_ctrs})
            resp_ctrs_overall.update({'total': total})

        LOG.info(u._LI('Retrieved container list for project: %s'), project_id)
        return resp_ctrs_overall
Example #8
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start transport_keys on_get')

        plugin_name = kw.get('plugin_name', None)
        if plugin_name is not None:
            plugin_name = parse.unquote_plus(plugin_name)

        result = self.repo.get_by_create_date(
            plugin_name=plugin_name,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True
        )

        transport_keys, offset, limit, total = result

        if not transport_keys:
            transport_keys_resp_overall = {'transport_keys': [],
                                           'total': total}
        else:
            transport_keys_resp = [
                hrefs.convert_transport_key_to_href(s.id)
                for s in transport_keys
            ]
            transport_keys_resp_overall = hrefs.add_nav_hrefs(
                'transport_keys',
                offset,
                limit,
                total,
                {'transport_keys': transport_keys_resp}
            )
            transport_keys_resp_overall.update({'total': total})

        return transport_keys_resp_overall
Example #9
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start consumers on_get '
                  'for container-ID %s:', self.container_id)

        try:
            self.container_repo.get(self.container_id, external_project_id)
        except exception.NotFound:
            controllers.containers.container_not_found()

        result = self.consumer_repo.get_by_container_id(
            self.container_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True)

        consumers, offset, limit, total = result

        if not consumers:
            resp_ctrs_overall = {'consumers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields()) for c in consumers
            ]
            resp_ctrs_overall = hrefs.add_nav_hrefs('consumers', offset, limit,
                                                    total,
                                                    {'consumers': resp_ctrs})
            resp_ctrs_overall.update({'total': total})

        return resp_ctrs_overall
Example #10
0
    def on_get(self, external_project_id, **kw):
        LOG.debug(u._('Start consumers on_get '
                      'for container-ID %s:'), self.container_id)

        result = self.consumer_repo.get_by_container_id(
            self.container_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True)

        consumers, offset, limit, total = result

        if not consumers:
            resp_ctrs_overall = {'consumers': [], 'total': total}
        else:
            resp_ctrs = [
                hrefs.convert_to_hrefs(c.to_dict_fields()) for c in consumers
            ]
            resp_ctrs_overall = hrefs.add_nav_hrefs('consumers', offset, limit,
                                                    total,
                                                    {'consumers': resp_ctrs})
            resp_ctrs_overall.update({'total': total})

        LOG.info(u._LI('Retrieved a consumer list for project: %s'),
                 external_project_id)
        return resp_ctrs_overall
Example #11
0
    def test_add_nav_hrefs_adds_previous_only(self):
        offset = 90
        limit = 10

        data_with_hrefs = hrefs.add_nav_hrefs(self.resource_name, offset, limit, self.num_elements, self.data)

        self.assertIn("previous", data_with_hrefs)
        self.assertNotIn("next", data_with_hrefs)
Example #12
0
    def test_add_nav_hrefs_adds_both_next_and_previous(self):
        offset = 10
        limit = 10

        data_with_hrefs = hrefs.add_nav_hrefs(
            self.resource_name, offset, limit, self.num_elements, self.data)

        self.assertIn('previous', data_with_hrefs)
        self.assertIn('next', data_with_hrefs)
Example #13
0
    def test_add_nav_hrefs_adds_previous_only(self):
        offset = 90
        limit = 10

        data_with_hrefs = hrefs.add_nav_hrefs(
            self.resource_name, offset, limit, self.num_elements, self.data)

        self.assertIn('previous', data_with_hrefs)
        self.assertNotIn('next', data_with_hrefs)
Example #14
0
    def on_get(self, external_project_id, **kw):
        def secret_fields(field):
            return putil.mime_types.augment_fields_with_content_types(field)

        LOG.debug('Start secrets on_get '
                  'for project-ID %s:', external_project_id)

        name = kw.get('name', '')
        if name:
            name = parse.unquote_plus(name)

        bits = kw.get('bits', 0)
        try:
            bits = int(bits)
        except ValueError:
            # as per Github issue 171, if bits is invalid then
            # the default should be used.
            bits = 0

        ctxt = controllers._get_barbican_context(pecan.request)
        user_id = None
        if ctxt:
            user_id = ctxt.user

        result = self.secret_repo.get_by_create_date(
            external_project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            name=name,
            alg=kw.get('alg'),
            mode=kw.get('mode'),
            bits=bits,
            suppress_exception=True,
            acl_only=kw.get('acl_only', None),
            user_id=user_id
        )

        secrets, offset, limit, total = result

        if not secrets:
            secrets_resp_overall = {'secrets': [],
                                    'total': total}
        else:
            secrets_resp = [
                hrefs.convert_to_hrefs(secret_fields(s))
                for s in secrets
            ]
            secrets_resp_overall = hrefs.add_nav_hrefs(
                'secrets', offset, limit, total,
                {'secrets': secrets_resp}
            )
            secrets_resp_overall.update({'total': total})

        LOG.info(u._LI('Retrieved secret list for project: %s'),
                 external_project_id)
        return secrets_resp_overall
Example #15
0
    def on_get(self, external_project_id, **kw):
        def secret_fields(field):
            return putil.mime_types.augment_fields_with_content_types(field)

        LOG.debug('Start secrets on_get '
                  'for project-ID %s:', external_project_id)

        name = kw.get('name', '')
        if name:
            name = parse.unquote_plus(name)

        bits = kw.get('bits', 0)
        try:
            bits = int(bits)
        except ValueError:
            # as per Github issue 171, if bits is invalid then
            # the default should be used.
            bits = 0

        ctxt = controllers._get_barbican_context(pecan.request)
        user_id = None
        if ctxt:
            user_id = ctxt.user

        result = self.secret_repo.get_by_create_date(
            external_project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            name=name,
            alg=kw.get('alg'),
            mode=kw.get('mode'),
            bits=bits,
            suppress_exception=True,
            acl_only=kw.get('acl_only', None),
            user_id=user_id
        )

        secrets, offset, limit, total = result

        if not secrets:
            secrets_resp_overall = {'secrets': [],
                                    'total': total}
        else:
            secrets_resp = [
                hrefs.convert_to_hrefs(secret_fields(s))
                for s in secrets
            ]
            secrets_resp_overall = hrefs.add_nav_hrefs(
                'secrets', offset, limit, total,
                {'secrets': secrets_resp}
            )
            secrets_resp_overall.update({'total': total})

        LOG.info(u._LI('Retrieved secret list for project: %s'),
                 external_project_id)
        return secrets_resp_overall
Example #16
0
    def _display_cas(self, cas, offset, limit, total):
        if not cas:
            cas_resp_overall = {'cas': [], 'total': total}
        else:
            cas_resp = [
                hrefs.convert_certificate_authority_to_href(ca.id)
                for ca in cas
            ]
            cas_resp_overall = hrefs.add_nav_hrefs('cas', offset, limit, total,
                                                   {'cas': cas_resp})
            cas_resp_overall.update({'total': total})

        return cas_resp_overall
Example #17
0
    def _display_cas(self, cas, offset, limit, total):
        if not cas:
            cas_resp_overall = {'cas': [],
                                'total': total}
        else:
            cas_resp = [
                hrefs.convert_certificate_authority_to_href(ca.id)
                for ca in cas]
            cas_resp_overall = hrefs.add_nav_hrefs('cas', offset, limit, total,
                                                   {'cas': cas_resp})
            cas_resp_overall.update({'total': total})

        return cas_resp_overall
Example #18
0
    def index(self, keystone_id, **kw):
        def secret_fields(field):
            return putil.mime_types.augment_fields_with_content_types(field)

        LOG.debug('Start secrets on_get '
                  'for project-ID %s:', keystone_id)

        name = kw.get('name', '')
        if name:
            name = urllib.unquote_plus(name)

        bits = kw.get('bits', 0)
        try:
            bits = int(bits)
        except ValueError:
            # as per Github issue 171, if bits is invalid then
            # the default should be used.
            bits = 0

        result = self.repos.secret_repo.get_by_create_date(
            keystone_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            name=name,
            alg=kw.get('alg'),
            mode=kw.get('mode'),
            bits=bits,
            suppress_exception=True
        )

        secrets, offset, limit, total = result

        if not secrets:
            secrets_resp_overall = {'secrets': [],
                                    'total': total}
        else:
            secrets_resp = [
                hrefs.convert_to_hrefs(secret_fields(s))
                for s in secrets
            ]
            secrets_resp_overall = hrefs.add_nav_hrefs(
                'secrets', offset, limit, total,
                {'secrets': secrets_resp}
            )
            secrets_resp_overall.update({'total': total})

        return secrets_resp_overall
Example #19
0
    def get_project_quotas_list(self, offset_arg=None, limit_arg=None):
        """Return a dict and list of all configured quota information

        :return: a dict and list of a page of quota config info
        """
        retrieved_project_quotas, offset, limit, total = self.repo.get_by_create_date(
            offset_arg=offset_arg, limit_arg=limit_arg, suppress_exception=True
        )
        resp_quotas = []
        for quotas in retrieved_project_quotas:
            list_item = {
                "project_id": quotas.project.external_id,
                "project_quotas": self._extract_project_quotas(quotas),
            }
            resp_quotas.append(list_item)
        resp = {"project_quotas": resp_quotas}
        resp_overall = hrefs.add_nav_hrefs("project_quotas", offset, limit, total, resp)
        resp_overall.update({"total": total})
        return resp_overall
Example #20
0
    def on_get(self, external_project_id, **kw):
        def secret_fields(field):
            return putil.mime_types.augment_fields_with_content_types(field)

        LOG.debug('Start secrets on_get '
                  'for project-ID %s:', external_project_id)

        name = kw.get('name', '')
        if name:
            name = urllib.unquote_plus(name)

        bits = kw.get('bits', 0)
        try:
            bits = int(bits)
        except ValueError:
            # as per Github issue 171, if bits is invalid then
            # the default should be used.
            bits = 0

        result = self.repos.secret_repo.get_by_create_date(
            external_project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            name=name,
            alg=kw.get('alg'),
            mode=kw.get('mode'),
            bits=bits,
            suppress_exception=True)

        secrets, offset, limit, total = result

        if not secrets:
            secrets_resp_overall = {'secrets': [], 'total': total}
        else:
            secrets_resp = [
                hrefs.convert_to_hrefs(secret_fields(s)) for s in secrets
            ]
            secrets_resp_overall = hrefs.add_nav_hrefs(
                'secrets', offset, limit, total, {'secrets': secrets_resp})
            secrets_resp_overall.update({'total': total})

        return secrets_resp_overall
Example #21
0
    def get_project_quotas_list(self, offset_arg=None, limit_arg=None):
        """Return a dict and list of all configured quota information

        :return: a dict and list of a page of quota config info
        """
        retrieved_project_quotas, offset, limit, total =\
            self.repo.get_by_create_date(offset_arg=offset_arg,
                                         limit_arg=limit_arg,
                                         suppress_exception=True)
        resp_quotas = []
        for quotas in retrieved_project_quotas:
            list_item = {'project_id': quotas.project.external_id,
                         'project_quotas':
                             self._extract_project_quotas(quotas)}
            resp_quotas.append(list_item)
        resp = {'project_quotas': resp_quotas}
        resp_overall = hrefs.add_nav_hrefs(
            'project_quotas', offset, limit, total, resp)
        resp_overall.update({'total': total})
        return resp_overall
Example #22
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start certificate_authorities on_get')

        plugin_name = kw.get('plugin_name')
        if plugin_name is not None:
            plugin_name = urllib.unquote_plus(plugin_name)

        plugin_ca_id = kw.get('plugin_ca_id', None)
        if plugin_ca_id is not None:
            plugin_ca_id = urllib.unquote_plus(plugin_ca_id)

        result = self.ca_repo.get_by_create_date(
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            plugin_name=plugin_name,
            plugin_ca_id=plugin_ca_id,
            suppress_exception=True
        )

        cas, offset, limit, total = result

        if not cas:
            cas_resp_overall = {'cas': [],
                                'total': total}
        else:
            cas_resp = [
                hrefs.convert_certificate_authority_to_href(s.id)
                for s in cas
            ]
            cas_resp_overall = hrefs.add_nav_hrefs(
                'cas',
                offset,
                limit,
                total,
                {'cas': cas_resp}
            )
            cas_resp_overall.update({'total': total})

        return cas_resp_overall
Example #23
0
    def get_project_quotas_list(self, offset_arg=None, limit_arg=None):
        """Return a dict and list of all configured quota information

        :return: a dict and list of a page of quota config info
        """
        session = self.repo.get_session()
        retrieved_project_quotas, offset, limit, total =\
            self.repo.get_by_create_date(session=session,
                                         offset_arg=offset_arg,
                                         limit_arg=limit_arg,
                                         suppress_exception=True)
        resp_quotas = []
        for quotas in retrieved_project_quotas:
            list_item = {'project_id': quotas.project_id,
                         'project_quotas':
                             self._extract_project_quotas(quotas)}
            resp_quotas.append(list_item)
        resp = {'project_quotas': resp_quotas}
        resp_overall = hrefs.add_nav_hrefs(
            'project_quotas', offset, limit, total, resp)
        resp_overall.update({'total': total})
        return resp_overall
Example #24
0
    def on_get(self, external_project_id, **kw):
        LOG.debug('Start orders on_get '
                  'for project-ID %s:', external_project_id)

        result = self.order_repo.get_by_create_date(
            external_project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None),
            suppress_exception=True)
        orders, offset, limit, total = result

        if not orders:
            orders_resp_overall = {'orders': [], 'total': total}
        else:
            orders_resp = [
                hrefs.convert_to_hrefs(o.to_dict_fields()) for o in orders
            ]
            orders_resp_overall = hrefs.add_nav_hrefs('orders', offset, limit,
                                                      total,
                                                      {'orders': orders_resp})
            orders_resp_overall.update({'total': total})

        return orders_resp_overall
Example #25
0
    def index(self, keystone_id, **kw):
        LOG.debug('Start orders on_get '
                  'for project-ID %s:', keystone_id)

        result = self.order_repo.get_by_create_date(
            keystone_id, offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit', None), suppress_exception=True)
        orders, offset, limit, total = result

        if not orders:
            orders_resp_overall = {'orders': [],
                                   'total': total}
        else:
            orders_resp = [
                hrefs.convert_to_hrefs(o.to_dict_fields())
                for o in orders
            ]
            orders_resp_overall = hrefs.add_nav_hrefs('orders',
                                                      offset, limit, total,
                                                      {'orders': orders_resp})
            orders_resp_overall.update({'total': total})

        return orders_resp_overall
Example #26
0
    def on_get(self, external_project_id, **kw):
        no_consumers = versions.is_supported(pecan.request, max_version='1.0')

        # NOTE(xek): consumers are being introduced in 1.1

        def secret_fields(field):
            resp = putil.mime_types.augment_fields_with_content_types(field)
            if no_consumers:
                del resp['consumers']
            return resp

        LOG.debug('Start secrets on_get '
                  'for project-ID %s:', external_project_id)

        name = kw.get('name', '')
        if name:
            name = parse.unquote_plus(name)

        bits = kw.get('bits', 0)
        try:
            bits = int(bits)
        except ValueError:
            # as per Github issue 171, if bits is invalid then
            # the default should be used.
            bits = 0

        for date_filter in 'created', 'updated', 'expiration':
            if kw.get(date_filter) and not self._is_valid_date_filter(
                    kw.get(date_filter)):
                _bad_query_string_parameters()
        if kw.get('sort') and not self._is_valid_sorting(kw.get('sort')):
            _bad_query_string_parameters()

        ctxt = controllers._get_barbican_context(pecan.request)
        user_id = None
        if ctxt:
            user_id = ctxt.user

        result = self.secret_repo.get_secret_list(
            external_project_id,
            offset_arg=kw.get('offset', 0),
            limit_arg=kw.get('limit'),
            name=name,
            alg=kw.get('alg'),
            mode=kw.get('mode'),
            bits=bits,
            secret_type=kw.get('secret_type'),
            suppress_exception=True,
            acl_only=kw.get('acl_only'),
            user_id=user_id,
            created=kw.get('created'),
            updated=kw.get('updated'),
            expiration=kw.get('expiration'),
            sort=kw.get('sort'))

        secrets, offset, limit, total = result

        if not secrets:
            secrets_resp_overall = {'secrets': [], 'total': total}
        else:
            secrets_resp = [
                hrefs.convert_to_hrefs(secret_fields(s)) for s in secrets
            ]
            secrets_resp_overall = hrefs.add_nav_hrefs(
                'secrets', offset, limit, total, {'secrets': secrets_resp})
            secrets_resp_overall.update({'total': total})

        LOG.info('Retrieved secret list for project: %s', external_project_id)
        return secrets_resp_overall