add notification path and use for service keys
This commit is contained in:
parent
97ae800e6c
commit
42b5196b21
4 changed files with 39 additions and 18 deletions
|
@ -3,8 +3,7 @@ from datetime import datetime, timedelta
|
|||
from app import app
|
||||
from data.database import db_for_update, User, ServiceKey, ServiceKeyApproval
|
||||
from data.model import ServiceKeyDoesNotExist, ServiceKeyAlreadyApproved, db_transaction
|
||||
from data.model.notification import create_notification
|
||||
|
||||
from data.model.notification import create_notification, delete_all_notifications_by_path_prefix
|
||||
|
||||
# TODO ACTION_LOGS for keys
|
||||
UNAPPROVED_TTL = timedelta(seconds=app.config['UNAPPROVED_SERVICE_KEY_TTL_SEC'])
|
||||
|
@ -30,19 +29,22 @@ def create_service_key(name, kid, service, jwk, metadata, expiration_date):
|
|||
sk = ServiceKey.create(name=name, kid=kid, service=service, jwk=jwk, metadata=metadata,
|
||||
expiration_date=expiration_date)
|
||||
|
||||
notification_metadata = {
|
||||
'name': name,
|
||||
'kid': kid,
|
||||
'service': service,
|
||||
'jwk': jwk,
|
||||
'metadata': metadata,
|
||||
'created_date': sk.created_date,
|
||||
'expiration_date': expiration_date,
|
||||
}
|
||||
|
||||
superusers = User.select().where(User.username << app.config['SUPER_USERS'])
|
||||
for superuser in superusers:
|
||||
# TODO(jzelinskie): create notification type in the database migration
|
||||
# I already put it in initdb
|
||||
create_notification('service_key_submitted', superuser, {
|
||||
'name': name,
|
||||
'kid': kid,
|
||||
'service': service,
|
||||
'jwk': jwk,
|
||||
'metadata': metadata,
|
||||
'created_date': sk.created_date,
|
||||
'expiration_date': expiration_date,
|
||||
})
|
||||
create_notification('service_key_submitted', superuser, metadata=notification_metadata,
|
||||
lookup_path='/service_key_approval/{0}'.format(kid))
|
||||
|
||||
_gc_expired(service)
|
||||
|
||||
|
@ -98,6 +100,9 @@ def approve_service_key(kid, approver, approval_type):
|
|||
except ServiceKey.DoesNotExist:
|
||||
raise ServiceKeyDoesNotExist
|
||||
|
||||
delete_all_notifications_by_path_prefix('/service_key_approval/{0}'.format(kid))
|
||||
_gc_expired(key.service)
|
||||
|
||||
|
||||
def _get_service_keys_query(kid=None, service=None, approved_only=False):
|
||||
query = ServiceKey.select()
|
||||
|
|
Reference in a new issue