Exemplo n.º 1
0
 def _create_rule(name, team_id, description=None):
     with app.app_context():
         return RuleController.create({
             'team_id': team_id,
             'name': name,
             'description': description
         })
Exemplo n.º 2
0
def post_rule(team_id):
    """Add a new rule.

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

    **Example request**:

    .. sourcecode:: http

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

      {
        "name": "Servers",
        "description": "Compute the QOS of our servers"
      }

    **Example response**:

    .. sourcecode:: http

      HTTP/1.1 201 CREATED

      {
        "checks": [],
        "createdAt": "2018-05-17T12:01:09Z",
        "description": "Compute the QOS of our servers",
        "id": "ff130e9b-d226-4465-9612-a93e12799091",
        "name": "Servers",
        "updatedAt": "2018-11-09T15:33:06Z"
      }

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

    payload = get_payload()
    payload["team_id"] = team_id
    rule = RuleController.create(payload)
    return jsonify(format_rule(rule)), 201