New cron type for audit interval

This patch set adds cron supporting for audit.

Implements: blueprint cron-based-continuous-audits
Change-Id: I8570bebb13332dfba80185e912aeda45b6b4cd70
This commit is contained in:
Alexander Chadin
2017-04-21 18:19:46 +03:00
parent 35fdbbe16e
commit 0b44492da7
20 changed files with 326 additions and 54 deletions

View File

@@ -16,8 +16,11 @@
"""Utilities and helper functions."""
import datetime
import re
from croniter import croniter
from jsonschema import validators
from oslo_log import log as logging
from oslo_utils import strutils
@@ -63,6 +66,15 @@ is_int_like = strutils.is_int_like
strtime = timeutils.strtime
def is_cron_like(value):
"""Return True is submitted value is like cron syntax"""
try:
croniter(value, datetime.datetime.now())
except Exception as e:
raise exception.CronFormatIsInvalid(message=str(e))
return True
def safe_rstrip(value, chars=None):
"""Removes trailing characters from a string if that does not make it empty