Time (#482)
* adding python 3.5 as a target * adding env flag * Aligning on arrow dates.
This commit is contained in:
@ -56,13 +56,12 @@ def determine_validity_years(end_date):
|
||||
:return: str validity in years
|
||||
"""
|
||||
now = arrow.utcnow()
|
||||
then = arrow.get(end_date)
|
||||
|
||||
if then < now.replace(years=+1):
|
||||
if end_date < now.replace(years=+1):
|
||||
return 1
|
||||
elif then < now.replace(years=+2):
|
||||
elif end_date < now.replace(years=+2):
|
||||
return 2
|
||||
elif then < now.replace(years=+3):
|
||||
elif end_date < now.replace(years=+3):
|
||||
return 3
|
||||
|
||||
raise Exception("DigiCert issued certificates cannot exceed three"
|
||||
@ -75,9 +74,8 @@ def get_issuance(options):
|
||||
:param options:
|
||||
:return:
|
||||
"""
|
||||
end_date = arrow.get(options['validity_end'])
|
||||
validity_years = determine_validity_years(end_date)
|
||||
return end_date, validity_years
|
||||
validity_years = determine_validity_years(options['validity_end'])
|
||||
return validity_years
|
||||
|
||||
|
||||
def process_options(options, csr):
|
||||
@ -109,8 +107,8 @@ def process_options(options, csr):
|
||||
|
||||
data['certificate']['dns_names'] = dns_names
|
||||
|
||||
end_date, validity_years = get_issuance(options)
|
||||
data['custom_expiration_date'] = end_date.format('YYYY-MM-DD')
|
||||
validity_years = get_issuance(options)
|
||||
data['custom_expiration_date'] = options['validity_end'].format('YYYY-MM-DD')
|
||||
data['validity_years'] = validity_years
|
||||
|
||||
return data
|
||||
|
@ -32,7 +32,7 @@ def test_process_options(app):
|
||||
'dns_names': names,
|
||||
'signature_hash': 'sha256'
|
||||
},
|
||||
'organization': {'id': 0},
|
||||
'organization': {'id': 111111},
|
||||
'validity_years': 1,
|
||||
'custom_expiration_date': arrow.get(2017, 5, 7).format('YYYY-MM-DD')
|
||||
}
|
||||
@ -47,18 +47,14 @@ def test_issuance():
|
||||
'validity_start': arrow.get(2016, 10, 30)
|
||||
}
|
||||
|
||||
end_date, period = get_issuance(options)
|
||||
|
||||
assert period == 2
|
||||
assert get_issuance(options) == 2
|
||||
|
||||
options = {
|
||||
'validity_end': arrow.get(2017, 5, 7),
|
||||
'validity_start': arrow.get(2016, 10, 30)
|
||||
}
|
||||
|
||||
end_date, period = get_issuance(options)
|
||||
|
||||
assert period == 1
|
||||
assert get_issuance(options) == 1
|
||||
|
||||
options = {
|
||||
'validity_end': arrow.get(2020, 5, 7),
|
||||
@ -66,7 +62,7 @@ def test_issuance():
|
||||
}
|
||||
|
||||
with pytest.raises(Exception):
|
||||
end_date, period = get_issuance(options)
|
||||
period = get_issuance(options)
|
||||
|
||||
|
||||
def test_signature_hash(app):
|
||||
|
@ -80,8 +80,8 @@ def process_options(options):
|
||||
}
|
||||
|
||||
if options.get('validity_end'):
|
||||
end_date, period = get_default_issuance(options)
|
||||
data['specificEndDate'] = str(end_date)
|
||||
period = get_default_issuance(options)
|
||||
data['specificEndDate'] = options['validity_end'].format("MM/DD/YYYY")
|
||||
data['validityPeriod'] = period
|
||||
|
||||
elif options.get('validity_years'):
|
||||
@ -100,19 +100,16 @@ def get_default_issuance(options):
|
||||
:param options:
|
||||
:return:
|
||||
"""
|
||||
specific_end_date = arrow.get(options['validity_end']).replace(days=-1).format("MM/DD/YYYY")
|
||||
|
||||
now = arrow.utcnow()
|
||||
then = arrow.get(options['validity_end'])
|
||||
|
||||
if then < now.replace(years=+1):
|
||||
if options['validity_end'] < now.replace(years=+1):
|
||||
validity_period = '1Y'
|
||||
elif then < now.replace(years=+2):
|
||||
elif options['validity_end'] < now.replace(years=+2):
|
||||
validity_period = '2Y'
|
||||
else:
|
||||
raise Exception("Verisign issued certificates cannot exceed two years in validity")
|
||||
|
||||
return specific_end_date, validity_period
|
||||
return validity_period
|
||||
|
||||
|
||||
def handle_response(content):
|
||||
|
Reference in New Issue
Block a user