From 948c6596818bb549a9bd19d34a2e2398df6f81cf Mon Sep 17 00:00:00 2001 From: Eric Wang <37554696+ericwang401@users.noreply.github.com> Date: Mon, 27 Nov 2023 20:44:40 -0600 Subject: [PATCH] refactor server setting route/function names to be more expressive/natural-sounding --- .../Client/Servers/ServerController.php | 30 ++++++++++++++----- .../Client/Servers/SettingsController.php | 10 +++---- .../api/server/settings/getAuthSettings.ts | 19 ++++++++++++ .../{getNetwork.ts => getNetworkSettings.ts} | 6 ++-- .../api/server/settings/getSecurity.ts | 17 ----------- ...pdateSecurity.ts => updateAuthSettings.ts} | 8 +++-- ...ateNetwork.ts => updateNetworkSettings.ts} | 6 ++-- .../partials/network/NameserversCard.tsx | 4 +-- .../partials/security/AuthenticationCard.tsx | 4 +-- routes/api-client.php | 8 ++--- 10 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 resources/scripts/api/server/settings/getAuthSettings.ts rename resources/scripts/api/server/settings/{getNetwork.ts => getNetworkSettings.ts} (65%) delete mode 100644 resources/scripts/api/server/settings/getSecurity.ts rename resources/scripts/api/server/settings/{updateSecurity.ts => updateAuthSettings.ts} (75%) rename resources/scripts/api/server/settings/{updateNetwork.ts => updateNetworkSettings.ts} (53%) diff --git a/app/Http/Controllers/Client/Servers/ServerController.php b/app/Http/Controllers/Client/Servers/ServerController.php index 26cafe71b49..3c30f4b7437 100644 --- a/app/Http/Controllers/Client/Servers/ServerController.php +++ b/app/Http/Controllers/Client/Servers/ServerController.php @@ -22,28 +22,39 @@ class ServerController extends ApplicationApiController { - public function __construct(private CotermJWTService $cotermJWTService, private ServerConsoleService $consoleService, private ServerDetailService $detailService, private ProxmoxServerRepository $serverRepository, private ProxmoxPowerRepository $powerRepository) + public function __construct( + private CotermJWTService $cotermJWTService, + private ServerConsoleService $consoleService, + private ServerDetailService $detailService, + private ProxmoxServerRepository $serverRepository, + private ProxmoxPowerRepository $powerRepository, + ) { } public function index(Server $server) { - return fractal($server, new ServerTransformer)->respond(); + return fractal($server, new ServerTransformer())->respond(); } public function details(Server $server) { - return fractal($this->detailService->getByProxmox($server), new ServerDetailTransformer)->respond(); + return fractal( + $this->detailService->getByProxmox($server), new ServerDetailTransformer(), + )->respond(); } public function getState(Server $server) { - return fractal()->item($this->serverRepository->setServer($server)->getState(), new ServerStateTransformer)->respond(); + return fractal()->item( + $this->serverRepository->setServer($server)->getState(), new ServerStateTransformer(), + )->respond(); } public function updateState(Server $server, SendPowerCommandRequest $request) { - $this->powerRepository->setServer($server)->send($request->enum('state', PowerAction::class)); + $this->powerRepository->setServer($server) + ->send($request->enum('state', PowerAction::class)); return $this->returnNoContent(); } @@ -56,8 +67,11 @@ public function createConsoleSession(CreateConsoleSessionRequest $request, Serve 'is_tls_enabled' => $server->node->coterm_tls_enabled, 'fqdn' => $server->node->coterm_fqdn, 'port' => $server->node->coterm_port, - 'token' => $this->cotermJWTService->handle($server, $request->user(), $request->enum('type', ConsoleType::class))->toString(), - ] + 'token' => $this->cotermJWTService->handle( + $server, $request->user(), $request->enum('type', ConsoleType::class), + ) + ->toString(), + ], ]); } else { $data = $this->consoleService->createConsoleUserCredentials($server); @@ -68,7 +82,7 @@ public function createConsoleSession(CreateConsoleSessionRequest $request, Serve 'vmid' => $server->vmid, 'fqdn' => $server->node->fqdn, 'port' => $server->node->port, - ], new ServerTerminalTransformer)->respond(); + ], new ServerTerminalTransformer())->respond(); } } } diff --git a/app/Http/Controllers/Client/Servers/SettingsController.php b/app/Http/Controllers/Client/Servers/SettingsController.php index a5de15346d4..0116cd0d460 100644 --- a/app/Http/Controllers/Client/Servers/SettingsController.php +++ b/app/Http/Controllers/Client/Servers/SettingsController.php @@ -27,7 +27,7 @@ use Convoy\Http\Requests\Client\Servers\Settings\MountMediaRequest; use Convoy\Http\Requests\Client\Servers\Settings\RenameServerRequest; use Convoy\Http\Requests\Client\Servers\Settings\UpdateNetworkRequest; -use Convoy\Http\Requests\Client\Servers\Settings\UpdateSecurityRequest; +use Convoy\Http\Requests\Client\Servers\Settings\UpdateAuthSettingsRequest; use Convoy\Http\Requests\Client\Servers\Settings\ReinstallServerRequest; use Convoy\Http\Requests\Client\Servers\Settings\UpdateBootOrderRequest; @@ -153,14 +153,14 @@ public function unmountMedia(Server $server, ISO $iso) return $this->returnNoContent(); } - public function getNetwork(Server $server) + public function getNetworkSettings(Server $server) { return fractal()->item([ 'nameservers' => $this->cloudinitService->getNameservers($server), ], new ServerNetworkTransformer())->respond(); } - public function updateNetwork(UpdateNetworkRequest $request, Server $server) + public function updateNetworkSettings(UpdateNetworkRequest $request, Server $server) { $this->cloudinitService->updateNameservers($server, $request->nameservers); @@ -169,14 +169,14 @@ public function updateNetwork(UpdateNetworkRequest $request, Server $server) ], new ServerNetworkTransformer())->respond(); } - public function getSecurity(Server $server) + public function getAuthSettings(Server $server) { return fractal()->item([ 'ssh_keys' => $this->authService->getSSHKeys($server), ], new ServerSecurityTransformer)->respond(); } - public function updateSecurity(UpdateSecurityRequest $request, Server $server) + public function updateAuthSettings(UpdateAuthSettingsRequest $request, Server $server) { if (AuthenticationType::from($request->type) === AuthenticationType::KEY) { $this->authService->updateSSHKeys($server, $request->ssh_keys); diff --git a/resources/scripts/api/server/settings/getAuthSettings.ts b/resources/scripts/api/server/settings/getAuthSettings.ts new file mode 100644 index 00000000000..752846960a7 --- /dev/null +++ b/resources/scripts/api/server/settings/getAuthSettings.ts @@ -0,0 +1,19 @@ +import http from '@/api/http' + +export interface AuthSettings { + sshKeys: string +} + +const rawDataToAuthSettings = (data: any): AuthSettings => ({ + sshKeys: data.ssh_keys, +}) + +const getAuthSettings = async (uuid: string): Promise => { + const { + data: { data }, + } = await http.get(`/api/client/servers/${uuid}/settings/auth`) + + return rawDataToAuthSettings(data) +} + +export default getAuthSettings \ No newline at end of file diff --git a/resources/scripts/api/server/settings/getNetwork.ts b/resources/scripts/api/server/settings/getNetworkSettings.ts similarity index 65% rename from resources/scripts/api/server/settings/getNetwork.ts rename to resources/scripts/api/server/settings/getNetworkSettings.ts index 5bf34b524e5..36930dc39bf 100644 --- a/resources/scripts/api/server/settings/getNetwork.ts +++ b/resources/scripts/api/server/settings/getNetworkSettings.ts @@ -4,10 +4,12 @@ export interface NetworkSettings { nameservers: string[] } -export default async (uuid: string): Promise => { +const getNetworkSettings = async (uuid: string): Promise => { const { data: { data }, } = await http.get(`/api/client/servers/${uuid}/settings/network`) return data -} \ No newline at end of file +} + +export default getNetworkSettings \ No newline at end of file diff --git a/resources/scripts/api/server/settings/getSecurity.ts b/resources/scripts/api/server/settings/getSecurity.ts deleted file mode 100644 index d496eb27f12..00000000000 --- a/resources/scripts/api/server/settings/getSecurity.ts +++ /dev/null @@ -1,17 +0,0 @@ -import http from '@/api/http' - -export interface SecuritySettings { - sshKeys: string -} - -const rawDataToSecurityObject = (data: any): SecuritySettings => ({ - sshKeys: data.ssh_keys, -}) - -export default async (uuid: string): Promise => { - const { - data: { data }, - } = await http.get(`/api/client/servers/${uuid}/settings/security`) - - return rawDataToSecurityObject(data) -} \ No newline at end of file diff --git a/resources/scripts/api/server/settings/updateSecurity.ts b/resources/scripts/api/server/settings/updateAuthSettings.ts similarity index 75% rename from resources/scripts/api/server/settings/updateSecurity.ts rename to resources/scripts/api/server/settings/updateAuthSettings.ts index 3c655c06957..5eeafa1735b 100644 --- a/resources/scripts/api/server/settings/updateSecurity.ts +++ b/resources/scripts/api/server/settings/updateAuthSettings.ts @@ -12,7 +12,7 @@ type UpdateKeysPayload = { type Payload = UpdatePasswordPayload | UpdateKeysPayload -export default (uuid: string, data: Payload) => { +const updateAuthSettings = (uuid: string, data: Payload) => { let payload = {} if (data.type === 'password') { @@ -29,5 +29,7 @@ export default (uuid: string, data: Payload) => { } } - return http.put(`/api/client/servers/${uuid}/settings/security`, payload) -} \ No newline at end of file + return http.put(`/api/client/servers/${uuid}/settings/auth`, payload) +} + +export default updateAuthSettings \ No newline at end of file diff --git a/resources/scripts/api/server/settings/updateNetwork.ts b/resources/scripts/api/server/settings/updateNetworkSettings.ts similarity index 53% rename from resources/scripts/api/server/settings/updateNetwork.ts rename to resources/scripts/api/server/settings/updateNetworkSettings.ts index 4a3f25ffa91..ceee8966ebc 100644 --- a/resources/scripts/api/server/settings/updateNetwork.ts +++ b/resources/scripts/api/server/settings/updateNetworkSettings.ts @@ -1,7 +1,9 @@ import http from '@/api/http' -export default (uuid: string, nameservers: string[]) => { +const updateNetworkSettings = (uuid: string, nameservers: string[]) => { return http.put(`/api/client/servers/${uuid}/settings/network`, { nameservers, }) -} \ No newline at end of file +} + +export default updateNetworkSettings diff --git a/resources/scripts/components/servers/settings/partials/network/NameserversCard.tsx b/resources/scripts/components/servers/settings/partials/network/NameserversCard.tsx index 4b8cff31ffa..041ca04eade 100644 --- a/resources/scripts/components/servers/settings/partials/network/NameserversCard.tsx +++ b/resources/scripts/components/servers/settings/partials/network/NameserversCard.tsx @@ -9,8 +9,8 @@ import { useTranslation } from 'react-i18next' import useSWR from 'swr' import { z } from 'zod' -import getNetwork from '@/api/server/settings/getNetwork' -import updateNetwork from '@/api/server/settings/updateNetwork' +import getNetwork from '@/api/server/settings/getNetworkSettings' +import updateNetwork from '@/api/server/settings/updateNetworkSettings' import Button from '@/components/elements/Button' import FlashMessageRender from '@/components/elements/FlashMessageRenderer' diff --git a/resources/scripts/components/servers/settings/partials/security/AuthenticationCard.tsx b/resources/scripts/components/servers/settings/partials/security/AuthenticationCard.tsx index 32d403a9447..01422c2e0ac 100644 --- a/resources/scripts/components/servers/settings/partials/security/AuthenticationCard.tsx +++ b/resources/scripts/components/servers/settings/partials/security/AuthenticationCard.tsx @@ -8,8 +8,8 @@ import { useTranslation } from 'react-i18next' import useSWR from 'swr' import { z } from 'zod' -import getSecurity from '@/api/server/settings/getSecurity' -import updateSecurity from '@/api/server/settings/updateSecurity' +import getSecurity from '@/api/server/settings/getAuthSettings' +import updateSecurity from '@/api/server/settings/updateAuthSettings' import Button from '@/components/elements/Button' import FlashMessageRender from '@/components/elements/FlashMessageRenderer' diff --git a/routes/api-client.php b/routes/api-client.php index b8043e323d0..bfbd19d34b0 100644 --- a/routes/api-client.php +++ b/routes/api-client.php @@ -35,10 +35,10 @@ Route::post('/hardware/isos/{iso}/mount', [Client\Servers\SettingsController::class, 'mountMedia']); Route::post('/hardware/isos/{iso}/unmount', [Client\Servers\SettingsController::class, 'unmountMedia']); - Route::get('/network', [Client\Servers\SettingsController::class, 'getNetwork']); - Route::put('/network', [Client\Servers\SettingsController::class, 'updateNetwork']); + Route::get('/network', [Client\Servers\SettingsController::class, 'getNetworkSettings']); + Route::put('/network', [Client\Servers\SettingsController::class, 'updateNetworkSettings']); - Route::get('/security', [Client\Servers\SettingsController::class, 'getSecurity']); - Route::put('/security', [Client\Servers\SettingsController::class, 'updateSecurity']); + Route::get('/auth', [Client\Servers\SettingsController::class, 'getAuthSettings']); + Route::put('/auth', [Client\Servers\SettingsController::class, 'updateAuthSettings']); }); });