'Register or update a domain certificate for this env.'

def certify(self, no_cleanup=False, no_confirm=True, manual=False):

    if (not self.domain):
        raise ClickException(((u"Can't    certify    a    domain    without    " + click.style(u'domain', fg=u'red', bold=True)) + u'    configured!'))
    if (not no_confirm):
        confirm = input(u'Are    you    sure    you    want    to    certify?    [y/n]    ')
        if (confirm != u'y'):
            return
    if no_cleanup:
        clean_up = False
        click.echo((((click.style(u'Warning!', fg=u'red', bold=True) + u'    You    are    calling    certify    with    ') + click.style(u'--no-cleanup', bold=True)) + u'.    Your    certificate    files    will    remain    in    the    system    temporary    directory    after    this    command    executes!'))
    else:
        clean_up = True
    deployed_versions = self.zappa.get_lambda_function_versions(self.lambda_name)
    if (len(deployed_versions) == 0):
        raise ClickException(((((u'This    application    ' + click.style(u"isn't    deployed    yet", fg=u'red')) + u'    -    did    you    mean    to    call    ') + click.style(u'deploy', bold=True)) + u'?'))
    account_key_location = self.stage_config.get(u'lets_encrypt_key', None)
    cert_location = self.stage_config.get(u'certificate', None)
    cert_key_location = self.stage_config.get(u'certificate_key', None)
    cert_chain_location = self.stage_config.get(u'certificate_chain', None)
    cert_arn = self.stage_config.get(u'certificate_arn', None)
    certificate_body = None
    certificate_private_key = None
    certificate_chain = None
    if ((not cert_location) and (not cert_arn)):
        if (not account_key_location):
            raise ClickException(((((((u"Can't    certify    a    domain    without    " + click.style(u'lets_encrypt_key', fg=u'red', bold=True)) + u'    or    ') + click.style(u'certificate', fg=u'red', bold=True)) + u'    or    ') + click.style(u'certificate_arn', fg=u'red', bold=True)) + u'    configured!'))
        if account_key_location.startswith(u's3://'):
            (bucket, key_name) = parse_s3_url(account_key_location)
            self.zappa.s3_client.download_file(bucket, key_name, u'/tmp/account.key')
        else:
            from shutil import copyfile
            copyfile(account_key_location, u'/tmp/account.key')
    elif ((not account_key_location) and (not cert_arn)):
        if ((not cert_location) or (not cert_key_location) or (not cert_chain_location)):
            raise ClickException(((u"Can't    certify    a    domain    without    " + click.style(u'certificate,    certificate_key    and    certificate_chain', fg=u'red', bold=True)) + u'    configured!'))
        with open(cert_location) as f:
            certificate_body = f.read()
        with open(cert_key_location) as f:
            certificate_private_key = f.read()
        with open(cert_chain_location) as f:
            certificate_chain = f.read()
    click.echo(((u'Certifying    domain    ' + click.style(self.domain, fg=u'green', bold=True)) + u'..'))
    if ((not cert_location) and (not cert_arn)):
        from .letsencrypt import get_cert_and_update_domain, cleanup
        cert_success = get_cert_and_update_domain(self.zappa, self.lambda_name, self.api_stage, self.domain, clean_up, manual)
        if clean_up:
            cleanup()
    else:
        if (not self.zappa.get_domain_name(self.domain)):
            dns_name = self.zappa.create_domain_name(domain_name=self.domain, certificate_name=(self.domain + u'-Zappa-Cert'), certificate_body=certificate_body, certificate_private_key=certificate_private_key, certificate_chain=certificate_chain, certificate_arn=cert_arn, lambda_name=self.lambda_name, stage=self.api_stage)
            if self.stage_config.get(u'route53_enabled', True):
                self.zappa.update_route53_records(self.domain, dns_name)
            print u'Created    a    new    domain    name    with    supplied    certificate.    Please    note    that    it    can    take    up    to    40    minutes    for    this    domain    to    be    created    and    propagated    through    AWS,    but    it    requires    no    further    work    on    your    part.'
        else:
            self.zappa.update_domain_name(domain_name=self.domain, certificate_name=(self.domain + u'-Zappa-Cert'), certificate_body=certificate_body, certificate_private_key=certificate_private_key, certificate_chain=certificate_chain, certificate_arn=cert_arn, lambda_name=self.lambda_name, stage=self.api_stage, route53=self.stage_config.get(u'route53_enabled', True))
        cert_success = True
    if cert_success:
        click.echo(((u'Certificate    ' + click.style(u'updated', fg=u'green', bold=True)) + u'!'))
    else:
        click.echo((click.style(u'Failed', fg=u'red', bold=True) + u'    to    generate    or    install    certificate!    :('))
        click.echo(u'\n==============\n')
        shamelessly_promote()
