-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Docker, Refactor, Fix Notification Co-authored-by: notCharles <charles@pelican.dev> * Pint * Required adjustments * Remove deprecated * Third time's the charm --------- Co-authored-by: notCharles <charles@pelican.dev>
- Loading branch information
1 parent
291b514
commit f3de185
Showing
9 changed files
with
245 additions
and
98 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
211 changes: 163 additions & 48 deletions
211
app/Filament/Resources/NodeResource/Pages/EditNode.php
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace App\Services\Nodes; | ||
|
||
use App\Models\ApiKey; | ||
use App\Models\Node; | ||
use App\Services\Api\KeyCreationService; | ||
use Illuminate\Http\Request; | ||
|
||
class NodeAutoDeployService | ||
{ | ||
/** | ||
* NodeAutoDeployService constructor. | ||
*/ | ||
public function __construct( | ||
private readonly KeyCreationService $keyCreationService | ||
) { | ||
} | ||
|
||
/** | ||
* Generates a new API key for the logged-in user with only permission to read | ||
* nodes, and returns that as the deployment key for a node. | ||
* | ||
* @throws \App\Exceptions\Model\DataValidationException | ||
*/ | ||
public function handle(Request $request, Node $node, ?bool $docker = false): ?string | ||
{ | ||
/** @var ApiKey|null $key */ | ||
$key = ApiKey::query() | ||
->where('key_type', ApiKey::TYPE_APPLICATION) | ||
->where('r_nodes', true) | ||
->first(); | ||
|
||
// We couldn't find a key that exists for this user with only permission for | ||
// reading nodes. Go ahead and create it now. | ||
if (!$key) { | ||
$key = $this->keyCreationService->setKeyType(ApiKey::TYPE_APPLICATION)->handle([ | ||
'memo' => 'Automatically generated node deployment key.', | ||
'user_id' => $request->user()->id, | ||
], ['r_nodes' => true]); | ||
} | ||
|
||
$token = $key->identifier . $key->token; | ||
|
||
if (!$token) { | ||
return null; | ||
} | ||
|
||
return sprintf( | ||
'%s wings configure --panel-url %s --token %s --node %d%s', | ||
$docker ? 'docker compose exec -it' : 'sudo', | ||
config('app.url'), | ||
$token, | ||
$node->id, | ||
$request->isSecure() ? '' : ' --allow-insecure' | ||
); | ||
} | ||
} |
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