Skip to content

Commit

Permalink
refactor server setting route/function names to be more expressive/na…
Browse files Browse the repository at this point in the history
…tural-sounding
  • Loading branch information
ericwang401 committed Nov 28, 2023
1 parent 854dbca commit 948c659
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 45 deletions.
30 changes: 22 additions & 8 deletions app/Http/Controllers/Client/Servers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
Expand All @@ -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();
}
}
}
10 changes: 5 additions & 5 deletions app/Http/Controllers/Client/Servers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions resources/scripts/api/server/settings/getAuthSettings.ts
Original file line number Diff line number Diff line change
@@ -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<AuthSettings> => {
const {
data: { data },
} = await http.get(`/api/client/servers/${uuid}/settings/auth`)

return rawDataToAuthSettings(data)
}

export default getAuthSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export interface NetworkSettings {
nameservers: string[]
}

export default async (uuid: string): Promise<NetworkSettings> => {
const getNetworkSettings = async (uuid: string): Promise<NetworkSettings> => {
const {
data: { data },
} = await http.get(`/api/client/servers/${uuid}/settings/network`)

return data
}
}

export default getNetworkSettings
17 changes: 0 additions & 17 deletions resources/scripts/api/server/settings/getSecurity.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -29,5 +29,7 @@ export default (uuid: string, data: Payload) => {
}
}

return http.put(`/api/client/servers/${uuid}/settings/security`, payload)
}
return http.put(`/api/client/servers/${uuid}/settings/auth`, payload)
}

export default updateAuthSettings
Original file line number Diff line number Diff line change
@@ -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,
})
}
}

export default updateNetworkSettings
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions routes/api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});

0 comments on commit 948c659

Please sign in to comment.