Merge "Do not count expired secrets toward quota"
This commit is contained in:
commit
efb6e62e8e
@ -685,8 +685,14 @@ class SecretRepo(BaseRepo):
|
||||
:param project_id: id of barbican project entity
|
||||
:param session: existing db session reference.
|
||||
"""
|
||||
|
||||
utcnow = timeutils.utcnow()
|
||||
expiration_filter = or_(models.Secret.expiration.is_(None),
|
||||
models.Secret.expiration > utcnow)
|
||||
|
||||
query = session.query(models.Secret).filter_by(deleted=False)
|
||||
query = query.filter(models.Secret.project_id == project_id)
|
||||
query = query.filter(expiration_filter)
|
||||
|
||||
return query
|
||||
|
||||
|
@ -17,6 +17,8 @@ from barbican.plugin.interface import secret_store as ss
|
||||
from barbican.tests import database_utils
|
||||
from barbican.tests import utils
|
||||
|
||||
import datetime
|
||||
|
||||
|
||||
@utils.parameterized_test_case
|
||||
class WhenTestingSecretRepository(database_utils.RepositoryTestCase):
|
||||
@ -214,3 +216,29 @@ class WhenTestingSecretRepository(database_utils.RepositoryTestCase):
|
||||
|
||||
count = self.repo.get_count(project.id, session=session)
|
||||
self.assertEqual(1, count)
|
||||
|
||||
def test_should_get_count_one_after_expiration(self):
|
||||
current_time = datetime.datetime.utcnow()
|
||||
tomorrow = current_time + datetime.timedelta(days=1)
|
||||
yesterday = current_time - datetime.timedelta(days=1)
|
||||
|
||||
session = self.repo.get_session()
|
||||
|
||||
project = models.Project()
|
||||
project.external_id = "my keystone id"
|
||||
project.save(session=session)
|
||||
|
||||
secret_model = models.Secret()
|
||||
secret_model.project_id = project.id
|
||||
secret_model.expiration = tomorrow
|
||||
self.repo.create_from(secret_model, session=session)
|
||||
|
||||
secret_model = models.Secret()
|
||||
secret_model.project_id = project.id
|
||||
secret_model.expiration = yesterday
|
||||
self.repo.create_from(secret_model, session=session)
|
||||
|
||||
session.commit()
|
||||
|
||||
count = self.repo.get_count(project.id, session=session)
|
||||
self.assertEqual(1, count)
|
||||
|
Loading…
Reference in New Issue
Block a user