yapf
This commit is contained in:
parent
932db23a5c
commit
4ed73d247b
4 changed files with 9 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from six import add_metaclass
|
||||
|
||||
|
||||
@add_metaclass(ABCMeta)
|
||||
class ServiceKeyWorkerDataInterface(object):
|
||||
"""
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
from data import model
|
||||
from workers.servicekeyworker.models_interface import ServiceKeyWorkerDataInterface
|
||||
|
||||
|
||||
class PreOCIModel(ServiceKeyWorkerDataInterface):
|
||||
def set_key_expiration(self, kid, expiration_date):
|
||||
model.service_keys.set_key_expiration(kid, expiration_date)
|
||||
|
||||
def create_service_key_for_testing(self, expiration):
|
||||
key = model.service_keys.create_service_key('test', 'somekid', 'quay', '', {}, expiration)
|
||||
return key.kid
|
||||
key = model.service_keys.create_service_key('test', 'somekid', 'quay', '', {}, expiration)
|
||||
return key.kid
|
||||
|
||||
def get_service_key_expiration(self, kid):
|
||||
try:
|
||||
|
@ -16,4 +17,5 @@ class PreOCIModel(ServiceKeyWorkerDataInterface):
|
|||
except model.ServiceKeyDoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
||||
|
|
|
@ -7,11 +7,12 @@ from workers.worker import Worker
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ServiceKeyWorker(Worker):
|
||||
def __init__(self):
|
||||
super(ServiceKeyWorker, self).__init__()
|
||||
self.add_operation(self._refresh_service_key,
|
||||
app.config.get('INSTANCE_SERVICE_KEY_REFRESH', 60)*60)
|
||||
app.config.get('INSTANCE_SERVICE_KEY_REFRESH', 60) * 60)
|
||||
|
||||
def _refresh_service_key(self):
|
||||
"""
|
||||
|
@ -22,6 +23,7 @@ class ServiceKeyWorker(Worker):
|
|||
model.set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration)
|
||||
logger.debug('Finished refresh of automatic service keys')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
worker = ServiceKeyWorker()
|
||||
worker.start()
|
||||
|
|
|
@ -13,7 +13,7 @@ def test_refresh_service_key(initialized_db):
|
|||
original_expiration = datetime.now() + timedelta(minutes=10)
|
||||
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):
|
||||
worker = ServiceKeyWorker()
|
||||
worker._refresh_service_key()
|
||||
|
|
Reference in a new issue