defaults = {
    'apt': {
        'packages': {
            'openssl': {
                'needed_by': {
                    'action:letsencrypt_update_certificates',
                },
            },
            'dehydrated': {
                'needed_by': {
                    'action:letsencrypt_update_certificates',
                },
            },
        },
    },
    'pacman': {
        'packages': {
            'dehydrated': {
                'needed_by': {
                    'action:letsencrypt_update_certificates',
                },
            },
        },
    },
}


@metadata_reactor.provides(
    'cron/jobs/letsencrypt',
)
def cron(metadata):
    if node.metadata.get('letsencrypt/domains'):
        return {
            'cron': {
                'jobs': {
                    'letsencrypt': '\n'.join([
                        '{} 4 * * *    root    /usr/bin/dehydrated --cron --accept-terms --challenge http-01 > /dev/null'.format((node.magic_number % 60)),
                        '{} 4 * * 0    root    /usr/bin/dehydrated --cleanup > /dev/null'.format((node.magic_number % 60)),
                    ]),
                },
            },
        }
    return {}
