ratelimit_exempt_hosts = set()

for identifier in node.metadata.get('ntfy/ratelimit-exempt-hosts', set()):
    ips = repo.libs.tools.resolve_identifier(repo, identifier)
    ratelimit_exempt_hosts |= {str(ip) for ip in ips['ipv4']}
    ratelimit_exempt_hosts |= {str(ip) for ip in ips['ipv6']}


files['/etc/ntfy/server.yml'] = {
    'content_type': 'mako',
    'context': {
        'ratelimit_exempt_hosts': ratelimit_exempt_hosts,
    },
    'after': {
        'pkg_apt:ntfy',
    },
    'triggers': {
        'svc_systemd:ntfy:restart',
    },
}

directories['/var/lib/ntfy'] = {
    'owner': 'ntfy',
    'group': 'ntfy',
    'mode': '0700',
    'before': {
        'pkg_apt:ntfy',
    },
}

directories['/var/cache/ntfy'] = {
    'owner': 'ntfy',
    'group': 'ntfy',
    'mode': '0700',
    'before': {
        'pkg_apt:ntfy',
    },
}

directories['/var/opt/ntfy'] = {
    'owner': 'ntfy',
    'group': 'ntfy',
    'before': {
        'pkg_apt:ntfy',
    },
}

svc_systemd['ntfy'] = {
    'needs': {
        'file:/etc/ntfy/server.yml',
        'pkg_apt:ntfy',
    },
}

users['ntfy'] = {
    'home': '/var/lib/ntfy',
}
