예제 #1
0
def api_packager_acl(packagername=None):
    '''
    User's ACL
    ----------
    List the ACLs of the user.

    ::

        /api/packager/acl/<fas_username>/

        /api/packager/acl/?packagername=<username>

    Accepts GET queries only.

    :arg packagername: String of the packager name.
    :kwarg acls: One or more ACL to filter the ACLs retrieved. Options are:
        ``approveacls``, ``commit``, ``watchbugzilla``, ``watchcommits``.
    :kwarg eol: a boolean to specify whether to include results for
        EOL collections or not. Defaults to False.
        If ``True``, it will return results for all collections (including
        EOL).
        If ``False``, it will return results only for non-EOL collections.
    :kwarg poc: a boolean specifying whether the results should be
        restricted to ACL for which the provided packager is the point
        of contact or not. Defaults to None.
        If ``True`` it will only return ACLs for packages on which the
        provided packager is point of contact.
        If ``False`` it will only return ACLs for packages on which the
        provided packager is not the point of contact.
        If ``None`` it will not filter the ACLs returned based on the point
        of contact of the package (thus every packages is returned).
    :kwarg page: The page number to return (useful in combination to limit).
    :kwarg limit: An integer to limit the number of results, defaults to
        250, maximum is 500 (acls).
    :kwarg count: A boolean to return the number of packages instead of the
        list. Defaults to False.

    *Results are paginated*

    Sample response:

    ::

        /api/packager/acl/pingou

        {
          "output": "ok",
          "page": 1,
          "page_total": 12
          "acls": [
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "critpath": False,
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchcommits"
            },
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "critpath": False,
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchbugzilla"
            }
          ]
        }

        /api/packager/acl/?packagername=random

        {
          "output": "notok",
          "error": "No ACL found for this user",
          "page": 1
        }

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername
    acls = flask.request.args.getlist('acls', None)
    eol = flask.request.args.get('eol', False)
    poc = flask.request.args.get('poc', None)
    if poc is not None:
        if poc in ['False', '0', 0]:
            poc = False
        poc = bool(poc)

    pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
    for acl in acls:
        if acl not in pkg_acl:
            output = {
                'output': 'notok',
                'error': 'Invalid request, "%s" is an invalid acl' % acl
            }
            httpcode = 500
            jsonout = flask.jsonify(output)
            jsonout.status_code = httpcode
            return jsonout

    page = flask.request.args.get('page', 1)
    limit = get_limit()
    count = flask.request.args.get('count', False)

    if packagername:
        packagers = pkgdblib.get_acl_packager(SESSION,
                                              packager=packagername,
                                              acls=acls,
                                              eol=eol,
                                              poc=poc,
                                              page=page,
                                              limit=limit,
                                              count=count)
        if packagers:
            output['output'] = 'ok'
            if count:
                output['acls_count'] = packagers
            else:
                tmp = []
                for pkg in packagers:
                    dic = pkg[0].to_json(pkglist=False)
                    dic['packagelist'] = pkg[1].to_json(acls=False)
                    tmp.append(dic)
                output['acls'] = tmp

            total_acl = pkgdblib.get_acl_packager(SESSION,
                                                  packager=packagername,
                                                  acls=acls,
                                                  eol=eol,
                                                  poc=poc,
                                                  count=True)

            if count:
                output['page_total'] = 1
            else:
                output['page_total'] = int(ceil(total_acl / float(limit)))
        else:
            output = {'output': 'notok', 'error': 'No ACL found for this user'}
            httpcode = 404
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    output['page'] = page
    if 'page_total' not in output:
        output['page_total'] = 1

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #2
0
def api_packager_acl(packagername=None):
    '''
