-
-
Notifications
You must be signed in to change notification settings - Fork 1
base and register #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
07781cc
base and register
rdeutz fde98c0
fix cs and phpstan
rdeutz 023714b
remove package
rdeutz f96e574
type check
rdeutz 464f231
Fix cs
SniperSister 3a09bb2
deduplicate calls
SniperSister a4ed09c
move base dto
SniperSister 2b23f2e
save site
rdeutz b4331a6
stan fix
rdeutz 33ba905
types
rdeutz c8f54ac
Merge branch 'main' into feature/api-v1
SniperSister d241969
fix nullable error on write
SniperSister 4d5d54e
push last_seen
SniperSister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,82 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers\Api\V1; | ||
|
|
||
| use App\Http\Controllers\Controller; | ||
| use App\Jobs\CheckSiteHealth; | ||
| use App\Models\Site; | ||
| use App\RemoteSite\Connection; | ||
| use App\Traits\ApiResponse; | ||
| use GuzzleHttp\Exception\ClientException; | ||
| use GuzzleHttp\Exception\ServerException; | ||
| use Illuminate\Http\JsonResponse; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| /** | ||
| * Class SiteController | ||
| * @package App\Http\Controllers\Api\V1 | ||
| * @since 1.0 | ||
| */ | ||
| class SiteController extends Controller | ||
| { | ||
| use ApiResponse; | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * | ||
| * @return JsonResponse | ||
| * @throws \Exception | ||
| */ | ||
| public function register(Request $request): JsonResponse | ||
| { | ||
| $url = $request->input('url'); | ||
| $key = $request->input('key'); | ||
|
|
||
| if (empty($url) || empty($key)) { | ||
| return $this->error('BadRequest'); | ||
| } | ||
|
|
||
| $connectionService = new Connection($url, $key); | ||
|
Check failure on line 39 in app/Http/Controllers/Api/V1/SiteController.php
|
||
|
|
||
| // Do a health check | ||
| try { | ||
| $connectionService->checkHealth(); | ||
| } catch (ServerException $e) { | ||
| return $this->error($e->getMessage(), 500); | ||
| } catch (ClientException|\Exception $e) { | ||
| return $this->error($e->getMessage()); | ||
| } | ||
|
|
||
| // If successful save site | ||
| $site = new Site(); | ||
|
|
||
| $site->key = $key; | ||
| $site->url = $url; | ||
|
|
||
| CheckSiteHealth::dispatch($site); | ||
|
|
||
| return $this->ok(); | ||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * | ||
| * @return JsonResponse | ||
| */ | ||
| public function check(Request $request): JsonResponse | ||
| { | ||
|
|
||
|
|
||
| return response()->json(['check']); | ||
| } | ||
|
|
||
| /** | ||
| * @param Request $request | ||
| * | ||
| * @return JsonResponse | ||
| */ | ||
| public function delete(Request $request): JsonResponse | ||
| { | ||
| return response()->json(['delete']); | ||
| } | ||
| } | ||
This file contains hidden or 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,19 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Resources; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Resources\Json\JsonResource; | ||
|
|
||
| class Site extends JsonResource | ||
| { | ||
| /** | ||
| * Transform the resource into an array. | ||
| * | ||
| * @return array<string, mixed> | ||
| */ | ||
| public function toArray(Request $request): array | ||
| { | ||
| return parent::toArray($request); | ||
| } | ||
| } | ||
This file contains hidden or 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,19 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Resources; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Resources\Json\ResourceCollection; | ||
|
|
||
| class SiteCollection extends ResourceCollection | ||
| { | ||
| /** | ||
| * Transform the resource collection into an array. | ||
| * | ||
| * @return array<int|string, mixed> | ||
| */ | ||
| public function toArray(Request $request): array | ||
| { | ||
| return parent::toArray($request); | ||
| } | ||
| } | ||
This file contains hidden or 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,29 @@ | ||
| <?php | ||
|
|
||
| namespace App\Traits; | ||
|
|
||
| trait ApiResponse | ||
| { | ||
| protected function ok($message = 'OK') | ||
| { | ||
| return $this->success($message, 200); | ||
| } | ||
|
|
||
| protected function success($message, $statusCode = 200) | ||
| { | ||
| return $this->response($message, $statusCode); | ||
| } | ||
|
|
||
| protected function error($message, $statusCode = 400) | ||
| { | ||
| return $this->response($message, $statusCode); | ||
| } | ||
|
|
||
| protected function response($message, $statusCode = 200) | ||
| { | ||
| return response()->json([ | ||
| 'message' => $message, | ||
| 'status' => $statusCode | ||
| ], $statusCode); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,83 @@ | ||
| <?php | ||
|
|
||
| use Laravel\Sanctum\Sanctum; | ||
|
|
||
| return [ | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Stateful Domains | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Requests from the following domains / hosts will receive stateful API | ||
| | authentication cookies. Typically, these should include your local | ||
| | and production domains which access your API via a frontend SPA. | ||
| | | ||
| */ | ||
|
|
||
| 'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( | ||
| '%s%s', | ||
| 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', | ||
| Sanctum::currentApplicationUrlWithPort() | ||
| ))), | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Sanctum Guards | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | This array contains the authentication guards that will be checked when | ||
| | Sanctum is trying to authenticate a request. If none of these guards | ||
| | are able to authenticate the request, Sanctum will use the bearer | ||
| | token that's present on an incoming request for authentication. | ||
| | | ||
| */ | ||
|
|
||
| 'guard' => ['web'], | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Expiration Minutes | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | This value controls the number of minutes until an issued token will be | ||
| | considered expired. This will override any values set in the token's | ||
| | "expires_at" attribute, but first-party sessions are not affected. | ||
| | | ||
| */ | ||
|
|
||
| 'expiration' => null, | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Token Prefix | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Sanctum can prefix new tokens in order to take advantage of numerous | ||
| | security scanning initiatives maintained by open source platforms | ||
| | that notify developers if they commit tokens into repositories. | ||
| | | ||
| | See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning | ||
| | | ||
| */ | ||
|
|
||
| 'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''), | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | Sanctum Middleware | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | When authenticating your first-party SPA with Sanctum you may need to | ||
| | customize some of the middleware Sanctum uses while processing the | ||
| | request. You may change the middleware listed below as required. | ||
| | | ||
| */ | ||
|
|
||
| 'middleware' => [ | ||
| 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, | ||
| 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, | ||
| 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, | ||
| ], | ||
|
|
||
| ]; |
32 changes: 32 additions & 0 deletions
32
database/migrations/2024_11_16_094841_create_personal_access_tokens_table.php
This file contains hidden or 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,32 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class () extends Migration { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('personal_access_tokens', function (Blueprint $table) { | ||
| $table->id(); | ||
| $table->morphs('tokenable'); | ||
| $table->string('name'); | ||
| $table->string('token', 64)->unique(); | ||
| $table->text('abilities')->nullable(); | ||
| $table->timestamp('last_used_at')->nullable(); | ||
| $table->timestamp('expires_at')->nullable(); | ||
| $table->timestamps(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('personal_access_tokens'); | ||
| } | ||
| }; |
This file contains hidden or 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,12 @@ | ||
| <?php | ||
|
|
||
| use App\Http\Controllers\Api\V1\SiteController; | ||
| use Illuminate\Support\Facades\Route; | ||
|
|
||
| Route::prefix('v1')->group(function () { | ||
| Route::controller(SiteController::class)->group(function () { | ||
| Route::get('register', 'register'); | ||
| Route::get('check/{hase}', 'check'); | ||
| Route::delete('delete/{hash}', 'delete'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.