예제 #1
0
def _url(endpoint):
    """
    Get rest query url of account resource id.
    """
    if endpoint == 'owner':
        return 'https://rest.logentries.com/management/accounts/' + str(
            apiutils.get_account_resource_id()) + '/owners'
    elif endpoint == 'user':
        return 'https://rest.logentries.com/management/accounts/' + str(
            apiutils.get_account_resource_id()) + '/users'
예제 #2
0
def _url(endpoint):
    """
    Get rest query url of account resource id.
    """
    if endpoint == 'owner':
        return 'https://rest.logentries.com/management/accounts/' + str(
            apiutils.get_account_resource_id()) + '/owners'
    elif endpoint == 'user':
        return 'https://rest.logentries.com/management/accounts/' + str(
            apiutils.get_account_resource_id()) + '/users'
예제 #3
0
def test_get_valid_account_resource_id():
    with patch.object(ConfigParser.ConfigParser,
                      'get',
                      return_value=misc_ex.TEST_APIKEY_WITH_VALID_LENGTH):
        account_resource_id = apiutils.get_account_resource_id()

        assert account_resource_id == misc_ex.TEST_APIKEY_WITH_VALID_LENGTH
예제 #4
0
def add_new_user(first_name, last_name, email):
    """
    Add a new user to the current account.
    """
    action = 'management/accounts/' + str(
        apiutils.get_account_resource_id()) + '/users'
    json_content = {
        "user": {
            "email": str(email),
            "first_name": str(first_name),
            "last_name": str(last_name)
        }
    }
    body = json.dumps(json_content)
    headers = apiutils.generate_headers('owner',
                                        method='POST',
                                        action=action,
                                        body=body)

    try:
        response = requests.request('POST',
                                    _url('user'),
                                    json=json_content,
                                    headers=headers)
        handle_create_user_response(response)
    except requests.exceptions.RequestException as error:
        print error
        exit(1)
예제 #5
0
def test_get_invalid_account_resource_id(capsys):
    with patch.object(ConfigParser.ConfigParser, 'get',
                      return_value=misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH):
        account_resource_id = apiutils.get_account_resource_id()
        out, err = capsys.readouterr()

        assert account_resource_id == misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH
        assert 'Error: Account Resource ID not of correct length\n' == out
예제 #6
0
def test_get_invalid_account_resource_id(capsys):
    with patch.object(ConfigParser.ConfigParser,
                      'get',
                      return_value=misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH):
        account_resource_id = apiutils.get_account_resource_id()
        out, err = capsys.readouterr()

        assert account_resource_id == misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH
        assert 'Error: Account Resource ID not of correct length\n' == out
예제 #7
0
def test_get_invalid_account_resource_id(capsys):
    with patch.object(ConfigParser.ConfigParser,
                      'get',
                      return_value=misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH):
        with pytest.raises(SystemExit):
            result = apiutils.get_account_resource_id()
            out, err = capsys.readouterr()

            assert result is None
            assert misc_ex.TEST_APIKEY_WITH_INVALID_LENGTH in out
            assert 'is not of correct length' in out
예제 #8
0
def list_users():
    """
    List users that is in the current account.
    """
    action = 'management/accounts/' + str(apiutils.get_account_resource_id()) + '/users'
    try:
        response = requests.request('GET', _url('user'), headers=apiutils.generate_headers(
            'owner', 'GET', action, ''))
        handle_userlist_response(response)
    except requests.exceptions.RequestException as error:
        print error
        exit(1)
예제 #9
0
def list_users():
    """
    List users that is in the current account.
    """
    action = 'management/accounts/' + str(
        apiutils.get_account_resource_id()) + '/users'
    try:
        response = requests.request('GET',
                                    _url('user'),
                                    headers=apiutils.generate_headers(
                                        'owner', 'GET', action, ''))
        handle_userlist_response(response)
    except requests.exceptions.RequestException as error:
        print error
        exit(1)
예제 #10
0
파일: userapi.py 프로젝트: scawley-r7/lecli
def add_new_user(first_name, last_name, email):
    """
    Add a new user to the current account.
    """
    action = 'management/accounts/' + str(apiutils.get_account_resource_id()) + '/users'
    body = {
        "email": str(email),
        "first_name": str(first_name),
        "last_name": str(last_name)
    }
    body = json.dumps(body, separators=(',', ':'))
    headers = apiutils.generate_headers('owner', method='POST', action=action, body=body)

    try:
        response = requests.request('POST', _url('user'), data=body, headers=headers)
        handle_create_user_response(response)
    except requests.exceptions.RequestException as error:
        print error
        exit(1)
예제 #11
0
def test_get_valid_account_resource_id():
    with patch.object(ConfigParser.ConfigParser, 'get',
                      return_value=misc_ex.TEST_APIKEY_WITH_VALID_LENGTH):
        account_resource_id = apiutils.get_account_resource_id()

        assert account_resource_id == misc_ex.TEST_APIKEY_WITH_VALID_LENGTH
예제 #12
0
def _url():
    """
    Get rest query url of account resource id.
    """
    return 'https://rest.logentries.com/management/accounts/%s/teams' % \
           apiutils.get_account_resource_id()
예제 #13
0
def _url():
    """
    Get rest query url of account resource id.
    """
    return 'https://rest.logentries.com/management/accounts/%s' + \
           apiutils.get_account_resource_id() + '/teams'