diff --git a/requirements-nover.txt b/requirements-nover.txt index 3898df463..786792fb5 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -62,4 +62,3 @@ bencode cryptography httmock moto -timeparse diff --git a/requirements.txt b/requirements.txt index 1e2557ac8..2d81b6b60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -107,7 +107,6 @@ SQLAlchemy==1.0.12 stevedore==1.12.0 stringscore==0.1.0 stripe==1.32.0 -timeparse==0.5.5 toposort==1.4 trollius==2.1 tzlocal==1.2.2 diff --git a/util/generatepresharedkey.py b/util/generatepresharedkey.py index 4343deb51..99b5eff22 100644 --- a/util/generatepresharedkey.py +++ b/util/generatepresharedkey.py @@ -1,10 +1,12 @@ +import argparse + +from dateutil.parser import parse as parse_date + from app import app from data import model from data.database import ServiceKeyApprovalType from data.model.log import log_action -from timeparse import ParseDatetime -import argparse def generate_key(service, name, expiration_date=None, notes=None): metadata = { @@ -34,12 +36,20 @@ def generate_key(service, name, expiration_date=None, notes=None): return private_key, key.kid +def valid_date(s): + try: + return parse_date(s) + except ValueError: + msg = "Not a valid date: '{0}'.".format(s) + raise argparse.ArgumentTypeError(msg) + + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Generates a preshared key') parser.add_argument('service', help='The service name for which the key is being generated') parser.add_argument('name', help='The friendly name for the key') - parser.add_argument('--expiration', help='The optional expiration date/time for the key', - default=None, action=ParseDatetime) + parser.add_argument('--expiration', default=None, type=valid_date, + help='The optional expiration date for the key') parser.add_argument('--notes', help='Optional notes about the key', default=None) args = parser.parse_args()