-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Git
committed
Jan 7, 2024
1 parent
98ad1fd
commit a550793
Showing
9 changed files
with
391 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import datetime | ||
from dateutil.relativedelta import relativedelta | ||
|
||
from . import CertificateTimeFormat | ||
|
||
class CertificateStatistics: | ||
"""This class is responsible for helping with calculations of meta data.""" | ||
CLASS_VERSION = "0.01" | ||
|
||
certificate_time_format = CertificateTimeFormat.CertificateTimeFormat().cert_time_format | ||
|
||
@staticmethod | ||
def returnNotAfter(__certificateObject) -> None: | ||
"""Return the notAfter field from the certificate.""" | ||
if __certificateObject is not None: | ||
return __certificateObject['notAfter'] | ||
return "" | ||
|
||
@staticmethod | ||
def howMuchTimeLeft(__certificateObject) -> None: | ||
"""Return the remaining time left on the certificate.""" | ||
if __certificateObject is not None: | ||
timeNow = datetime.datetime.utcnow().replace(microsecond=0) | ||
certNotAfter = datetime.datetime.strptime( | ||
CertificateStatistics.returnNotAfter( | ||
__certificateObject | ||
), | ||
CertificateStatistics.certificate_time_format | ||
) | ||
|
||
__delta = relativedelta(certNotAfter, timeNow) | ||
|
||
myDeltaDate = { | ||
'years': __delta.years, | ||
'months': __delta.months, | ||
'days': __delta.days, | ||
'hours': __delta.hours, | ||
'minutes': __delta.minutes, | ||
'seconds': __delta.seconds, | ||
} | ||
timeLeft = [] | ||
|
||
for field in myDeltaDate: | ||
if myDeltaDate[field] > 1: | ||
timeLeft.append(f"{myDeltaDate[field]} {field}") | ||
else: | ||
if myDeltaDate[field] == 1: | ||
timeLeft.append(f"{myDeltaDate[field]} {field[:-1]}") | ||
|
||
certResult = ', '.join(timeLeft) | ||
else: | ||
certResult = "Invalid certificate" | ||
return certResult | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CertificateTimeFormat: | ||
"""Defines the time format for usage in Certificates.""" | ||
CLASS_VERSION = "0.01" | ||
cert_time_format = "%b %d %H:%M:%S %Y %Z" |
Oops, something went wrong.