import re


def cert_arn_lookup(session, domain_name):
    """Looks up the ARN for a SSL Certificate

    Args:
        session (Session|None) : Boto3 session used to lookup information in AWS
                                 If session is None no lookup is performed
        domain_name (string) : Domain Name that the Certificate was issued for

    Returns:
        (string|None) : Certificate ARN or None if the Certificate could not be located
    """
    if session is None:
        return None

    client = session.client('acm')
    response = client.list_certificates()
    for certs in response['CertificateSummaryList']:
        if certs['DomainName'] == domain_name:
            return certs['CertificateArn']
        if certs['DomainName'].startswith('*'):    # if it is a wildcard domain like "*.thebossdev.io"
            cert_name = certs['DomainName'][1:] + '$'
            if re.search(cert_name, domain_name) != None:
                return certs['CertificateArn']
    return None