This commit is contained in:
Joseph Schorr 2017-07-12 16:37:51 +03:00
parent 932db23a5c
commit 4ed73d247b
4 changed files with 9 additions and 4 deletions

View file

@ -1,6 +1,7 @@
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from six import add_metaclass from six import add_metaclass
@add_metaclass(ABCMeta) @add_metaclass(ABCMeta)
class ServiceKeyWorkerDataInterface(object): class ServiceKeyWorkerDataInterface(object):
""" """

View file

@ -1,6 +1,7 @@
from data import model from data import model
from workers.servicekeyworker.models_interface import ServiceKeyWorkerDataInterface from workers.servicekeyworker.models_interface import ServiceKeyWorkerDataInterface
class PreOCIModel(ServiceKeyWorkerDataInterface): class PreOCIModel(ServiceKeyWorkerDataInterface):
def set_key_expiration(self, kid, expiration_date): def set_key_expiration(self, kid, expiration_date):
model.service_keys.set_key_expiration(kid, expiration_date) model.service_keys.set_key_expiration(kid, expiration_date)
@ -16,4 +17,5 @@ class PreOCIModel(ServiceKeyWorkerDataInterface):
except model.ServiceKeyDoesNotExist: except model.ServiceKeyDoesNotExist:
return None return None
pre_oci_model = PreOCIModel() pre_oci_model = PreOCIModel()

View file

@ -7,6 +7,7 @@ from workers.worker import Worker
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class ServiceKeyWorker(Worker): class ServiceKeyWorker(Worker):
def __init__(self): def __init__(self):
super(ServiceKeyWorker, self).__init__() super(ServiceKeyWorker, self).__init__()
@ -22,6 +23,7 @@ class ServiceKeyWorker(Worker):
model.set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration) model.set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration)
logger.debug('Finished refresh of automatic service keys') logger.debug('Finished refresh of automatic service keys')
if __name__ == "__main__": if __name__ == "__main__":
worker = ServiceKeyWorker() worker = ServiceKeyWorker()
worker.start() worker.start()

View file

@ -13,7 +13,7 @@ def test_refresh_service_key(initialized_db):
original_expiration = datetime.now() + timedelta(minutes=10) original_expiration = datetime.now() + timedelta(minutes=10)
test_key_kid = model.create_service_key_for_testing(original_expiration) test_key_kid = model.create_service_key_for_testing(original_expiration)
instance_keys = AttrDict(dict(local_key_id=test_key_kid, service_key_expiration=10)) instance_keys = AttrDict(dict(local_key_id=test_key_kid, service_key_expiration=30))
with patch('workers.servicekeyworker.servicekeyworker.instance_keys', instance_keys): with patch('workers.servicekeyworker.servicekeyworker.instance_keys', instance_keys):
worker = ServiceKeyWorker() worker = ServiceKeyWorker()
worker._refresh_service_key() worker._refresh_service_key()