コード例 #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
ファイル: user_api.py プロジェクト: StephenHynes7/lecli
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
ファイル: test_apiutils.py プロジェクト: stopal-r7/lecli
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
ファイル: user_api.py プロジェクト: StephenHynes7/lecli
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
ファイル: test_apiutils.py プロジェクト: stopal-r7/lecli
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
ファイル: team_api.py プロジェクト: StephenHynes7/lecli
def _url():
    """
    Get rest query url of account resource id.
    """
    return 'https://rest.logentries.com/management/accounts/%s' + \
           apiutils.get_account_resource_id() + '/teams'