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
|
|
|
|
2016-06-27 12:02:16 +01: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'
|
2016-06-27 12:02:16 +01:00
|
|
|
|
|
|
|
|
|
2016-11-30 17:01:44 +00:00
|
|
|
class ApiKeyApiClient(NotifyAdminAPIClient):
|
2016-01-20 17:32:55 +00:00
|
|
|
|
2018-11-07 11:53:29 +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):
|
2016-06-27 12:02:16 +01:00
|
|
|
data = {
|
|
|
|
|
'name': key_name,
|
2016-07-06 15:10:36 +01:00
|
|
|
'key_type': key_type
|
2016-06-27 12:02:16 +01:00
|
|
|
}
|
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']
|
|
|
|
|
|
2016-06-27 12:02:16 +01:00
|
|
|
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()
|