Only refresh current instance service key

This commit is contained in:
Evan Cordell 2016-04-29 11:20:30 -05:00 committed by Jimmy Zelinskie
parent a6f6a114c2
commit 489752a0b7
3 changed files with 14 additions and 19 deletions

View file

@ -7,7 +7,7 @@ from peewee import JOIN_LEFT_OUTER
from Crypto.PublicKey import RSA
from jwkest.jwk import RSAKey
from data.database import db_for_update, User, ServiceKey, ServiceKeyApproval, ServiceKeyApprovalType
from data.database import db_for_update, User, ServiceKey, ServiceKeyApproval
from data.model import (ServiceKeyDoesNotExist, ServiceKeyAlreadyApproved, ServiceNameInvalid,
db_transaction, config)
from data.model.notification import create_notification, delete_all_notifications_by_path_prefix
@ -29,6 +29,7 @@ def _stale_expired_keys_clause():
expired_ttl = timedelta(seconds=config.app_config['EXPIRED_SERVICE_KEY_TTL_SEC'])
return (ServiceKey.expiration_date <= (datetime.utcnow() - expired_ttl))
def _stale_unapproved_keys_clause(service):
unapproved_ttl = timedelta(seconds=config.app_config['UNAPPROVED_SERVICE_KEY_TTL_SEC'])
return ((ServiceKey.service == service) &
@ -36,10 +37,6 @@ def _stale_unapproved_keys_clause(service):
(ServiceKey.created_date <= (datetime.utcnow() - unapproved_ttl)))
def _unexpired_clause():
return ServiceKey.expiration_date >= datetime.utcnow()
def _gc_expired(service):
ServiceKey.delete().where(_stale_expired_keys_service_clause(service) |
_stale_unapproved_keys_clause(service)).execute()
@ -147,16 +144,6 @@ def set_key_expiration(kid, expiration_date):
service_key.save()
def refresh_automatic_service_keys(extension):
"""
Finds all unexpired automatic keys and sets their
expiration to `now + extension`
"""
for service_key in list(_list_service_keys_query(approval_type=ServiceKeyApprovalType.AUTOMATIC).where(_unexpired_clause())):
service_key.expiration_date = datetime.now() + extension
service_key.save()
def approve_service_key(kid, approver, approval_type, notes=''):
try:
with db_transaction():