Ejemplo n.º 1
0
 def store_item(self, product):
     """Handler for storing item. Should return new item id."""
     creator = api_utils.get_user_id()
     product['type'] = (const.SOFTWARE if product['product_type']
                        == const.DISTRO else const.CLOUD)
     if product['type'] == const.SOFTWARE:
         product['product_ref_id'] = six.text_type(uuid.uuid4())
     vendor_id = product.pop('organization_id', None)
     if not vendor_id:
         # find or create default vendor for new product
         # TODO(andrey-mp): maybe just fill with info here and create
         # at DB layer in one transaction
         default_vendor_name = 'vendor_' + creator
         vendors = db.get_organizations_by_user(creator)
         for v in vendors:
             if v['name'] == default_vendor_name:
                 vendor_id = v['id']
                 break
         else:
             vendor = {'name': default_vendor_name}
             vendor = db.add_organization(vendor, creator)
             vendor_id = vendor['id']
     product['organization_id'] = vendor_id
     product = db.add_product(product, creator)
     return {'id': product['id']}
Ejemplo n.º 2
0
    def get(self):
        """Get information of vendors."""
        allowed_keys = ['id', 'type', 'name', 'description']
        user = api_utils.get_user_id()
        try:
            is_admin = api_utils.check_user_is_foundation_admin()
            if is_admin:
                vendors = db.get_organizations(allowed_keys=allowed_keys)
                for vendor in vendors:
                    vendor['can_manage'] = True
            else:
                result = dict()
                types = [const.FOUNDATION, const.OFFICIAL_VENDOR]
                vendors = db.get_organizations_by_types(
                    types, allowed_keys=allowed_keys)
                for vendor in vendors:
                    _id = vendor['id']
                    result[_id] = vendor
                    result[_id]['can_manage'] = False

                vendors = db.get_organizations_by_user(
                    user, allowed_keys=allowed_keys)
                for vendor in vendors:
                    _id = vendor['id']
                    if _id not in result:
                        result[_id] = vendor
                    result[_id]['can_manage'] = True
                vendors = list(result.values())
        except Exception as ex:
            LOG.exception('An error occurred during '
                          'operation with database: %s' % ex)
            pecan.abort(400)
        return {'vendors': vendors}
Ejemplo n.º 3
0
    def get(self):
        """Get information of all products."""
        allowed_keys = ['id', 'name', 'description', 'product_ref_id', 'type',
                        'product_type', 'public', 'organization_id']
        user = api_utils.get_user_id()
        is_admin = user in db.get_foundation_users()
        try:
            if is_admin:
                products = db.get_products(allowed_keys=allowed_keys)
                for s in products:
                    s['can_manage'] = True
            else:
                result = dict()
                products = db.get_public_products(allowed_keys=allowed_keys)
                for s in products:
                    _id = s['id']
                    result[_id] = s
                    result[_id]['can_manage'] = False

                products = db.get_products_by_user(user,
                                                   allowed_keys=allowed_keys)
                for s in products:
                    _id = s['id']
                    if _id not in result:
                        result[_id] = s
                    result[_id]['can_manage'] = True
                products = result.values()
        except Exception as ex:
            LOG.exception('An error occurred during '
                          'operation with database: %s' % ex)
            pecan.abort(400)

        products.sort(key=lambda x: x['name'])
        return {'products': products}
Ejemplo n.º 4
0
    def delete(self, schema_id):
        """Delete schema."""
        schema = db.get_schema(schema_id)
        if schema['openid'] != api_utils.get_user_id():
            raise exc.HTTPUnauthorized('Only owner can do it with the schema.')

        db.delete_schema(schema_id)
        pecan.response.status = 204
Ejemplo n.º 5
0
 def store_item(self, body):
     """Handler for storing item."""
     pubkey = {'openid': api_utils.get_user_id()}
     parts = body['raw_key'].strip().split()
     if len(parts) == 2:
         parts.append('')
     pubkey['format'], pubkey['pubkey'], pubkey['comment'] = parts
     pubkey_id = db.store_pubkey(pubkey)
     return pubkey_id
Ejemplo n.º 6
0
    def store_item(self, version_info):
        """Add a new version for the product."""
        if (not api_utils.check_user_is_product_admin(self.product_id)
                and not api_utils.check_user_is_foundation_admin()):
            pecan.abort(403, 'Forbidden.')

        creator = api_utils.get_user_id()
        pecan.response.status = 201
        return db.add_product_version(self.product_id, version_info['version'],
                                      creator, version_info.get('cpid'))
Ejemplo n.º 7
0
    def put(self, vendor_id, openid):
        """Add user to vendor group."""
        openid = base64.b64decode(openid)

        if not (api_utils.check_user_is_foundation_admin()
                or api_utils.check_user_is_vendor_admin(vendor_id)):
            pecan.abort(403, 'Forbidden.')

        vendor = db.get_organization(vendor_id)
        creator = api_utils.get_user_id()
        db.add_user_to_group(openid, vendor['group_id'], creator)
        pecan.response.status = 204
Ejemplo n.º 8
0
    def get(self):
        """Get a list of all available schemas."""
        results = db.get_schemas()
        openid = api_utils.get_user_id()
        for result in results:
            if result['openid'] != openid:
                result['openid'] = None
        results = sorted(results,
            cmp=lambda x, y: cmp(x['description'], y['description'])
                if x['openid'] == y['openid'] else -1 if x['openid'] else 1)

        # TODO: add paging

        page = {'results': results,
                'pagination': {
                    'current_page': 1,
                    'total_pages': 1
                }}
        return page
Ejemplo n.º 9
0
 def store_item(self, schema):
     """Handler for storing item. Should return new item id."""
     schema['openid'] = api_utils.get_user_id()
     schema_id = db.store_schema(schema)
     return {'schema_id': schema_id}
Ejemplo n.º 10
0
 def store_item(self, vendor):
     """Handler for create item. Should return new item id."""
     creator = api_utils.get_user_id()
     vendor = db.add_organization(vendor, creator)
     return {'id': vendor['id']}