def put_rule_checks(team_id, rule_id): """ .. :quickref: PUT; Lorem ipsum.""" if not TeamPermission.is_manager_or_editor(team_id): abort(403) payload = get_payload() rule = RuleController.update_checks(rule_id=rule_id, checks_id=payload["checks"]) return jsonify({"checks": [format_check(r) for r in rule["checks"]]}), 200
def post_source_variable(team_id, source_id): """ .. :quickref: POST; Lorem ipsum.""" if not TeamPermission.is_manager_or_editor(team_id): abort(403) payload = get_payload() payload.update({"team_id": team_id, "source_id": source_id}) variable = VariableController.create(payload) return jsonify(format_variable(variable)), 200
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
def execute_rule(team_id, rule_id): """ .. :quickref: POST; Lorem ipsum.""" if not TeamPermission.is_user(team_id): abort(403) payload = get_payload() # Does the team owns the rule RuleController.get({"Rule": {"id": rule_id, "team_id": team_id}}) result = RuleController.execute(rule_id, **payload) return jsonify({"result": result}), 200
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
def put_source(team_id, source_id): """Edit an existing source. .. :quickref: PUT; Edit an existing source. **Example request**: .. sourcecode:: http PUT /v1/teams/66859c4a-3e0a-4968-a5a4-4c3b8662acb7/sources/e2c1c635-2d7c-4881-83d1-e4e7027ac7a2 HTTP/1.1 Host: example.com Accept: application/json { "name": "My edited source" } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK { "checks": [], "configuration": {}, "createdAt": "2019-01-21T14:08:22Z", "id": "e2c1c635-2d7c-4881-83d1-e4e7027ac7a2", "name": "My edited source", "plugin": "Fake", "updatedAt": "2019-01-21T14:21:24Z" } :resheader Content-Type: application/json :status 200: the edited source """ if not TeamPermission.is_manager(team_id): abort(403) payload = get_payload() source = SourceController.update( payload, {"Source": { "id": source_id, "team_id": team_id }}) return jsonify(format_source(source, True)), 200
def post_source(team_id): """Add a new source. .. :quickref: POST; Add a new source. **Example request**: .. sourcecode:: http POST /v1/teams/66859c4a-3e0a-4968-a5a4-4c3b8662acb7/sources HTTP/1.1 Host: example.com Accept: application/json { "name": "My source", "plugin": "Fake", "configuration": {} } **Example response**: .. sourcecode:: http HTTP/1.1 201 CREATED { "checks": [], "configuration": {}, "createdAt": "2019-01-21T14:08:22Z", "id": "e2c1c635-2d7c-4881-83d1-e4e7027ac7a2", "name": "My source", "plugin": "Fake", "updatedAt": "2019-01-21T14:08:22Z" } :resheader Content-Type: application/json :status 201: the created source """ if not TeamPermission.is_manager(team_id): abort(403) payload = get_payload() payload["team_id"] = team_id source = SourceController.create(payload) return jsonify(format_source(source, True)), 201
def put_rule(team_id, rule_id): """Edit an existing rule. .. :quickref: PUT; Edit an existing rule. **Example request**: .. sourcecode:: http PUT /v1/teams/66859c4a-3e0a-4968-a5a4-4c3b8662acb7/rules/ff130e9b-d226-4465-9612-a93e12799091 HTTP/1.1 Host: example.com Accept: application/json { "name": "My edited rule" } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK { "checks": [], "createdAt": "2018-05-17T12:01:09Z", "description": "Compute the QOS of our servers", "id": "ff130e9b-d226-4465-9612-a93e12799091", "name": "My edited rule", "updatedAt": "2018-11-09T15:33:06Z" } :resheader Content-Type: application/json :status 200: the edited rule """ if not TeamPermission.is_manager_or_editor(team_id): abort(403) payload = get_payload() rule = RuleController.update(payload, {"Rule": { "id": rule_id, "team_id": team_id }}) return jsonify(format_rule(rule)), 200
def put_grants(team_id): """Change the grants of a team. .. :quickref: PUT; Change the grants of a team. **Example request**: .. sourcecode:: http PUT /teams/76b96ead-a7ed-447b-8fa6-26b57bc571e5/grants HTTP/1.1 Host: example.com Accept: application/json { 'grants': [{ 'user': '******', 'role': 'member' }] } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK [ { 'role': 'member', 'user': '******' } ] :resheader Content-Type: application/json :status 200: the grants """ if not TeamPermission.is_manager(team_id): abort(403) payload = get_payload() grants = TeamController.put_grants(team_id=team_id, grants=payload["grants"]) return jsonify(grants)
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
def put_check_variable(team_id, source_id, check_id, variable_id): """ .. :quickref: PUT; Lorem ipsum.""" if not TeamPermission.is_manager_or_editor(team_id): abort(403) payload = get_payload() variable = VariableController.update( payload, { "Variable": { "id": variable_id, "team_id": team_id, "rule_id": None, "source_id": source_id, "check_id": check_id, } }, ) return jsonify(format_variable(variable)), 200