コード例 #1
0
ファイル: api.py プロジェクト: rapid7/lecli
def add_log(logset_id, log_id):
    """
    Add a log to the logset
    """
    params = {
        "logset":{
            "logs_info": [{
                "id": str(log_id)
            }]
        }
    }
    headers = api_utils.generate_headers('ro')

    try:
        response = requests.get(_url((logset_id,))[1], headers=headers)
        if response_utils.response_error(response):
            sys.stderr.write('Add log %s to logset %s failed\n'
                             % (log_id, logset_id))
            sys.exit(1)
        elif response.status_code == 200:
            existing_logset = response.json()
            replace_logset(logset_id, api_utils.combine_objects(existing_logset, params))
    except requests.exceptions.RequestException as error:
        sys.stderr.write(error)
        sys.exit(1)
コード例 #2
0
def update_log(log_id, params):
    """
    Update a log with the details provided
    """
    url = "/".join([_url(), log_id])
    headers = api_utils.generate_headers('ro')

    if check_logset_exists(params):
        try:
            response = requests.get(url, headers=headers)
            existing_log = response.json()
            replace_log(log_id, api_utils.combine_objects(existing_log, params))
        except requests.exceptions.RequestException as error:
            sys.stderr.write(error)
            sys.exit(1)
    else:
        sys.stderr.write("One or more of the specified logsets does not exist.\n")
コード例 #3
0
def test_combine_objects():
    left = {
        "log": {
            "id": "21dd21e7-708a-4bc4-bf45-ffbc78190ecd",
            "logsets_info": [],
            "name": "test_log_old",
            "structures": [],
            "tokens": [],
            "user_data": {}
        }
    }

    right = {
        "log": {
            "name":
            "test_log_new",
            "structures": [],
            "tokens": [],
            "user_data": {},
            "logsets_info": [{
                "id": "e227f890-7742-47b4-86b2-5ff1d345397e",
                "name": "test_logset"
            }]
        }
    }

    expected_result = {
        "log": {
            "id":
            "21dd21e7-708a-4bc4-bf45-ffbc78190ecd",
            "logsets_info": [{
                "id": "e227f890-7742-47b4-86b2-5ff1d345397e",
                "name": "test_logset"
            }],
            "name":
            "test_log_new",
            "structures": [],
            "tokens": [],
            "user_data": {}
        }
    }

    result = api_utils.combine_objects(left, right)

    assert result == expected_result
コード例 #4
0
ファイル: test_apiutils.py プロジェクト: rapid7/lecli
def test_combine_objects():
    left = {
        "log": {
            "id": "21dd21e7-708a-4bc4-bf45-ffbc78190ecd",
            "logsets_info": [],
            "name": "test_log_old",
            "structures": [],
            "tokens": [],
            "user_data": {}
        }
    }

    right = {
        "log": {
            "name": "test_log_new",
            "structures": [],
            "tokens": [],
            "user_data": {},
            "logsets_info": [{
                "id": "e227f890-7742-47b4-86b2-5ff1d345397e",
                "name": "test_logset"
            }]
        }
    }

    expected_result = {
        "log": {
            "id": "21dd21e7-708a-4bc4-bf45-ffbc78190ecd",
            "logsets_info": [{
                "id": "e227f890-7742-47b4-86b2-5ff1d345397e",
                "name": "test_logset"
            }],
            "name": "test_log_new",
            "structures": [],
            "tokens": [],
            "user_data": {}
        }
    }

    result = api_utils.combine_objects(left, right)

    assert result == expected_result
コード例 #5
0
ファイル: api.py プロジェクト: qboriskr/lecli
def add_log(logset_id, log_id):
    """
    Add a log to the logset
    """
    params = {"logset": {"logs_info": [{"id": str(log_id)}]}}
    headers = api_utils.generate_headers('ro')

    try:
        response = requests.get(_url((logset_id, ))[1], headers=headers)
        if response_utils.response_error(response):
            sys.stderr.write('Add log %s to logset %s failed\n' %
                             (log_id, logset_id))
            sys.exit(1)
        elif response.status_code == 200:
            existing_logset = response.json()
            replace_logset(logset_id,
                           api_utils.combine_objects(existing_logset, params))
    except requests.exceptions.RequestException as error:
        sys.stderr.write(error)
        sys.exit(1)