decorators.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:TigerHost 作者: naphatkrit 项目源码 文件源码
def option_hosted_zone_id(f):
    """Similar to click.option for hosted-zone-id, but in the event
    that the user does not specify the option, try to retrieve
    the ID from AWS and only error out if that fails or is ambiguous.
    """
    @click.option('--hosted-zone-id', '-hz', default=None, help='Route 53 Hosted Zone ID for {}'.format(settings.DOMAIN_NAME))
    @click.pass_context
    def new_func(ctx, hosted_zone_id, *args, **kwargs):
        """
        :param click.Context ctx:
        """
        if hosted_zone_id is None:
            echo_heading('Trying to find hosted zone for {}.'.format(settings.DOMAIN_NAME), marker='-', marker_color='magenta')
            client = boto3.client('route53')
            response = client.list_hosted_zones_by_name(
                DNSName=settings.DOMAIN_NAME
            )
            if len(response['HostedZones']) == 0:
                click.echo('Unable to find a Hosted Zone for {}. Please specify it explicitly by passing --hosted-zone-id/-hz.')
                ctx.exit(code=exit_codes.OTHER_FAILURE)
            elif len(response['HostedZones']) > 1:
                click.echo('Found multiple Hosted Zones for {}. Please specify one explicitly by passing --hosted-zone-id/-hz.')
                ctx.exit(code=exit_codes.OTHER_FAILURE)
            hosted_zone_id = response['HostedZones'][0]['Id'].split('/')[-1]
            click.echo('Done.')
        return ctx.invoke(f, hosted_zone_id=hosted_zone_id, *args, **kwargs)
    return update_wrapper(new_func, f)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号