1010$/LicenseInfo$
1111"""
1212
13- import re
1413import shlex
1514import subprocess
1615import sys
17- from datetime import datetime , timedelta
1816from pathlib import Path
1917
2018from pyng .commands import Commands
@@ -24,10 +22,6 @@ class Error(Exception):
2422 pass
2523
2624
27- ExpiresLine = re .compile (
28- r"\bExpires:\s+\S{3}\s+(\S{3}) (\d+) \d\d:\d\d:\d\d (\d{4})"
29- ) # looking for a date like 'Sep 16 23:59:59 2017'
30-
3125# Make a function decorator that will generate an ArgumentParser
3226command = Commands ()
3327
@@ -60,34 +54,12 @@ def sign(executable, *, vault_uri, cert_name, client_id, client_secret, tenant_i
6054 '-tr' , 'http://timestamp.digicert.com' ,
6155 '-v' , executable ]
6256 print (name , 'signing:' , shlex .join (command ))
63- done = subprocess .run (command ,
64- stdout = subprocess .PIPE ,
65- stderr = subprocess .STDOUT ,
66- text = True )
67- print (done .stdout , end = '' )
57+ done = subprocess .run (command )
6858 rc = done .returncode
6959 if rc != 0 :
7060 raise Error (name + ' signing failed' )
7161
7262 print (name , 'signing succeeded' )
73- # Check the certificate expiration date in the output to warn of imminent expiration
74- for line in done .stdout .splitlines ():
75- found = ExpiresLine .search (line )
76- if found :
77- # month is an abbreviated name, translate
78- try :
79- expiration = datetime .strptime (' ' .join (found .groups ()), '%b %d %Y' )
80- except ValueError :
81- raise Error ('failed to parse expiration from: ' + line )
82- else :
83- expires = expiration - datetime .now ()
84- print (f'Certificate expires in { expires .days } days' )
85- if expires < timedelta (certwarning ):
86- print (f'::warning::Certificate expires in { expires .days } days: { expiration } ' )
87- break
88- else :
89- # raise Error('Failed to find certificate expiration date')
90- print ('::warning::Failed to find certificate expiration date' )
9163 return rc
9264
9365
0 commit comments