define storage instances with phpdoc

This commit is contained in:
Saeed Vaziry 2024-01-03 22:31:50 +01:00
parent 31bd146239
commit 2d7f225ff2
9 changed files with 29 additions and 14 deletions

View File

@ -17,9 +17,12 @@ public function update(Service $service, string $ini): void
{ {
$tmpName = Str::random(10).strtotime('now'); $tmpName = Str::random(10).strtotime('now');
try { try {
Storage::disk('local')->put($tmpName, $ini); /** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk('local');
$storageDisk->put($tmpName, $ini);
$service->server->ssh('root')->upload( $service->server->ssh('root')->upload(
Storage::disk('local')->path($tmpName), $storageDisk->path($tmpName),
"/etc/php/$service->version/cli/php.ini" "/etc/php/$service->version/cli/php.ini"
); );
$this->deleteTempFile($tmpName); $this->deleteTempFile($tmpName);

View File

@ -343,10 +343,13 @@ public function sshKey(): array
]; ];
} }
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
return [ return [
'public_key' => Str::replace("\n", '', Storage::disk(config('core.key_pairs_disk'))->get($this->id.'.pub')), 'public_key' => Str::replace("\n", '', Storage::disk(config('core.key_pairs_disk'))->get($this->id.'.pub')),
'public_key_path' => Storage::disk(config('core.key_pairs_disk'))->path($this->id.'.pub'), 'public_key_path' => $storageDisk->path($this->id.'.pub'),
'private_key_path' => Storage::disk(config('core.key_pairs_disk'))->path((string) $this->id), 'private_key_path' => $storageDisk->path((string) $this->id),
]; ];
} }

View File

@ -164,10 +164,12 @@ private function createKeyPair(): void
$result = $this->ec2Client->createKeyPair([ $result = $this->ec2Client->createKeyPair([
'KeyName' => $keyName, 'KeyName' => $keyName,
]); ]);
Storage::disk(config('core.key_pairs_disk'))->put((string) $this->server->id, $result['KeyMaterial']); /** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
$storageDisk->put((string) $this->server->id, $result['KeyMaterial']);
generate_public_key( generate_public_key(
Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id), $storageDisk->path((string) $this->server->id),
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id.'.pub'), $storageDisk->path($this->server->id.'.pub'),
); );
} }

View File

@ -17,6 +17,8 @@ public function __construct(?Server $server = null)
protected function generateKeyPair(): void protected function generateKeyPair(): void
{ {
generate_key_pair(Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id)); /** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
generate_key_pair($storageDisk->path((string) $this->server->id));
} }
} }

View File

@ -59,13 +59,15 @@ public function regions(): array
public function create(): void public function create(): void
{ {
/** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
File::copy( File::copy(
storage_path(config('core.ssh_private_key_name')), storage_path(config('core.ssh_private_key_name')),
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id) $storageDisk->path($this->server->id)
); );
File::copy( File::copy(
storage_path(config('core.ssh_public_key_name')), storage_path(config('core.ssh_public_key_name')),
Storage::disk(config('core.key_pairs_disk'))->path($this->server->id.'.pub') $storageDisk->path($this->server->id.'.pub')
); );
} }

View File

@ -85,7 +85,9 @@ public function regions(): array
public function create(): void public function create(): void
{ {
// generate key pair // generate key pair
generate_key_pair(Storage::disk(config('core.key_pairs_disk'))->path((string) $this->server->id)); /** @var \Illuminate\Filesystem\FilesystemAdapter $storageDisk */
$storageDisk = Storage::disk(config('core.key_pairs_disk'));
generate_key_pair($storageDisk->path((string) $this->server->id));
$createSshKey = Http::withToken($this->server->serverProvider->credentials['token']) $createSshKey = Http::withToken($this->server->serverProvider->credentials['token'])
->post($this->apiUrl.'/ssh-keys', [ ->post($this->apiUrl.'/ssh-keys', [

View File

@ -39,8 +39,8 @@
'ssh_user' => env('SSH_USER', 'vito'), 'ssh_user' => env('SSH_USER', 'vito'),
'ssh_public_key_name' => env('SSH_PUBLIC_KEY_NAME', 'ssh-public.key'), 'ssh_public_key_name' => env('SSH_PUBLIC_KEY_NAME', 'ssh-public.key'),
'ssh_private_key_name' => env('SSH_PRIVATE_KEY_NAME', 'ssh-private.pem'), 'ssh_private_key_name' => env('SSH_PRIVATE_KEY_NAME', 'ssh-private.pem'),
'logs_disk' => env('SERVER_LOGS_DISK', 'server-logs-local'), 'logs_disk' => env('SERVER_LOGS_DISK', 'server-logs-local'), // should to be FilesystemAdapter storage
'key_pairs_disk' => env('KEY_PAIRS_DISK', 'key-pairs-local'), 'key_pairs_disk' => env('KEY_PAIRS_DISK', 'key-pairs-local'), // should to be FilesystemAdapter storage
/* /*
* General * General

View File

@ -30,6 +30,7 @@
'disks' => [ 'disks' => [
// should be FilesystemAdapter
'local' => [ 'local' => [
'driver' => 'local', 'driver' => 'local',
'root' => storage_path('app'), 'root' => storage_path('app'),

View File

@ -1,6 +1,6 @@
<div> <div>
<x-primary-button x-data="" x-on:click.prevent="$dispatch('open-modal', 'create-project')"> <x-primary-button x-data="" x-on:click.prevent="$dispatch('open-modal', 'create-project')">
{{ __('Create') }} {{ __('Connect') }}
</x-primary-button> </x-primary-button>
<x-modal name="create-project" :show="$open"> <x-modal name="create-project" :show="$open">