mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
use blade as conmmands template (#444)
* use blade as conmmands template * fix lint * fix ssl
This commit is contained in:
@ -3,17 +3,18 @@
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\SSH\HasScripts;
|
||||
use App\Exceptions\SSHError;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Dropbox extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$upload = $this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/upload.sh', [
|
||||
view('ssh.storage.dropbox.upload', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
@ -33,10 +34,13 @@ public function upload(string $src, string $dest): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/download.sh', [
|
||||
view('ssh.storage.dropbox.download', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
@ -45,10 +49,13 @@ public function download(string $src, string $dest): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function delete(string $src): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('dropbox/delete-file.sh', [
|
||||
view('ssh.storage.dropbox.delete-file', [
|
||||
'src' => $src,
|
||||
'token' => $this->storageProvider->credentials['token'],
|
||||
]),
|
||||
|
@ -2,16 +2,17 @@
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\SSH\HasScripts;
|
||||
use App\Exceptions\SSHError;
|
||||
|
||||
class FTP extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/upload.sh', [
|
||||
view('ssh.storage.ftp.upload', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
@ -29,10 +30,13 @@ public function upload(string $src, string $dest): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/download.sh', [
|
||||
view('ssh.storage.ftp.download', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
@ -46,10 +50,13 @@ public function download(string $src, string $dest): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function delete(string $src): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('ftp/delete-file.sh', [
|
||||
view('ssh.storage.ftp.delete-file', [
|
||||
'src' => $src,
|
||||
'host' => $this->storageProvider->credentials['host'],
|
||||
'port' => $this->storageProvider->credentials['port'],
|
||||
|
@ -2,20 +2,21 @@
|
||||
|
||||
namespace App\SSH\Storage;
|
||||
|
||||
use App\SSH\HasScripts;
|
||||
use App\Exceptions\SSHError;
|
||||
|
||||
class Local extends AbstractStorage
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function upload(string $src, string $dest): array
|
||||
{
|
||||
$destDir = dirname($dest);
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/upload.sh', [
|
||||
view('ssh.storage.local.upload', [
|
||||
'src' => $src,
|
||||
'dest_dir' => $destDir,
|
||||
'dest_file' => $dest,
|
||||
'destDir' => $destDir,
|
||||
'destFile' => $dest,
|
||||
]),
|
||||
'upload-to-local'
|
||||
);
|
||||
@ -25,10 +26,13 @@ public function upload(string $src, string $dest): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function download(string $src, string $dest): void
|
||||
{
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('local/download.sh', [
|
||||
view('ssh.storage.local.download', [
|
||||
'src' => $src,
|
||||
'dest' => $dest,
|
||||
]),
|
||||
@ -36,6 +40,9 @@ public function download(string $src, string $dest): void
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function delete(string $src): void
|
||||
{
|
||||
$this->server->os()->deleteFile($src);
|
||||
|
@ -5,12 +5,11 @@
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\SSH\HasS3Storage;
|
||||
use App\SSH\HasScripts;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class S3 extends AbstractStorage
|
||||
{
|
||||
use HasS3Storage, HasScripts;
|
||||
use HasS3Storage;
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
@ -20,7 +19,7 @@ public function upload(string $src, string $dest): array
|
||||
/** @var \App\StorageProviders\S3 $provider */
|
||||
$provider = $this->storageProvider->provider();
|
||||
|
||||
$uploadCommand = $this->getScript('s3/upload.sh', [
|
||||
$uploadCommand = view('ssh.storage.s3.upload', [
|
||||
'src' => $src,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'dest' => $this->prepareS3Path($dest),
|
||||
@ -40,7 +39,6 @@ public function upload(string $src, string $dest): array
|
||||
return [
|
||||
'size' => null, // You can parse the size from the output if needed
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +49,7 @@ public function download(string $src, string $dest): void
|
||||
/** @var \App\StorageProviders\S3 $provider */
|
||||
$provider = $this->storageProvider->provider();
|
||||
|
||||
$downloadCommand = $this->getScript('s3/download.sh', [
|
||||
$downloadCommand = view('ssh.storage.s3.download', [
|
||||
'src' => $this->prepareS3Path($src),
|
||||
'dest' => $dest,
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
@ -71,13 +69,16 @@ public function download(string $src, string $dest): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function delete(string $src): void
|
||||
{
|
||||
/** @var \App\StorageProviders\S3 $provider */
|
||||
$provider = $this->storageProvider->provider();
|
||||
|
||||
$this->server->ssh()->exec(
|
||||
$this->getScript('s3/delete-file.sh', [
|
||||
view('ssh.storage.s3.delete-file', [
|
||||
'src' => $this->prepareS3Path($src),
|
||||
'bucket' => $this->storageProvider->credentials['bucket'],
|
||||
'key' => $this->storageProvider->credentials['key'],
|
||||
|
@ -1,6 +0,0 @@
|
||||
curl --location --request POST 'https://api.dropboxapi.com/2/files/delete_v2' \
|
||||
--header 'Authorization: Bearer __token__' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"path": "__src__"
|
||||
}'
|
@ -1,4 +0,0 @@
|
||||
curl -o __dest__ --location --request POST 'https://content.dropboxapi.com/2/files/download' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"__src__"}' \
|
||||
--header 'Authorization: Bearer __token__'
|
@ -1,6 +0,0 @@
|
||||
curl -sb --location --request POST 'https://content.dropboxapi.com/2/files/upload' \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Dropbox-API-Arg: {"path":"__dest__"}' \
|
||||
--header 'Content-Type: text/plain; charset=dropbox-cors-hack' \
|
||||
--header 'Authorization: Bearer __token__' \
|
||||
--data-binary '@__src__'
|
@ -1 +0,0 @@
|
||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -Q "DELE /__src__"
|
@ -1 +0,0 @@
|
||||
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"
|
@ -1 +0,0 @@
|
||||
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__
|
@ -1 +0,0 @@
|
||||
cp __src__ __dest__
|
@ -1,2 +0,0 @@
|
||||
mkdir -p __dest_dir__
|
||||
cp __src__ __dest_file__
|
@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
aws s3 rm s3://__bucket__/__src__
|
@ -1,32 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
if aws s3 cp s3://__bucket__/__src__ __dest__; then
|
||||
echo "Download successful"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
install_aws_cli() {
|
||||
echo "Installing AWS CLI"
|
||||
ARCH=$(uname -m)
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-$ARCH.zip" -o "aws.zip"
|
||||
unzip -q aws.zip
|
||||
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
|
||||
rm -rf aws.zip aws
|
||||
}
|
||||
|
||||
if ! command_exists aws; then
|
||||
install_aws_cli
|
||||
fi
|
||||
|
||||
if ! command_exists aws; then
|
||||
echo "Error: AWS CLI installation failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export AWS_ACCESS_KEY_ID=__key__
|
||||
export AWS_SECRET_ACCESS_KEY=__secret__
|
||||
export AWS_DEFAULT_REGION=__region__
|
||||
export AWS_ENDPOINT_URL=__endpoint__
|
||||
|
||||
if aws s3 cp __src__ s3://__bucket__/__dest__; then
|
||||
echo "Upload successful"
|
||||
fi
|
Reference in New Issue
Block a user