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

38 lines
1.3 KiB
Python
Raw Normal View History

from app.notify_client import _attach_current_user, NotifyAdminAPIClient
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):
def __init__(self):
2016-09-12 14:59:53 +01:00
super().__init__("a", "b", "c")
2016-01-20 17:32:55 +00:00
def init_app(self, app):
self.base_url = app.config['API_HOST_NAME']
2016-09-08 15:55:07 +01:00
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
self.api_key = app.config['ADMIN_CLIENT_SECRET']
2016-01-20 17:32:55 +00:00
def get_api_keys(self, service_id, key_id=None):
2016-01-21 12:28:05 +00:00
if key_id:
return self.get(url='/service/{}/api-keys/{}'.format(service_id, key_id))
else:
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)