From 2c881c97226f0a5d50ba67a5abda019be45f70b0 Mon Sep 17 00:00:00 2001 From: "Harry (hjbdev)" Date: Thu, 27 Mar 2025 12:56:28 +0000 Subject: [PATCH] saloon, hetzner requests, spatie/ssh, serverprovider enum --- app/Enums/ServerProvider.php | 9 ++ .../Connectors/HetznerConnector.php | 22 +++ .../Hetzner/Images/ListImagesRequest.php | 34 +++++ .../Locations/ListLocationsRequest.php | 16 ++ .../ServerTypes/ListServerTypesRequest.php | 16 ++ .../Hetzner/Servers/CreateServerRequest.php | 37 +++++ app/Models/Server.php | 8 + composer.json | 4 +- composer.lock | 142 +++++++++++++++++- config/services.php | 4 + 10 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 app/Enums/ServerProvider.php create mode 100644 app/Http/Integrations/Connectors/HetznerConnector.php create mode 100644 app/Http/Integrations/Requests/Hetzner/Images/ListImagesRequest.php create mode 100644 app/Http/Integrations/Requests/Hetzner/Locations/ListLocationsRequest.php create mode 100644 app/Http/Integrations/Requests/Hetzner/ServerTypes/ListServerTypesRequest.php create mode 100644 app/Http/Integrations/Requests/Hetzner/Servers/CreateServerRequest.php diff --git a/app/Enums/ServerProvider.php b/app/Enums/ServerProvider.php new file mode 100644 index 0000000..493ecee --- /dev/null +++ b/app/Enums/ServerProvider.php @@ -0,0 +1,9 @@ + 'application/json', + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . config('services.hetzner.key'), + ]; + } +} diff --git a/app/Http/Integrations/Requests/Hetzner/Images/ListImagesRequest.php b/app/Http/Integrations/Requests/Hetzner/Images/ListImagesRequest.php new file mode 100644 index 0000000..11b3cea --- /dev/null +++ b/app/Http/Integrations/Requests/Hetzner/Images/ListImagesRequest.php @@ -0,0 +1,34 @@ + $this->name, + 'include_deprecated' => $this->includeDeprecated, + 'architecture' => $this->architecture, + 'label_selector' => $this->labelSelector, + ]; + } + + public function resolveEndpoint(): string + { + return '/images'; + } +} diff --git a/app/Http/Integrations/Requests/Hetzner/Locations/ListLocationsRequest.php b/app/Http/Integrations/Requests/Hetzner/Locations/ListLocationsRequest.php new file mode 100644 index 0000000..32a581a --- /dev/null +++ b/app/Http/Integrations/Requests/Hetzner/Locations/ListLocationsRequest.php @@ -0,0 +1,16 @@ + $this->image, + 'name' => $this->name, + 'server_type' => $this->serverType, + 'location' => $this->location, + ]; + } + + public function resolveEndpoint(): string + { + return '/servers'; + } +} diff --git a/app/Models/Server.php b/app/Models/Server.php index 38487ce..49f62b7 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\ServerProvider; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -9,6 +10,13 @@ class Server extends Model { protected $guarded = []; + protected function casts(): array + { + return [ + 'provider' => ServerProvider::class, + ]; + } + public function services(): HasMany { return $this->hasMany(Service::class); diff --git a/composer.json b/composer.json index bda25e9..ce8e87e 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,8 @@ "inertiajs/inertia-laravel": "^2.0", "laravel/framework": "^12.0", "laravel/tinker": "^2.10.1", + "saloonphp/saloon": "3.0", + "spatie/ssh": "^1.13", "tightenco/ziggy": "^2.4" }, "require-dev": { @@ -79,4 +81,4 @@ }, "minimum-stability": "stable", "prefer-stable": true -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 1b56b99..5e0f03e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "855d890ad6f8126c618922c69a4ae044", + "content-hash": "9d020e23e3b4787ce468533e44c3783c", "packages": [ { "name": "brick/math", @@ -3360,6 +3360,146 @@ ], "time": "2024-04-27T21:32:50+00:00" }, + { + "name": "saloonphp/saloon", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/saloonphp/saloon.git", + "reference": "b36be6b45e2170e1325cf034bc378e31318afe11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/saloonphp/saloon/zipball/b36be6b45e2170e1325cf034bc378e31318afe11", + "reference": "b36be6b45e2170e1325cf034bc378e31318afe11", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.6", + "guzzlehttp/promises": "^1.5 || ^2.0", + "guzzlehttp/psr7": "^2.0", + "php": "^8.1", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0" + }, + "conflict": { + "sammyjo20/saloon": "*" + }, + "require-dev": { + "ext-simplexml": "*", + "friendsofphp/php-cs-fixer": "^3.5", + "illuminate/collections": "^9.39 || ^10.0", + "league/flysystem": "^3.0", + "pestphp/pest": "^2.6", + "phpstan/phpstan": "^1.9", + "spatie/ray": "^1.33", + "symfony/dom-crawler": "^6.0" + }, + "suggest": { + "illuminate/collections": "Required for the response collect() method.", + "symfony/dom-crawler": "Required for the response dom() method." + }, + "type": "library", + "autoload": { + "psr-4": { + "Saloon\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sam Carré", + "email": "29132017+Sammyjo20@users.noreply.github.com", + "role": "Developer" + } + ], + "description": "Build beautiful API integrations and SDKs with Saloon", + "homepage": "https://github.com/saloonphp/saloon", + "keywords": [ + "api", + "api-integrations", + "saloon", + "sammyjo20", + "sdk" + ], + "support": { + "issues": "https://github.com/saloonphp/saloon/issues", + "source": "https://github.com/saloonphp/saloon/tree/v3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sammyjo20", + "type": "github" + }, + { + "url": "https://ko-fi.com/sammyjo20", + "type": "ko_fi" + } + ], + "time": "2023-10-01T08:13:44+00:00" + }, + { + "name": "spatie/ssh", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/ssh.git", + "reference": "cfccf0873611a2d1b030f65d1dd319c8005d993f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/ssh/zipball/cfccf0873611a2d1b030f65d1dd319c8005d993f", + "reference": "cfccf0873611a2d1b030f65d1dd319c8005d993f", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "symfony/process": "^4.4|^5.3|^6.0|^7.0" + }, + "require-dev": { + "pestphp/pest": "^1.22", + "spatie/pest-plugin-snapshots": "^1.1", + "symfony/var-dumper": "^5.3|6.0|^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Ssh\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A lightweight package to execute commands over an SSH connection", + "homepage": "https://github.com/spatie/ssh", + "keywords": [ + "spatie", + "ssh" + ], + "support": { + "issues": "https://github.com/spatie/ssh/issues", + "source": "https://github.com/spatie/ssh/tree/1.13.0" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + } + ], + "time": "2024-12-23T10:27:18+00:00" + }, { "name": "symfony/clock", "version": "v7.2.0", diff --git a/config/services.php b/config/services.php index 27a3617..839d401 100644 --- a/config/services.php +++ b/config/services.php @@ -35,4 +35,8 @@ return [ ], ], + 'hetzner' => [ + 'key' => env('HETZNER_KEY'), + ] + ];