def valid_certificate(name, weeks=0, days=0, hours=0, minutes=0, seconds=0):
 ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
 now = time.time()
 cert_info = __salt__['tls.cert_info'](name)
 if (now < cert_info['not_before']):
  ret['comment'] = 'Certificate is not yet valid'
  return ret
 if (now > cert_info['not_after']):
  ret['comment'] = 'Certificate is expired'
  return ret
 delta_remaining = datetime.timedelta(seconds=(cert_info['not_after'] - now))
 delta_kind_map = {'weeks': weeks, 'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds}
 delta_min = datetime.timedelta(**delta_kind_map)
 if (delta_remaining < delta_min):
  ret['comment'] = 'Certificate will expire in {0}, which is less than {1}'.format(delta_remaining, delta_min)
  return ret
 ret['result'] = True
 ret['comment'] = 'Certificate is valid for {0}'.format(delta_remaining)
 return ret

def valid_certificate ( name , weeks = 0 , days = 0 , hours = 0 , minutes = 0 , seconds = 0 ) : ret = { 'name' : name , 'changes' : { } , 'result' : False , 'comment' : '' } now = time . time ( ) cert_info = __salt__ [ 'tls.cert_info' ] ( name ) if ( now < cert_info [ 'not_before' ] ) : ret [ 'comment' ] = 'Certificate is not yet valid' return ret if ( now > cert_info [ 'not_after' ] ) : ret [ 'comment' ] = 'Certificate is expired' return ret delta_remaining = datetime . timedelta ( seconds = ( cert_info [ 'not_after' ] - now ) ) delta_kind_map = { 'weeks' : weeks , 'days' : days , 'hours' : hours , 'minutes' : minutes , 'seconds' : seconds } delta_min = datetime . timedelta ( ** delta_kind_map ) if ( delta_remaining < delta_min ) : ret [ 'comment' ] = 'Certificate will expire in {0}, which is less than {1}' . format ( delta_remaining , delta_min ) return ret ret [ 'result' ] = True ret [ 'comment' ] = 'Certificate is valid for {0}' . format ( delta_remaining ) return ret
verify that a tls certificate is valid now and will be valid for the time specified through weeks .