Exemple #1
0
def update_vulnerability(vuln_id):
    """Update vulnerability details

    **Example request**:

    .. sourcecode:: http

        PUT /api/1.0/vulnerabilities/1 HTTP/1.1
        Host: do.cert.europa.eu
        Accept: application/json
        Content-Type: application/json

        {
          "reporter_name": "Test updated"
        }

    **Example response**:

    .. sourcecode:: http

        HTTP/1.0 200 OK
        Content-Type: application/json

        {
          "message": "Vulnerability saved"
        }

    **Example validation error**:

    .. sourcecode:: http

        HTTP/1.0 422 UNPROCESSABLE ENTITY
        Content-Type: application/json

        {
          "message": "'reporter_name' is a required property",
          "validator": "required"
        }

    :param vuln_id: Vulnerability unique ID

    :reqheader Accept: Content type(s) accepted by the client
    :resheader Content-Type: this depends on `Accept` header or request

    :<json string url: Vulnerable URL
    :<json string check_string: Vulnerability check
    :<json string organization_id: Organization unique ID.
        Get unique IDs from :http:get:`/api/1.0/organizations`.
    :<json string reported: Report date
    :<json string request_method: ``GET``, ``POST`` or ``PUT``.
        Defaults to ``GET``.
    :<json string rtir_id: RTIR investigation ID
    :<json array types: One or more vulnerability types

    :>json string message: Status message

    :status 200: Vulnerability was successfully added
    :status 422: Request could not be processed
    """
    vuln = Vulnerability.get(vuln_id)
    if not vuln:
        return redirect(url_for('api.add_vulnerability'))

    list_types = []
    if 'types' in request.json:
        json_types = request.json.pop('types')
        for vtype in json_types:
            if Tag.query.filter_by(name=vtype).first():
                list_types.append(Tag.query.filter_by(name=vtype).first())
            else:
                list_types.append(Tag(name=vtype))

    vuln.from_json(request.json)
    vuln.labels_ = list_types
    db.session.add(vuln)
    db.session.commit()
    return ApiResponse({'message': 'Vulnerability saved'})