Files
notifications-admin/app/notify_client/api_key_api_client.py
T

31 lines
926 B
Python
Raw Normal View History

2018-02-20 11:22:17 +00:00
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
2016-01-20 17:32:55 +00:00
# must match key types in notifications-api/app/models.py
KEY_TYPE_NORMAL = 'normal'
KEY_TYPE_TEAM = 'team'
2016-07-06 15:10:36 +01:00
KEY_TYPE_TEST = 'test'
class ApiKeyApiClient(NotifyAdminAPIClient):
2016-01-20 17:32:55 +00:00
def get_api_keys(self, service_id):
return self.get(url='/service/{}/api-keys'.format(service_id))
2016-01-20 17:32:55 +00:00
2016-07-06 15:10:36 +01:00
def create_api_key(self, service_id, key_name, key_type):
data = {
'name': key_name,
2016-07-06 15:10:36 +01:00
'key_type': key_type
}
2016-08-11 14:20:43 +01:00
data = _attach_current_user(data)
2016-01-20 17:32:55 +00:00
key = self.post(url='/service/{}/api-key'.format(service_id), data=data)
return key['data']
def revoke_api_key(self, service_id, key_id):
2016-04-15 11:08:19 +01:00
data = _attach_current_user({})
return self.post(
url='/service/{0}/api-key/revoke/{1}'.format(service_id, key_id),
data=data)
2018-10-26 15:39:32 +01:00
api_key_api_client = ApiKeyApiClient()