예제 #1
0
파일: rules.py 프로젝트: dingcycle/depc
    def before_data_load(cls, data):
        """Ensure that all checks exist."""
        if "checks" in data:
            for check_id in data["checks"]:
                try:
                    CheckController.get(filters={"Check": {"id": check_id}})
                except NotFoundError:
                    raise NotFoundError("Check {} not found".format(check_id))

            # Transform ID into objects
            data["checks"] = CheckController._list({"Check": {"id": data["checks"]}})
예제 #2
0
파일: checks.py 프로젝트: dingcycle/depc
def list_team_checks(team_id):
    """List the checks of a team.

    .. :quickref: GET; List the checks of a team.

    **Example request**:

    .. sourcecode:: http

      GET /teams/66859c4a-3e0a-4968-a5a4-4c3b8662acb7/checks HTTP/1.1
      Host: example.com
      Accept: application/json

    **Example response**:

    .. sourcecode:: http

      HTTP/1.1 200 OK

        {
          'checks': [{
            'name': 'My check',
            'parameters': {'metric': 'foo', 'threshold': 100},
            'type': 'Threshold'
          }]
        }

    :resheader Content-Type: application/json
    :status 200: the list of checks
    """
    if not TeamPermission.is_user(team_id):
        abort(403)

    checks = CheckController.list_team_checks(team_id)
    return jsonify({"checks": [format_check(c) for c in checks]}), 200
예제 #3
0
 def _create_check(name, source_id, type='Threshold', parameters={}):
     with app.app_context():
         return CheckController.create({
             'source_id': source_id,
             'name': name,
             'type': type,
             'parameters': parameters
         })
예제 #4
0
파일: checks.py 프로젝트: dingcycle/depc
def delete_source_check(team_id, source_id, check_id):
    """

    .. :quickref: DELETE; Lorem ipsum."""
    if not TeamPermission.is_manager_or_editor(team_id):
        abort(403)

    check = CheckController.delete(
        filters={"Check": {"id": check_id, "source_id": source_id}}
    )
    return jsonify(format_check(check)), 200
예제 #5
0
파일: checks.py 프로젝트: dingcycle/depc
def put_source_check(team_id, source_id, check_id):
    """

    .. :quickref: PUT; Lorem ipsum."""
    if not TeamPermission.is_manager_or_editor(team_id):
        abort(403)

    payload = get_payload()
    check = CheckController.update(
        payload, {"Check": {"id": check_id, "source_id": source_id}}
    )
    return jsonify(format_check(check)), 200
예제 #6
0
파일: rules.py 프로젝트: dingcycle/depc
    def update_checks(cls, rule_id, checks_id):
        rule = cls._get(filters={"Rule": {"id": rule_id}})

        checks = []
        for check_id in checks_id:
            check = CheckController._get(filters={"Check": {"id": check_id}})
            checks.append(check)

        rule.checks = checks
        db.session.commit()

        return cls.resource_to_dict(rule)
예제 #7
0
파일: checks.py 프로젝트: dingcycle/depc
def post_source_check(team_id, source_id):
    """Add a new check.

    .. :quickref: POST; Add a new check.

    **Example request**:

    .. sourcecode:: http

      POST /v1/teams/66859c4a-3e0a-4968-a5a4-4c3b8662acb7/sources/e2c1c635-2d7c-4881-83d1-e4e7027ac7a2/checks HTTP/1.1
      Host: example.com
      Accept: application/json

      {
        "name": "My check",
        "type": "Threshold",
        "parameters": {
          "metric": "foo",
          "threshold": 100
        }
      }

    **Example response**:

    .. sourcecode:: http

      HTTP/1.1 201 CREATED

      {
        'name': 'My check',
        'parameters': {
          'metric': 'foo',
          'threshold': 100
        },
        'type': 'Threshold'
      }

    :resheader Content-Type: application/json
    :status 201: the created check
    """
    if not TeamPermission.is_manager_or_editor(team_id):
        abort(403)

    payload = get_payload()
    payload["source_id"] = source_id

    source = CheckController.create(payload)
    return jsonify(format_check(source)), 201
예제 #8
0
파일: rules.py 프로젝트: dingcycle/depc
 def resource_to_dict(cls, obj, blacklist=False):
     d = super().resource_to_dict(obj, blacklist=False)
     d["checks"] = [CheckController.resource_to_dict(c) for c in obj.checks]
     return d