-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a08b590
commit f50069a
Showing
15 changed files
with
491 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\CheckSiteHealth; | ||
use App\Models\Site; | ||
use Illuminate\Console\Command; | ||
|
||
class PerformSiteHealthCheck extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:check-site-health {siteId}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Check site health for given site id'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
CheckSiteHealth::dispatchSync( | ||
Site::findOrFail($this->input->getArgument('siteId')) | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
app/Http/Controllers/Controller.php → app/Controllers/Controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
namespace app\Controllers; | ||
|
||
abstract class Controller | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Enum; | ||
|
||
enum HttpMethod | ||
{ | ||
case POST; | ||
case GET; | ||
case PATCH; | ||
case HEAD; | ||
case PUT; | ||
case DELETE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
|
||
class HorizonBasicAuthMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
$authenticationHasPassed = false; | ||
|
||
if ($request->header('PHP_AUTH_USER', null) && $request->header('PHP_AUTH_PW', null)) { | ||
$username = $request->header('PHP_AUTH_USER'); | ||
$password = $request->header('PHP_AUTH_PW'); | ||
|
||
if ($username === config('horizon.basic_auth.username') | ||
&& $password === config('horizon.basic_auth.password')) { | ||
$authenticationHasPassed = true; | ||
} | ||
} | ||
|
||
if ($authenticationHasPassed === false) { | ||
return response()->make('Invalid credentials.', 401, ['WWW-Authenticate' => 'Basic']); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Enum\HttpMethod; | ||
use App\Models\Site; | ||
use GuzzleHttp\Exception\RequestException; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Queue\Queueable; | ||
|
||
class CheckSiteHealth implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(protected readonly Site $site) | ||
{ | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$response = $this->site->performWebserviceRequest( | ||
HttpMethod::GET, | ||
'health.json' | ||
); | ||
|
||
$healthData = collect($response); | ||
|
||
// Perform a sanity check | ||
if (!$healthData->has('cms_version')) { | ||
throw new \Exception("Invalid health response content"); | ||
} | ||
|
||
// Write updated data to DB | ||
$this->site->update($healthData->only([ | ||
'php_version', | ||
'db_type', | ||
'db_version', | ||
'cms_version', | ||
'server_os' | ||
])->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Queue\Queueable; | ||
|
||
class UpdateSite implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Laravel\Horizon\Horizon; | ||
use Laravel\Horizon\HorizonApplicationServiceProvider; | ||
|
||
class HorizonServiceProvider extends HorizonApplicationServiceProvider | ||
{ | ||
/** | ||
* Overload authorization method from \Laravel\Horizon\HorizonApplicationServiceProvider | ||
* to allow access to Horizon without having a logged in user. | ||
* | ||
* @return void | ||
*/ | ||
protected function authorization() | ||
{ | ||
Horizon::auth(function () { | ||
return true; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.