From 16070c2b57b85742b7fb42388fa922b5aba59eb9 Mon Sep 17 00:00:00 2001 From: Bohdan Shulha Date: Sat, 9 Nov 2024 16:01:39 +0100 Subject: [PATCH] feat: #263 store and display public ssh key --- .../Http/Controllers/EventController.php | 1 + .../AgentStartedEventData/SwarmData.php | 1 + .../AppSource/GitWithDockerfileSource.php | 2 + .../AppSource/GitWithNixpacksSource.php | 2 + .../PullDockerImage/PullDockerImageResult.php | 2 +- app/Models/SwarmData.php | 1 + resources/js/Components/CopyToClipboard.vue | 104 +++++++++++++ .../js/Pages/Nodes/Partials/AgentInstall.vue | 145 ++++-------------- .../js/Pages/Nodes/Partials/PublicSSHKey.vue | 31 ++++ resources/js/Pages/Nodes/Settings.vue | 6 + .../Partials/DeploymentData/WorkerForm.vue | 4 +- .../Services/Partials/TemplatePicker.vue | 3 - 12 files changed, 179 insertions(+), 123 deletions(-) create mode 100644 resources/js/Components/CopyToClipboard.vue create mode 100644 resources/js/Pages/Nodes/Partials/PublicSSHKey.vue diff --git a/api-nodes/Http/Controllers/EventController.php b/api-nodes/Http/Controllers/EventController.php index b9b46fe..5fdf471 100644 --- a/api-nodes/Http/Controllers/EventController.php +++ b/api-nodes/Http/Controllers/EventController.php @@ -77,6 +77,7 @@ public function started(Node $node, AgentStartedEventData $data) $swarm->data->joinTokens = $data->swarm->joinTokens; $swarm->data->managerNodes = $data->swarm->managerNodes; $swarm->data->encryptionKey = $data->swarm->encryptionKey; + $swarm->data->publicSSHKey = $data->swarm->publicSSHKey; $nodeAddresses = $swarm->nodes->pluck('data.address')->toArray(); $dockerServices = collect($swarm->services) diff --git a/api-nodes/Models/AgentStartedEventData/SwarmData.php b/api-nodes/Models/AgentStartedEventData/SwarmData.php index 1911337..3509ec9 100644 --- a/api-nodes/Models/AgentStartedEventData/SwarmData.php +++ b/api-nodes/Models/AgentStartedEventData/SwarmData.php @@ -15,5 +15,6 @@ public function __construct( /* @var ManagerNode[] */ public array $managerNodes, public string $encryptionKey, + public string $publicSSHKey, ) {} } diff --git a/app/Models/DeploymentData/AppSource/GitWithDockerfileSource.php b/app/Models/DeploymentData/AppSource/GitWithDockerfileSource.php index 8b4bfc7..0f3c240 100644 --- a/app/Models/DeploymentData/AppSource/GitWithDockerfileSource.php +++ b/app/Models/DeploymentData/AppSource/GitWithDockerfileSource.php @@ -4,11 +4,13 @@ use App\Models\DeploymentData\Volume; use Spatie\LaravelData\Attributes\Validation\DoesntStartWith; +use Spatie\LaravelData\Attributes\Validation\StartsWith; use Spatie\LaravelData\Data; class GitWithDockerfileSource extends Data { public function __construct( + #[StartsWith('git@')] public string $repo, public string $ref, #[DoesntStartWith('/')] diff --git a/app/Models/DeploymentData/AppSource/GitWithNixpacksSource.php b/app/Models/DeploymentData/AppSource/GitWithNixpacksSource.php index 6adb6de..ac3a8de 100644 --- a/app/Models/DeploymentData/AppSource/GitWithNixpacksSource.php +++ b/app/Models/DeploymentData/AppSource/GitWithNixpacksSource.php @@ -3,11 +3,13 @@ namespace App\Models\DeploymentData\AppSource; use App\Models\DeploymentData\Volume; +use Spatie\LaravelData\Attributes\Validation\StartsWith; use Spatie\LaravelData\Data; class GitWithNixpacksSource extends Data { public function __construct( + #[StartsWith('git@')] public string $repo, public string $ref, public string $nixpacksFilePath, diff --git a/app/Models/NodeTasks/PullDockerImage/PullDockerImageResult.php b/app/Models/NodeTasks/PullDockerImage/PullDockerImageResult.php index c493d97..ded600f 100644 --- a/app/Models/NodeTasks/PullDockerImage/PullDockerImageResult.php +++ b/app/Models/NodeTasks/PullDockerImage/PullDockerImageResult.php @@ -15,6 +15,6 @@ public function __construct( public function formattedHtml(): string { - return implode("
\n", $this->output); + return implode('
', $this->output); } } diff --git a/app/Models/SwarmData.php b/app/Models/SwarmData.php index 8b6fec5..c7c11a7 100644 --- a/app/Models/SwarmData.php +++ b/app/Models/SwarmData.php @@ -27,6 +27,7 @@ public function __construct( /* @var ManagerNode[] */ public array $managerNodes, public string $encryptionKey = '', + public string $publicSSHKey = '', ) {} public function findRegistry(string $id): ?DockerRegistry diff --git a/resources/js/Components/CopyToClipboard.vue b/resources/js/Components/CopyToClipboard.vue new file mode 100644 index 0000000..adc05e4 --- /dev/null +++ b/resources/js/Components/CopyToClipboard.vue @@ -0,0 +1,104 @@ + + + diff --git a/resources/js/Pages/Nodes/Partials/AgentInstall.vue b/resources/js/Pages/Nodes/Partials/AgentInstall.vue index f6338d1..ed01e9e 100644 --- a/resources/js/Pages/Nodes/Partials/AgentInstall.vue +++ b/resources/js/Pages/Nodes/Partials/AgentInstall.vue @@ -3,16 +3,12 @@ import { onMounted, ref } from "vue"; import { CopyClipboard } from "flowbite"; import InputLabel from "@/Components/InputLabel.vue"; import Tour from "@/Components/Tour.vue"; +import CopyToClipboard from "@/Components/CopyToClipboard.vue"; defineProps({ node: Object, }); -const trigger = ref(null); -const copyToClipboardRef = ref(null); - -const showSuccessMessage = ref(false); - const providers = [ { name: "Hetzner", @@ -46,30 +42,6 @@ const providers = [ }, ]; -onMounted(() => { - const clipboard = new CopyClipboard( - trigger.value, - copyToClipboardRef.value, - ); - - clipboard.updateOnCopyCallback((clipboard) => { - showSuccess(); - - // reset to default state - setTimeout(() => { - resetToDefault(); - }, 2000); - }); - - const showSuccess = () => { - showSuccessMessage.value = true; - }; - - const resetToDefault = () => { - showSuccessMessage.value = false; - }; -}); - const steps = [ { title: "Welcome to Ptah.sh!", @@ -221,95 +193,34 @@ const steps = [ Execute this script in your server's console to install an Agent -
-
-
+ +
diff --git a/resources/js/Pages/Nodes/Partials/PublicSSHKey.vue b/resources/js/Pages/Nodes/Partials/PublicSSHKey.vue new file mode 100644 index 0000000..ea031a2 --- /dev/null +++ b/resources/js/Pages/Nodes/Partials/PublicSSHKey.vue @@ -0,0 +1,31 @@ + + + diff --git a/resources/js/Pages/Nodes/Settings.vue b/resources/js/Pages/Nodes/Settings.vue index ce18316..febe55a 100644 --- a/resources/js/Pages/Nodes/Settings.vue +++ b/resources/js/Pages/Nodes/Settings.vue @@ -11,6 +11,7 @@ import DockerRegistries from "@/Pages/Nodes/Partials/DockerRegistries.vue"; import S3Storages from "@/Pages/Nodes/Partials/S3Storages.vue"; import DeleteResourceSection from "@/Components/DeleteResourceSection.vue"; import { router } from "@inertiajs/vue3"; +import PublicSSHKey from "./Partials/PublicSSHKey.vue"; const props = defineProps([ "node", @@ -58,9 +59,14 @@ const destroyNode = () => router.delete(route("nodes.destroy", props.node.id)); v-if="$props.initTaskGroup" :taskGroup="$props.initTaskGroup" /> +