User's ACL
----------
    List the ACLs of the user.

    ::

        /api/packager/acl/<fas_username>/

        /api/packager/acl/?packagername=<username>

    Accept GET queries only.

    :arg packagername: String of the packager name.
    :kwarg acls: One or more ACL to filter the ACLs retrieved. Options are:
        ``approveacls``, ``commit``, ``watchbugzilla``, ``watchcommits``.
    :kwarg eol: a boolean to specify whether to include results for
        EOL collections or not. Defaults to False.
        If ``True``, it will return results for all collections (including
        EOL).
        If ``False``, it will return results only for non-EOL collections.
    :kwarg poc: a boolean specifying whether the results should be
        restricted to ACL for which the provided packager is the point
        of contact or not. Defaults to None.
        If ``True`` it will only return ACLs for packages on which the
        provided packager is point of contact.
        If ``False`` it will only return ACLs for packages on which the
        provided packager is not the point of contact.
        If ``None`` it will not filter the ACLs returned based on the point
        of contact of the package (thus every packages is returned).
    :kwarg page: The page number to return (useful in combination to limit).
    :kwarg limit: An integer to limit the number of results, defaults to
        250, maximum is 500 (acls).
    :kwarg count: A boolean to return the number of packages instead of the
        list. Defaults to False.

    *Results are paginated*

    Sample response:

    ::

        /api/packager/acl/pingou

        {
          "output": "ok",
          "page": 1,
          "page_total": 12
          "acls": [
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "critpath": False,
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchcommits"
            },
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "critpath": False,
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchbugzilla"
            }
          ]
        }

        /api/packager/acl/?packagername=random

        {
          "output": "notok",
          "error": "No ACL found for this user",
          "page": 1
        }

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername
    acls = flask.request.args.getlist('acls', None)
    eol = flask.request.args.get('eol', False)
    poc = flask.request.args.get('poc', None)
    if poc is not None:
        if poc in ['False', '0', 0]:
            poc = False
        poc = bool(poc)

    pkg_acl = pkgdblib.get_status(SESSION, 'pkg_acl')['pkg_acl']
    for acl in acls:
        if acl not in pkg_acl:
            output = {
                'output': 'notok',
                'error': 'Invalid request, "%s" is an invalid acl' % acl}
            httpcode = 500
            jsonout = flask.jsonify(output)
            jsonout.status_code = httpcode
            return jsonout

    page = flask.request.args.get('page', 1)
    limit = get_limit()
    count = flask.request.args.get('count', False)

    if packagername:
        packagers = pkgdblib.get_acl_packager(
            SESSION,
            packager=packagername,
            acls=acls,
            eol=eol,
            poc=poc,
            page=page,
            limit=limit,
            count=count)
        if packagers:
            output['output'] = 'ok'
            if count:
                output['acls_count'] = packagers
            else:
                output['acls'] = [pkg.to_json() for pkg in packagers]

            total_acl = pkgdblib.get_acl_packager(
                SESSION,
                packager=packagername,
                acls=acls,
                eol=eol,
                poc=poc,
                count=True)

            if count:
                output['page_total'] = 1
            else:
                output['page_total'] = int(ceil(total_acl / float(limit)))
        else:
            output = {'output': 'notok', 'error': 'No ACL found for this user'}
            httpcode = 404
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    output['page'] = page
    if 'page_total' not in output:
        output['page_total'] = 1

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #3
0
def api_packager_acl(packagername=None):
    '''
User's ACL
----------
    List the ACLs of the user.

    ::

        /api/packager/acl/<fas_username>/

        /api/packager/acl/?packagername=<username>

    Accept GET queries only.

    :arg username: String of the packager name.
    :kwarg page: The page number to return (useful in combination to limit).
    :kwarg limit: An integer to limit the number of results, defaults to
        250 (acls).
    :kwarg count: A boolean to return the number of packages instead of the
        list. Defaults to False.

    Sample response:

    ::

        /api/packager/acl/pingou

        {
          "output": "ok",
          "page": 1,
          "page_total": 12
          "acls": [
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchcommits"
            },
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchbugzilla"
            }
          ]
        }

        /api/packager/acl/?packagername=random

        {
          "output": "notok",
          "error": "No ACL found for this user",
          "page": 1
        }

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername

    page = flask.request.args.get('page', 1)
    limit = flask.request.args.get('limit', 250)
    count = flask.request.args.get('count', False)

    if packagername:
        packagers = pkgdblib.get_acl_packager(SESSION,
                                              packager=packagername,
                                              page=page,
                                              limit=limit,
                                              count=count)
        if packagers:
            output['output'] = 'ok'
            output['acls'] = [pkg.to_json() for pkg in packagers]

            total_acl = pkgdblib.get_acl_packager(SESSION,
                                                  packager=packagername,
                                                  count=True)

            output['page_total'] = total_acl / limit
        else:
            output = {'output': 'notok', 'error': 'No ACL found for this user'}
            httpcode = 404
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    output['page'] = page

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout
예제 #4
0
def api_packager_acl(packagername=None):
    '''
User's ACL
----------
    List the ACLs of the user.

    ::

        /api/packager/acl/<fas_username>/

        /api/packager/acl/?packagername=<username>

    Accept GET queries only.

    :arg username: String of the packager name.
    :kwarg page: The page number to return (useful in combination to limit).
    :kwarg limit: An integer to limit the number of results, defaults to
        250 (acls).
    :kwarg count: A boolean to return the number of packages instead of the
        list. Defaults to False.

    Sample response:

    ::

        /api/packager/acl/pingou

        {
          "output": "ok",
          "page": 1,
          "page_total": 12
          "acls": [
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchcommits"
            },
            {
              "status": "Approved",
              "fas_name": "pingou",
              "packagelist": {
                "point_of_contact": "pingou",
                "collection": {
                  "status": "EOL",
                  "branchname": "f16",
                  "version": "16",
                  "name": "Fedora"
                },
                "package": {
                  "status": "Approved",
                  "upstream_url": null,
                  "description": null,
                  "summary": "Data of T- and B-cell Acute Lymphocytic "
                             "Leukemia",
                  "creation_date": 1384775354.0,
                  "review_url": null,
                  "name": "R-ALL"
                }
              },
              "acl": "watchbugzilla"
            }
          ]
        }

        /api/packager/acl/?packagername=random

        {
          "output": "notok",
          "error": "No ACL found for this user",
          "page": 1
        }

    '''
    httpcode = 200
    output = {}

    packagername = flask.request.args.get('packagername', None) or packagername

    page = flask.request.args.get('page', 1)
    limit = flask.request.args.get('limit', 250)
    count = flask.request.args.get('count', False)

    if packagername:
        packagers = pkgdblib.get_acl_packager(
            SESSION,
            packager=packagername,
            page=page,
            limit=limit,
            count=count)
        if packagers:
            output['output'] = 'ok'
            output['acls'] = [pkg.to_json() for pkg in packagers]

            total_acl = pkgdblib.get_acl_packager(
                SESSION,
                packager=packagername,
                count=True)

            output['page_total'] = total_acl / limit
        else:
            output = {'output': 'notok', 'error': 'No ACL found for this user'}
            httpcode = 404
    else:
        output = {'output': 'notok', 'error': 'Invalid request'}
        httpcode = 500

    output['page'] = page

    jsonout = flask.jsonify(output)
    jsonout.status_code = httpcode
    return jsonout