def will_expire(certificate, days):
    '''
    Returns a dict containing details of a certificate and whether
    the certificate will expire in the specified number of days.
    Input can be a PEM string or file path.

    .. versionadded:: 2016.11.0

    certificate:
        The certificate to be read. Can be a path to a certificate file,
        or a string containing the PEM formatted text of the certificate.

    CLI Example:

    .. code-block:: bash

        salt '*' x509.will_expire "/etc/pki/mycert.crt" days=30
    '''
    ts_pt = "%Y-%m-%d %H:%M:%S"
    ret = {}

    if os.path.isfile(certificate):
        try:
            ret['path'] = certificate
            ret['check_days'] = days

            cert = _get_certificate_obj(certificate)

            _check_time = datetime.datetime.utcnow() + datetime.timedelta(days=days)
            _expiration_date = cert.get_not_after().get_datetime()

            ret['cn'] = _parse_subject(cert.get_subject())['CN']
            ret['will_expire'] = _expiration_date.strftime(ts_pt) <= _check_time.strftime(ts_pt)
        except ValueError as err:
            log.debug('Unable to return details of a sertificate expiration: %s', err)
            log.trace(err, exc_info=True)

    return ret
def will_expire ( certificate , days ) : ts_pt = "%Y-%m-%d %H:%M:%S" ret = { } if os . path . isfile ( certificate ) : try : ret [ 'path' ] = certificate ret [ 'check_days' ] = days cert = _get_certificate_obj ( certificate ) _check_time = datetime . datetime . utcnow ( ) + datetime . timedelta ( days = days ) _expiration_date = cert . get_not_after ( ) . get_datetime ( ) ret [ 'cn' ] = _parse_subject ( cert . get_subject ( ) ) [ 'CN' ] ret [ 'will_expire' ] = _expiration_date . strftime ( ts_pt ) <= _check_time . strftime ( ts_pt ) except ValueError as err : log . debug ( 'Unable to return details of a sertificate expiration: %s' , err ) log . trace ( err , exc_info = True ) return ret
Returns a dict containing details of a certificate and whether
    the certificate will expire in the specified number of days.
    Input can be a PEM string or file path.

    .. versionadded:: 2016.11.0

    certificate:
        The certificate to be read. Can be a path to a certificate file,
        or a string containing the PEM formatted text of the certificate.

    CLI Example:

    .. code-block:: bash

        salt '*' x509.will_expire "/etc/pki/mycert.crt" days=30