<commit_before><?php

namespace DoSomething\Gateway\Server\Commands;

use JOSE_JWK;
use Illuminate\Console\Command;
use DoSomething\Gateway\Common\RestApiClient;

class PublicKeyCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'gateway:key';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Load public key for Gateway server middleware.';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $url = config('services.northstar.url');
        $path = config('services.northstar.key');
        $http = new RestApiClient($url);

        // Print an error if a URL isn't set in config file.
        if (empty($url)) {
            $this->error('Set a Northstar URL in config/services.php! <https://git.io/...>');
        }

        $discoveryUrl = $url.'/.well-known/openid-configuration';

        $this->comment('Reading configuration from '.$discoveryUrl.'...');
        $configuration = $http->get($discoveryUrl);
        $jwksUri = $configuration['jwks_uri'];

        $this->comment('Reading public key from '.$jwksUri.'...');
        $jwks = $http->get($jwksUri);

        $components = $jwks['keys'][0];
        $jwk = JOSE_JWK::decode($components);

        file_put_contents($path, (string) $jwk);
        $this->info('Wrote public key to ' . $path . '.');
    }
}<commit_msg>Better error handling if routes 404.<commit_after><?php

namespace DoSomething\Gateway\Server\Commands;

use JOSE_JWK;
use Illuminate\Console\Command;
use DoSomething\Gateway\Common\RestApiClient;

class PublicKeyCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'gateway:key';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Load public key for Gateway server middleware.';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $url = config('services.northstar.url');
        $path = config('services.northstar.key');
        $http = new RestApiClient($url);

        // Print an error if a URL isn't set in config file.
        if (empty($url)) {
            $this->error('Set a Northstar URL in config/services.php! <https://git.io/...>');

            return false;
        }

        $discoveryUrl = $url.'/.well-known/openid-configuration';

        $this->comment('Reading configuration from '.$discoveryUrl.'...');
        $configuration = $http->get($discoveryUrl);
        if (empty($configuration)) {
            $this->error('Could not load configuration.');

            return false;
        }

        $jwksUri = $configuration['jwks_uri'];

        $this->comment('Reading public key from '.$jwksUri.'...');
        $jwks = $http->get($jwksUri);
        if (empty($jwks)) {
            $this->error('Could not load public key.');

            return false;
        }

        $components = $jwks['keys'][0];
        $jwk = JOSE_JWK::decode($components);

        file_put_contents($path, (string) $jwk);
        $this->info('Wrote public key to ' . $path . '.');
    }
}
{'fraction_non_alphanumeric': 0.1492358405753671, 'fraction_numerical': 0.0014983518130056938, 'mean_word_length': 2.2789783889980355, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '2388046', 'n_tokens_mistral': 1010, 'n_tokens_neox': 976, 'n_words': 236}