mirror of https://github.com/MISP/PyMISP
new: get_new_authkey for a user
parent
9ee4f4715c
commit
24e79c8340
|
@ -2192,6 +2192,19 @@ class PyMISP:
|
||||||
usersettings.append(us)
|
usersettings.append(us)
|
||||||
return u, role, usersettings
|
return u, role, usersettings
|
||||||
|
|
||||||
|
def get_new_authkey(self, user: Union[MISPUser, int, str, UUID] = 'me') -> str:
|
||||||
|
'''Get a new authorization key for a specific user, defaults to user doing the call.
|
||||||
|
|
||||||
|
:param user: The owner of the key
|
||||||
|
'''
|
||||||
|
data = {"user_id": get_uuid_or_id_from_abstract_misp(user)}
|
||||||
|
r = self._prepare_request('POST', '/auth_keys/add', data=data)
|
||||||
|
authkey = self._check_json_response(r)
|
||||||
|
if 'AuthKey' in authkey and 'authkey_raw' in authkey['AuthKey']:
|
||||||
|
return authkey['AuthKey']['authkey_raw']
|
||||||
|
else:
|
||||||
|
raise PyMISPUnexpectedResponse(f'Unable to get authkey: {authkey}')
|
||||||
|
|
||||||
def add_user(self, user: MISPUser, pythonify: bool = False) -> Union[Dict, MISPUser]:
|
def add_user(self, user: MISPUser, pythonify: bool = False) -> Union[Dict, MISPUser]:
|
||||||
"""Add a new user
|
"""Add a new user
|
||||||
|
|
||||||
|
|
|
@ -1753,6 +1753,9 @@ class TestComprehensive(unittest.TestCase):
|
||||||
user.email = 'foo@bar.de'
|
user.email = 'foo@bar.de'
|
||||||
user = self.admin_misp_connector.update_user(user, pythonify=True)
|
user = self.admin_misp_connector.update_user(user, pythonify=True)
|
||||||
self.assertEqual(user.email, 'foo@bar.de')
|
self.assertEqual(user.email, 'foo@bar.de')
|
||||||
|
# get API key
|
||||||
|
key = self.user_misp_connector.get_new_authkey()
|
||||||
|
self.assertTrue(isinstance(key, str))
|
||||||
|
|
||||||
def test_organisation(self):
|
def test_organisation(self):
|
||||||
# Get list
|
# Get list
|
||||||
|
|
Loading…
Reference in New Issue