Add OpenCorporates collector for org targets, gated on an API token

Closes the last coverage gap for org (person remains intentionally
unaddressed — no good free/non-scraping option exists). Unlike the
other 8 sources, OpenCorporates now requires an API token even on its
free tier (confirmed: keyless request gets 401). RunnerRegistry::has()
checks services.opencorporates.token is configured before exposing the
source as runnable, so it degrades to "not yet integrated" in the UI
rather than a broken Run button, until OPENCORPORATES_API_TOKEN is set.

Also fixes a real bug hit while building this: a RunnerRegistry::REQUIRES
class constant mapping source key to a closure crashed on file load
(PHP class constants can't hold closures) — inlined the one check
instead of building an abstraction for a single case.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
cedry2k1992
2026-07-20 12:10:27 +03:00
co-authored by Claude Sonnet 5
parent 86f73c46b2
commit dc4388eabf
9 changed files with 261 additions and 3 deletions
+14 -1
View File
@@ -7,6 +7,7 @@ use App\Osint\Runners\DnsRunner;
use App\Osint\Runners\GravatarRunner;
use App\Osint\Runners\HoleheRunner;
use App\Osint\Runners\IpApiRunner;
use App\Osint\Runners\OpenCorporatesRunner;
use App\Osint\Runners\SherlockRunner;
use App\Osint\Runners\TheHarvesterRunner;
use App\Osint\Runners\WhoisRunner;
@@ -29,11 +30,23 @@ class RunnerRegistry
'holehe' => HoleheRunner::class,
'gravatar' => GravatarRunner::class,
'dns' => DnsRunner::class,
'opencorporates' => OpenCorporatesRunner::class,
];
public function has(string $sourceKey): bool
{
return isset(self::RUNNERS[$sourceKey]);
if (! isset(self::RUNNERS[$sourceKey])) {
return false;
}
// OpenCorporates additionally needs an API token configured before
// it's actually runnable — otherwise it's hidden rather than shown
// as a broken "Run" button that always fails.
if ($sourceKey === 'opencorporates') {
return filled(config('services.opencorporates.token'));
}
return true;
}
public function resolve(string $sourceKey): Runner
@@ -0,0 +1,56 @@
<?php
namespace App\Osint\Runners;
use App\Models\Target;
use App\Osint\Runner;
use App\Osint\RunnerException;
use App\Osint\RunnerResult;
use Illuminate\Support\Facades\Http;
class OpenCorporatesRunner implements Runner
{
public function run(Target $target): RunnerResult
{
if ($target->type !== 'org') {
throw new RunnerException('OpenCorporates only supports "org" targets.');
}
$token = config('services.opencorporates.token');
if (blank($token)) {
throw new RunnerException('OpenCorporates API token not configured (OPENCORPORATES_API_TOKEN).');
}
$response = Http::timeout((int) config('osint.run_timeout'))
->get('https://api.opencorporates.com/v0.4/companies/search', [
'q' => $target->value,
'api_token' => $token,
'per_page' => 10,
]);
if (! $response->successful()) {
throw new RunnerException('OpenCorporates request failed with status '.$response->status().'.');
}
$companies = $response->json('results.companies') ?? [];
$matches = collect($companies)->map(function (array $entry) {
$company = $entry['company'];
$label = sprintf(
'%s (%s%s)',
$company['name'],
$company['jurisdiction_code'] ?? 'unknown jurisdiction',
$company['current_status'] ? ', '.$company['current_status'] : ''
);
return ['name' => $label, 'url' => $company['opencorporates_url']];
})->all();
$summary = count($matches) > 0
? sprintf('Found %d compan%s matching "%s".', count($matches), count($matches) === 1 ? 'y' : 'ies', $target->value)
: sprintf('No companies found matching "%s".', $target->value);
return new RunnerResult(raw: ['matches' => $matches], summary: $summary);
}
}
+5
View File
@@ -32,5 +32,10 @@ class AppServiceProvider extends ServiceProvider
RateLimiter::for('osint-runner:holehe', fn () => Limit::perMinute(15));
RateLimiter::for('osint-runner:gravatar', fn () => Limit::perMinute(45));
RateLimiter::for('osint-runner:dns', fn () => Limit::perMinute(60));
// OpenCorporates' free tier is 50 requests/day, 200/month — this
// matches their real quota (not a courtesy limit) to protect the
// configured token from getting exhausted or suspended.
RateLimiter::for('osint-runner:opencorporates', fn () => Limit::perDay(50));
}
}