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(
    'systemd-timers/timers/letsencrypt',
)
def cron(metadata):
    if node.metadata.get('letsencrypt/domains'):
        return {
            'systemd-timers': {
                'timers': {
                    'letsencrypt': {
                        'command': [
                            '/usr/bin/dehydrated --cron --accept-terms --challenge http-01',
                            '/usr/bin/dehydrated --cleanup',
                        ],
                        'when': '04:{}:00'.format(node.magic_number % 60),
                        'exclude_from_monitoring': True,
                    },
                },
            },
        }
    return {}
