rework superuser api
This commit is contained in:
parent
4079dba167
commit
35ed73e195
4 changed files with 205 additions and 60 deletions
|
@ -22,7 +22,29 @@ def _gc_expired(service):
|
|||
|
||||
# TODO ACTION_LOGS for keys
|
||||
|
||||
def upsert_service_key(name, kid, service, jwk, metadata, expiration_date):
|
||||
|
||||
def create_service_key(name, kid, service, jwk, metadata, expiration_date):
|
||||
_gc_expired(service)
|
||||
|
||||
sk = ServiceKey.create(name=name, kid=kid, service=service, jwk=jwk, metadata=metadata,
|
||||
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,
|
||||
})
|
||||
|
||||
|
||||
def update_service_key(name, kid, metadata, expiration_date):
|
||||
_gc_expired(service)
|
||||
|
||||
try:
|
||||
|
@ -33,29 +55,23 @@ def upsert_service_key(name, kid, service, jwk, metadata, expiration_date):
|
|||
key.expiration_date = expiration_date
|
||||
key.save()
|
||||
except ServiceKey.DoesNotExist:
|
||||
sk = ServiceKey.create(name=name, kid=kid, service=service, jwk=jwk, metadata=metadata,
|
||||
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
|
||||
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,
|
||||
})
|
||||
raise ServiceKeyDoesNotExist
|
||||
|
||||
|
||||
def get_service_keys(service, kid=None):
|
||||
def get_service_keys(approved_only, kid=None, service=None):
|
||||
_gc_expired(service)
|
||||
|
||||
query = ServiceKey.select().where(ServiceKey.service == service,
|
||||
~(ServiceKey.approval >> None))
|
||||
if kid:
|
||||
query = ServiceKey.select()
|
||||
|
||||
if service is not None:
|
||||
query = query.where(ServiceKey.service == service)
|
||||
|
||||
if kid is not None:
|
||||
query.where(ServiceKey.kid == kid)
|
||||
|
||||
if approved_only:
|
||||
query = query.where(~(ServiceKey.approval >> None))
|
||||
|
||||
return query
|
||||
|
||||
|
||||
|
@ -69,11 +85,10 @@ def delete_service_key(service, kid):
|
|||
raise ServiceKeyDoesNotExist()
|
||||
|
||||
|
||||
def approve_service_key(service, kid, approver, approval_type):
|
||||
def approve_service_key(kid, approver, approval_type):
|
||||
try:
|
||||
with db_transaction():
|
||||
key = db_for_update(ServiceKey.select().where(ServiceKey.service == service,
|
||||
ServiceKey.kid == kid)).get()
|
||||
key = db_for_update(ServiceKey.select().where(ServiceKey.kid == kid)).get()
|
||||
if key.approval is not None:
|
||||
raise ServiceKeyAlreadyApproved
|
||||
|
||||
|
|
Reference in a new issue