chore: remove debug log, finally found it
This commit is contained in:
@@ -27,17 +27,9 @@ class GithubAppPermissionJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
Log::debug('Starting GithubAppPermissionJob', [
|
|
||||||
'app_id' => $this->github_app->app_id,
|
|
||||||
'installation_id' => $this->github_app->installation_id,
|
|
||||||
'api_url' => $this->github_app->api_url,
|
|
||||||
]);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log::debug('Generating GitHub JWT token');
|
|
||||||
$github_access_token = generateGithubJwt($this->github_app);
|
$github_access_token = generateGithubJwt($this->github_app);
|
||||||
|
|
||||||
Log::debug('Fetching app permissions from GitHub API');
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => "Bearer $github_access_token",
|
'Authorization' => "Bearer $github_access_token",
|
||||||
'Accept' => 'application/vnd.github+json',
|
'Accept' => 'application/vnd.github+json',
|
||||||
@@ -55,31 +47,14 @@ class GithubAppPermissionJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
$response = $response->json();
|
$response = $response->json();
|
||||||
$permissions = data_get($response, 'permissions');
|
$permissions = data_get($response, 'permissions');
|
||||||
|
|
||||||
Log::debug('Retrieved GitHub permissions', [
|
|
||||||
'app_id' => $this->github_app->app_id,
|
|
||||||
'permissions' => $permissions,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->github_app->contents = data_get($permissions, 'contents');
|
$this->github_app->contents = data_get($permissions, 'contents');
|
||||||
$this->github_app->metadata = data_get($permissions, 'metadata');
|
$this->github_app->metadata = data_get($permissions, 'metadata');
|
||||||
$this->github_app->pull_requests = data_get($permissions, 'pull_requests');
|
$this->github_app->pull_requests = data_get($permissions, 'pull_requests');
|
||||||
$this->github_app->administration = data_get($permissions, 'administration');
|
$this->github_app->administration = data_get($permissions, 'administration');
|
||||||
|
|
||||||
Log::debug('Saving updated permissions to database', [
|
|
||||||
'app_id' => $this->github_app->app_id,
|
|
||||||
'contents' => $this->github_app->contents,
|
|
||||||
'metadata' => $this->github_app->metadata,
|
|
||||||
'pull_requests' => $this->github_app->pull_requests,
|
|
||||||
'administration' => $this->github_app->administration,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->github_app->save();
|
$this->github_app->save();
|
||||||
$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');
|
$this->github_app->makeVisible('client_secret')->makeVisible('webhook_secret');
|
||||||
|
|
||||||
Log::debug('Successfully completed GithubAppPermissionJob', [
|
|
||||||
'app_id' => $this->github_app->app_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Log::error('GithubAppPermissionJob failed', [
|
Log::error('GithubAppPermissionJob failed', [
|
||||||
'app_id' => $this->github_app->app_id,
|
'app_id' => $this->github_app->app_id,
|
||||||
|
@@ -15,23 +15,11 @@ use Lcobucci\JWT\Token\Builder;
|
|||||||
|
|
||||||
function generateGithubToken(GithubApp $source, string $type)
|
function generateGithubToken(GithubApp $source, string $type)
|
||||||
{
|
{
|
||||||
Log::debug('Generating GitHub token', [
|
|
||||||
'app_id' => $source->app_id,
|
|
||||||
'type' => $type,
|
|
||||||
'api_url' => $source->api_url,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = Http::get("{$source->api_url}/zen");
|
$response = Http::get("{$source->api_url}/zen");
|
||||||
$serverTime = CarbonImmutable::now()->setTimezone('UTC');
|
$serverTime = CarbonImmutable::now()->setTimezone('UTC');
|
||||||
$githubTime = Carbon::parse($response->header('date'));
|
$githubTime = Carbon::parse($response->header('date'));
|
||||||
$timeDiff = abs($serverTime->diffInSeconds($githubTime));
|
$timeDiff = abs($serverTime->diffInSeconds($githubTime));
|
||||||
|
|
||||||
Log::debug('Time synchronization check', [
|
|
||||||
'server_time' => $serverTime->format('Y-m-d H:i:s'),
|
|
||||||
'github_time' => $githubTime->format('Y-m-d H:i:s'),
|
|
||||||
'difference_seconds' => $timeDiff,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($timeDiff > 50) {
|
if ($timeDiff > 50) {
|
||||||
Log::error('System time out of sync with GitHub', [
|
Log::error('System time out of sync with GitHub', [
|
||||||
'time_difference' => $timeDiff,
|
'time_difference' => $timeDiff,
|
||||||
@@ -60,20 +48,9 @@ function generateGithubToken(GithubApp $source, string $type)
|
|||||||
->getToken($algorithm, $signingKey)
|
->getToken($algorithm, $signingKey)
|
||||||
->toString();
|
->toString();
|
||||||
|
|
||||||
Log::debug('JWT token generated', [
|
|
||||||
'token_type' => $type,
|
|
||||||
'issued_at' => $now->modify('-1 minute')->format('Y-m-d H:i:s'),
|
|
||||||
'expires_at' => $now->modify('+8 minutes')->format('Y-m-d H:i:s'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return match ($type) {
|
return match ($type) {
|
||||||
'jwt' => $jwt,
|
'jwt' => $jwt,
|
||||||
'installation' => (function () use ($source, $jwt) {
|
'installation' => (function () use ($source, $jwt) {
|
||||||
Log::debug('Requesting installation token', [
|
|
||||||
'app_id' => $source->app_id,
|
|
||||||
'installation_id' => $source->installation_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = Http::withHeaders([
|
$response = Http::withHeaders([
|
||||||
'Authorization' => "Bearer $jwt",
|
'Authorization' => "Bearer $jwt",
|
||||||
'Accept' => 'application/vnd.github.machine-man-preview+json',
|
'Accept' => 'application/vnd.github.machine-man-preview+json',
|
||||||
@@ -89,10 +66,6 @@ function generateGithubToken(GithubApp $source, string $type)
|
|||||||
throw new RuntimeException("Failed to get installation token for {$source->name} with error: ".$error);
|
throw new RuntimeException("Failed to get installation token for {$source->name} with error: ".$error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug('Successfully obtained installation token', [
|
|
||||||
'app_id' => $source->app_id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $response->json()['token'];
|
return $response->json()['token'];
|
||||||
})(),
|
})(),
|
||||||
default => throw new \InvalidArgumentException("Unsupported token type: {$type}")
|
default => throw new \InvalidArgumentException("Unsupported token type: {$type}")
|
||||||
|
Reference in New Issue
Block a user