<commit_before>-- Copyright 2022 <NAME>. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

local json = require("json")

name = "DNSRepo"
type = "api"

function start()
    set_rate_limit(2)
end

function check()
    local c
    local cfg = datasrc_config()
    if cfg ~= nil then
        c = cfg.credentials
    end

    if (c ~= nil and c.key ~= nil and c.key ~= "") then
        return true
    end
    return false
end

function vertical(ctx, domain)
    local c
    local cfg = datasrc_config()
    if cfg ~= nil then
        c = cfg.credentials
    end

    if (c == nil or c.key == nil or c.key == "") then
        return
    end

    local resp, err = request(ctx, {['url']=build_url(domain, c.key)})
    if (err ~= nil and err ~= "") then
        log(ctx, "vertical request to service failed: " .. err)
        return
    end
    resp = "{\"results\":" .. resp .. "}"

    local d = json.decode(resp)
    if (d == nil or d.results == nil or #(d.results) == 0) then
        return
    end

    for _, r in pairs(d.results) do
        new_name(ctx, r.domain)
    end
end

function build_url(domain, key)
    return "https://dnsrepo.noc.org/api/?apikey=" .. key .. "&search=" .. domain .. "&limit=5000"
end<commit_msg>Added support for querying the data source without credentials<commit_after>-- Copyright © by <NAME> 2022. All rights reserved.
-- Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
-- SPDX-License-Identifier: Apache-2.0

local json = require("json")

name = "DNSRepo"
type = "api"

function start()
    set_rate_limit(2)
end

function check()
    local c
    local cfg = datasrc_config()
    if cfg ~= nil then
        c = cfg.credentials
    end

    if (c ~= nil and c.key ~= nil and c.key ~= "") then
        return true
    end
    return false
end

function vertical(ctx, domain)
    local c
    local cfg = datasrc_config()
    if cfg ~= nil then
        c = cfg.credentials
    end

    if (c == nil or c.key == nil or c.key == "") then
        scrape(ctx, {['url']="https://dnsrepo.noc.org/?domain=" .. domain})
        return
    end

    local resp, err = request(ctx, {['url']=build_url(domain, c.key)})
    if (err ~= nil and err ~= "") then
        log(ctx, "vertical request to service failed: " .. err)
        return
    end
    resp = "{\"results\":" .. resp .. "}"

    local d = json.decode(resp)
    if (d == nil or d.results == nil or #(d.results) == 0) then
        return
    end

    for _, r in pairs(d.results) do
        new_name(ctx, r.domain)
    end
end

function build_url(domain, key)
    return "https://dnsrepo.noc.org/api/?apikey=" .. key .. "&search=" .. domain .. "&limit=5000"
end
{'fraction_non_alphanumeric': 0.13638012332245195, 'fraction_numerical': 0.008705114254624592, 'mean_word_length': 2.3029940119760477, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2249652', 'n_tokens_mistral': 917, 'n_tokens_neox': 900, 'n_words': 314}