updating dependencies, and fixing the deprecated arrow.replaces to shift

This commit is contained in:
Hossein Shafagh
2019-09-20 13:49:38 -07:00
parent ea8524f035
commit a13c45e9cc
13 changed files with 159 additions and 144 deletions

View File

@ -419,7 +419,7 @@ def render(args):
)
if time_range:
to = arrow.now().replace(weeks=+time_range).format("YYYY-MM-DD")
to = arrow.now().shift(weeks=+time_range).format("YYYY-MM-DD")
now = arrow.now().format("YYYY-MM-DD")
query = query.filter(Certificate.not_after <= to).filter(
Certificate.not_after >= now
@ -561,7 +561,7 @@ def stats(**kwargs):
"""
if kwargs.get("metric") == "not_after":
start = arrow.utcnow()
end = start.replace(weeks=+32)
end = start.shift(weeks=+32)
items = (
database.db.session.query(Certificate.issuer, func.count(Certificate.id))
.group_by(Certificate.issuer)

View File

@ -15,11 +15,11 @@ def convert_validity_years(data):
now = arrow.utcnow()
data["validity_start"] = now.isoformat()
end = now.replace(years=+int(data["validity_years"]))
end = now.shift(years=+int(data["validity_years"]))
if not current_app.config.get("LEMUR_ALLOW_WEEKEND_EXPIRATION", True):
if is_weekend(end):
end = end.replace(days=-2)
end = end.shift(days=-2)
data["validity_end"] = end.isoformat()
return data

View File

@ -46,10 +46,10 @@ class PendingCertificateOutputSchema(LemurOutputSchema):
# Note aliasing is the first step in deprecating these fields.
notify = fields.Boolean()
active = fields.Boolean(attribute="notify")
active = fields.Boolean(attribute="notify", dump_only=True)
cn = fields.String()
common_name = fields.String(attribute="cn")
common_name = fields.String(attribute="cn", dump_only=True)
owner = fields.Email()

View File

@ -244,7 +244,7 @@ def render(args):
)
if time_range:
to = arrow.now().replace(weeks=+time_range).format("YYYY-MM-DD")
to = arrow.now().shift(weeks=+time_range).format("YYYY-MM-DD")
now = arrow.now().format("YYYY-MM-DD")
query = query.filter(PendingCertificate.not_after <= to).filter(
PendingCertificate.not_after >= now

View File

@ -72,11 +72,11 @@ def determine_validity_years(end_date):
"""
now = arrow.utcnow()
if end_date < now.replace(years=+1):
if end_date < now.shift(years=+1):
return 1
elif end_date < now.replace(years=+2):
elif end_date < now.shift(years=+2):
return 2
elif end_date < now.replace(years=+3):
elif end_date < now.shift(years=+3):
return 3
raise Exception(
@ -148,12 +148,12 @@ def map_cis_fields(options, csr):
"""
if not options.get("validity_years"):
if not options.get("validity_end"):
options["validity_end"] = arrow.utcnow().replace(
options["validity_end"] = arrow.utcnow().shift(
years=current_app.config.get("DIGICERT_DEFAULT_VALIDITY", 1)
)
options["validity_years"] = determine_validity_years(options["validity_end"])
else:
options["validity_end"] = arrow.utcnow().replace(
options["validity_end"] = arrow.utcnow().shift(
years=options["validity_years"]
)

View File

@ -111,16 +111,14 @@ def process_options(options):
data["subject_alt_names"] = ",".join(get_additional_names(options))
if options.get("validity_end") > arrow.utcnow().replace(years=2):
if options.get("validity_end") > arrow.utcnow().shift(years=2):
raise Exception(
"Verisign issued certificates cannot exceed two years in validity"
)
if options.get("validity_end"):
# VeriSign (Symantec) only accepts strictly smaller than 2 year end date
if options.get("validity_end") < arrow.utcnow().replace(years=2).replace(
days=-1
):
if options.get("validity_end") < arrow.utcnow().shift(years=2, days=-1):
period = get_default_issuance(options)
data["specificEndDate"] = options["validity_end"].format("MM/DD/YYYY")
data["validityPeriod"] = period
@ -149,9 +147,9 @@ def get_default_issuance(options):
"""
now = arrow.utcnow()
if options["validity_end"] < now.replace(years=+1):
if options["validity_end"] < now.shift(years=+1):
validity_period = "1Y"
elif options["validity_end"] < now.replace(years=+2):
elif options["validity_end"] < now.shift(years=+2):
validity_period = "2Y"
else:
raise Exception(
@ -261,7 +259,7 @@ class VerisignIssuerPlugin(IssuerPlugin):
url = current_app.config.get("VERISIGN_URL") + "/reportingws"
end = arrow.now()
start = end.replace(days=-7)
start = end.shift(days=-7)
data = {
"reportType": "detail",
@ -299,7 +297,7 @@ class VerisignSourcePlugin(SourcePlugin):
def get_certificates(self):
url = current_app.config.get("VERISIGN_URL") + "/reportingws"
end = arrow.now()
start = end.replace(years=-5)
start = end.shift(years=-5)
data = {
"reportType": "detail",
"startDate": start.format("MM/DD/YYYY"),

View File

@ -10,11 +10,11 @@ def test_convert_validity_years(session):
data = convert_validity_years(dict(validity_years=2))
assert data["validity_start"] == arrow.utcnow().isoformat()
assert data["validity_end"] == arrow.utcnow().replace(years=+2).isoformat()
assert data["validity_end"] == arrow.utcnow().shift(years=+2).isoformat()
with freeze_time("2015-01-10"):
data = convert_validity_years(dict(validity_years=1))
assert (
data["validity_end"]
== arrow.utcnow().replace(years=+1, days=-2).isoformat()
== arrow.utcnow().shift(years=+1, days=-2).isoformat()
)