Пример #1
0
    def get(self):
        """Get information of all uploaded test results.

        Get information of all uploaded test results in descending
        chronological order. Make it possible to specify some
        input parameters for filtering.
        For example:
            /v1/results?page=<page number>&cpid=1234.
        By default, page is set to page number 1,
        if the page parameter is not specified.
        """
        expected_input_params = [
            const.START_DATE,
            const.END_DATE,
            const.CPID,
            const.SIGNED
        ]

        filters = api_utils.parse_input_params(expected_input_params)
        records_count = db.get_test_records_count(filters)
        page_number, total_pages_number = \
            api_utils.get_page_number(records_count)

        try:
            per_page = CONF.api.results_per_page
            results = db.get_test_records(page_number, per_page, filters)

            for result in results:
                result.update({'url': parse.urljoin(
                    CONF.ui_url, CONF.api.test_results_url
                ) % result['id']})

                cloud_id = result['cpid']
                cloud = db.get_cloud(cloud_id)
                if cloud:
                    result.update({'cloud_name': cloud['name'],
                                   'cloud_description': cloud['description']})

            page = {'results': results,
                    'pagination': {
                        'current_page': page_number,
                        'total_pages': total_pages_number
                    }}
        except Exception as ex:
            LOG.debug('An error occurred during '
                      'operation with database: %s' % ex)
            pecan.abort(400)

        return page
Пример #2
0
def _check_owner(test_id):
    """Check that user has access to specified test run as owner."""
    if not is_authenticated():
        return False

    # Check that test has pubkey attached that equals to user key
    test_pubkey = db.get_test_meta_key(test_id, const.PUBLIC_KEY)
    pubkeys = [' '.join((pk['format'], pk['pubkey']))
               for pk in get_user_public_keys()]
    if test_pubkey in pubkeys:
        return True

    # Check that test has link to cloud that belongs to user
    test = db.get_test(test_id)
    cloud = db.get_cloud(test['cpid'])
    if cloud and cloud['openid'] == get_user_id():
        return True

    return False
Пример #3
0
    def get_one(self, test_id):
        """Handler for getting item."""
        if api_utils.get_user_role(test_id) == const.ROLE_OWNER:
            test_info = db.get_test(
                test_id, allowed_keys=['id', 'cpid', 'created_at',
                                       'duration_seconds', 'meta']
            )
        else:
            test_info = db.get_test(test_id)
        test_list = db.get_test_results(test_id)
        test_name_list = [test_dict['name'] for test_dict in test_list]
        test_info.update({'results': test_name_list,
                          'user_role': api_utils.get_user_role(test_id)})

        cloud_id = test_info['cpid']
        cloud = db.get_cloud(cloud_id)
        if cloud:
            test_info.update({'cloud_name': cloud['name'],
                              'cloud_description': cloud['description'],
                              'cloud_shared': cloud['shared']})

        return test_info