From 309f5a750dace9f434c24b05d5379331f3ffc585 Mon Sep 17 00:00:00 2001 From: Barry O'Donovan Date: Sat, 2 Nov 2024 12:06:38 +0000 Subject: [PATCH] Update MANRS API endpoint --- app/Console/Commands/InManrs.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/InManrs.php b/app/Console/Commands/InManrs.php index 2a38ad289..28dbd92eb 100644 --- a/app/Console/Commands/InManrs.php +++ b/app/Console/Commands/InManrs.php @@ -24,6 +24,7 @@ */ use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Http; use IXP\Models\Customer; /** * Artisan command to update the in_peeringdb flag of members @@ -59,12 +60,18 @@ class InManrs extends Command public function handle(): int { // get list of peeringdb networks: - if( !( $json = file_get_contents( 'https://www.manrs.org/wp-json/manrs/v1/asn' ) ) ) { - $this->error( 'Could not load ASNs via MANRS\'s API' ); + try { + $resp = Http::withHeaders( [ + 'X-Request-Client' => 'IXP Manager', + 'X-Request-Client-Version' => APPLICATION_VERSION, + ] )->throw()->acceptJson() + ->get( 'https://api.manrs.org/asns' ); + } catch(\Exception $e) { + $this->error( 'Could not load ASNs via MANRS\'s API: ' . $e->getMessage() ); return 1; } - $asns = json_decode( $json, true ); + $asns = $resp['asns']; if( !is_array( $asns ) || !count( $asns ) ) { $this->error( 'Empty or no ASNs returned from MANRS\'s API' );