fixes handling of lifetimes in config, from days to seconds

This commit is contained in:
Ronald Steinke 2018-01-10 10:14:42 +01:00
parent 1242ba060d
commit d87a075786
2 changed files with 15 additions and 16 deletions

View File

@ -661,17 +661,13 @@ class OneM2MDefaultController(LoggerMixin):
except ParseError as e:
raise CSEValueError(
"Illegal value for expirationTime: %s" % (e,))
if expiration_time < self.now + self.global_config[
"min_lifetime"]:
if expiration_time < self.now + self.global_config["min_lifetime"]:
self.logger.warn("expirationTime is too low. Adjusting")
expiration_time = self.now + self.global_config[
"min_lifetime"]
expiration_time = self.now + self.global_config["min_lifetime"]
self.fields.append("expirationTime")
elif expiration_time > self.now + self.global_config[
"max_lifetime"]:
elif expiration_time > self.now + self.global_config["max_lifetime"]:
self.logger.warn("expirationTime is too high. Adjusting")
expiration_time = self.now + self.global_config[
"max_lifetime"]
expiration_time = self.now + self.global_config["max_lifetime"]
self.fields.append("expirationTime")
values["expirationTime"] = expiration_time
@ -693,8 +689,7 @@ class OneM2MDefaultController(LoggerMixin):
values[attribute.name] is not None)
# TODO(rkr): check mandatory attributes
if not have_attr and attribute.mandatory:
raise CSEMissingValue("Missing attribute: %s" %
(attribute.name,))
raise CSEMissingValue("Missing attribute: %s" % (attribute.name,))
if have_attr and attribute.accesstype == attribute.RO:
self._handle_ro_attribute(attribute)

View File

@ -3,18 +3,22 @@ from openmtc.configuration import (Configuration, BooleanOption, ListOption,
LowerCaseEnumOption, LogLevel, SimpleOption)
def timedelta_in_seconds(sec):
return timedelta(seconds=sec)
class GlobalConfiguration(Configuration):
__name__ = "global configuration"
__options__ = {"disable_forwarding": BooleanOption(default=False),
"default_lifetime": SimpleOption(type=int,
default=timedelta(60 * 60),
converter=timedelta),
default=timedelta_in_seconds(60 * 60),
converter=timedelta_in_seconds),
"max_lifetime": SimpleOption(type=int,
default=timedelta(60 * 60 * 24),
converter=timedelta),
default=timedelta_in_seconds(60 * 60 * 24),
converter=timedelta_in_seconds),
"min_lifetime": SimpleOption(type=int,
default=timedelta(5),
converter=timedelta),
default=timedelta_in_seconds(5),
converter=timedelta_in_seconds),
"additional_host_names": ListOption(str),
"require_auth": BooleanOption(default=False),
"default_content_type": SimpleOption()}