From 3cc8d105e19f7a9c8d0da0f87b8a5d929689a004 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Tue, 8 Oct 2024 12:58:55 -0400 Subject: [PATCH] Enforce default and max lease length times when offer is claimed --- esi_leap/api/controllers/v1/offer.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/esi_leap/api/controllers/v1/offer.py b/esi_leap/api/controllers/v1/offer.py index b22dcabb..ca2296c0 100644 --- a/esi_leap/api/controllers/v1/offer.py +++ b/esi_leap/api/controllers/v1/offer.py @@ -303,9 +303,21 @@ def claim(self, offer_uuid, new_lease): if "end_time" not in lease_dict: q = offer.get_next_lease_start_time(lease_dict["start_time"]) if q is None: - lease_dict["end_time"] = offer.end_time + max_end_time = offer.end_time else: - lease_dict["end_time"] = q.start_time + max_end_time = q.start_time + default_end_time = lease_dict["start_time"] + datetime.timedelta( + days=CONF.api.default_lease_time + ) + end_time = min([default_end_time, max_end_time]) + lease_dict["end_time"] = end_time + else: + utils.check_lease_length( + cdict, + lease_dict["start_time"], + lease_dict["end_time"], + CONF.api.max_lease_time, + ) new_lease = lease_obj.Lease(**lease_dict) new_lease.create(request)