mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-29 15:44:41 +00:00
test s3 connection before set up
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#### Release date: 1. April 2022
|
#### Release date: 1. April 2022
|
||||||
- Improved email setup in administration settings and setup wizard
|
- Improved email setup in administration settings and setup wizard
|
||||||
- Ability to set custom s3 compatible service in administration settings and setup wizard
|
- Ability to set custom s3 compatible service in administration settings and setup wizard
|
||||||
|
- Test s3 connection before set up in administration settings and setup wizard
|
||||||
|
|
||||||
## Version 2.0.0 - 2.0.10
|
## Version 2.0.0 - 2.0.10
|
||||||
#### Release date: 31. March 2022
|
#### Release date: 31. March 2022
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
"/chunks/app-settings.js": "/chunks/app-settings.js?id=55da23af2b076069",
|
"/chunks/app-settings.js": "/chunks/app-settings.js?id=55da23af2b076069",
|
||||||
"/chunks/app-appearance.js": "/chunks/app-appearance.js?id=a694a01f3641712c",
|
"/chunks/app-appearance.js": "/chunks/app-appearance.js?id=a694a01f3641712c",
|
||||||
"/chunks/app-index.js": "/chunks/app-index.js?id=efdbfa062749ca00",
|
"/chunks/app-index.js": "/chunks/app-index.js?id=efdbfa062749ca00",
|
||||||
"/chunks/app-environment.js": "/chunks/app-environment.js?id=1f5458233a20b263",
|
"/chunks/app-environment.js": "/chunks/app-environment.js?id=9be9c6b1a20b00cb",
|
||||||
"/chunks/app-others.js": "/chunks/app-others.js?id=16dc948aa2205189",
|
"/chunks/app-others.js": "/chunks/app-others.js?id=16dc948aa2205189",
|
||||||
"/chunks/app-sign-in-out.js": "/chunks/app-sign-in-out.js?id=1cfffc99465b9a7a",
|
"/chunks/app-sign-in-out.js": "/chunks/app-sign-in-out.js?id=1cfffc99465b9a7a",
|
||||||
"/chunks/app-adsense.js": "/chunks/app-adsense.js?id=a5dc9e715f8561bd",
|
"/chunks/app-adsense.js": "/chunks/app-adsense.js?id=a5dc9e715f8561bd",
|
||||||
@@ -72,5 +72,5 @@
|
|||||||
"/chunks/invitation.js": "/chunks/invitation.js?id=9ed8456c9d6d5ce1",
|
"/chunks/invitation.js": "/chunks/invitation.js?id=9ed8456c9d6d5ce1",
|
||||||
"/css/tailwind.css": "/css/tailwind.css",
|
"/css/tailwind.css": "/css/tailwind.css",
|
||||||
"/css/app.css": "/css/app.css",
|
"/css/app.css": "/css/app.css",
|
||||||
"/chunks/environment.js": "/chunks/environment.js?id=cef6ee74e56cb0d0"
|
"/chunks/environment.js": "/chunks/environment.js?id=520e1f9745f40ada"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default {
|
|||||||
this.title = args.title || undefined
|
this.title = args.title || undefined
|
||||||
this.message = args.message || undefined
|
this.message = args.message || undefined
|
||||||
|
|
||||||
this.button = this.$t('alerts.error_confirm')
|
this.button = this.$te('alerts.error_confirm') ? this.$t('alerts.error_confirm') : 'That’s horrible!'
|
||||||
this.emoji = '😢😢😢'
|
this.emoji = '😢😢😢'
|
||||||
this.buttonStyle = 'danger'
|
this.buttonStyle = 'danger'
|
||||||
|
|
||||||
|
|||||||
@@ -932,20 +932,6 @@ export default {
|
|||||||
storage: this.storage
|
storage: this.storage
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
events.$emit('toaster', {
|
|
||||||
type: 'success',
|
|
||||||
message: this.$t('storage_driver_updated'),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
events.$emit('toaster', {
|
|
||||||
type: 'danger',
|
|
||||||
message: this.$t('popup_error.title'),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.isSendingStorageForm = false
|
|
||||||
|
|
||||||
this.storage = {
|
this.storage = {
|
||||||
driver: undefined,
|
driver: undefined,
|
||||||
key: undefined,
|
key: undefined,
|
||||||
@@ -954,6 +940,28 @@ export default {
|
|||||||
region: undefined,
|
region: undefined,
|
||||||
bucket: undefined,
|
bucket: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.$emit('toaster', {
|
||||||
|
type: 'success',
|
||||||
|
message: this.$t('storage_driver_updated'),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
|
||||||
|
if (error.response.status === 401 && error.response.data.type === 's3-connection-error') {
|
||||||
|
events.$emit('alert:open', {
|
||||||
|
title: 'S3 Connection Error - Wrong Credentials or Not Permitted',
|
||||||
|
message: error.response.data.message,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
events.$emit('toaster', {
|
||||||
|
type: 'danger',
|
||||||
|
message: this.$t('popup_error.title'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.isSendingStorageForm = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async emailSetupSubmit() {
|
async emailSetupSubmit() {
|
||||||
|
|||||||
@@ -544,6 +544,7 @@ import Headline from '../Auth/Headline'
|
|||||||
import { required } from 'vee-validate/dist/rules'
|
import { required } from 'vee-validate/dist/rules'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
|
import {events} from "../../bus";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'EnvironmentSetup',
|
name: 'EnvironmentSetup',
|
||||||
@@ -982,7 +983,14 @@ export default {
|
|||||||
this.$router.push({ name: 'AppSetup' })
|
this.$router.push({ name: 'AppSetup' })
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.isError = true
|
if (error.response.status === 401 && error.response.data.type === 's3-connection-error') {
|
||||||
|
events.$emit('alert:open', {
|
||||||
|
title: 'S3 Connection Error - Wrong Credentials or Not Permitted',
|
||||||
|
message: error.response.data.message,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.isError = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
namespace Domain\Settings\Actions;
|
||||||
|
|
||||||
|
use Storage;
|
||||||
|
use Domain\Settings\DTO\S3CredentialsData;
|
||||||
|
|
||||||
|
class TestS3ConnectionAction
|
||||||
|
{
|
||||||
|
public function __invoke(S3CredentialsData $credentials): void
|
||||||
|
{
|
||||||
|
// Set temporary s3 connection
|
||||||
|
config([
|
||||||
|
'filesystems.disks.s3' => [
|
||||||
|
'driver' => 's3',
|
||||||
|
'key' => $credentials->key,
|
||||||
|
'secret' => $credentials->secret,
|
||||||
|
'region' => $credentials->region,
|
||||||
|
'bucket' => $credentials->bucket,
|
||||||
|
'endpoint' => $credentials->endpoint,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Try to get files
|
||||||
|
Storage::disk('s3')->allFiles();
|
||||||
|
|
||||||
|
// Try to create folder
|
||||||
|
Storage::disk('s3')->makeDirectory('s3-test');
|
||||||
|
|
||||||
|
// Delete test folder
|
||||||
|
Storage::disk('s3')->deleteDirectory('s3-test');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,10 +3,19 @@ namespace Domain\Settings\Controllers;
|
|||||||
|
|
||||||
use Artisan;
|
use Artisan;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use Aws\S3\Exception\S3Exception;
|
||||||
|
use League\Flysystem\UnableToWriteFile;
|
||||||
|
use Domain\Settings\DTO\S3CredentialsData;
|
||||||
|
use Domain\Settings\Actions\TestS3ConnectionAction;
|
||||||
use Domain\Settings\Requests\StoreStorageCredentialsRequest;
|
use Domain\Settings\Requests\StoreStorageCredentialsRequest;
|
||||||
|
|
||||||
class StoreStorageCredentialsController
|
class StoreStorageCredentialsController
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TestS3ConnectionAction $testS3Connection,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new email credentials to .env file
|
* Set new email credentials to .env file
|
||||||
*/
|
*/
|
||||||
@@ -15,6 +24,20 @@ class StoreStorageCredentialsController
|
|||||||
// Abort in demo mode
|
// Abort in demo mode
|
||||||
abort_if(is_demo(), 204, 'Done.');
|
abort_if(is_demo(), 204, 'Done.');
|
||||||
|
|
||||||
|
// Test s3 credentials
|
||||||
|
if ($request->input('storage.driver') !== 'local') {
|
||||||
|
try {
|
||||||
|
// connect to the s3
|
||||||
|
($this->testS3Connection)(S3CredentialsData::fromRequest($request));
|
||||||
|
} catch (S3Exception | UnableToWriteFile $error) {
|
||||||
|
return response([
|
||||||
|
'type' => 's3-connection-error',
|
||||||
|
'title' => 'S3 Connection Error',
|
||||||
|
'message' => $error->getMessage(),
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! app()->runningUnitTests()) {
|
if (! app()->runningUnitTests()) {
|
||||||
$drivers = [
|
$drivers = [
|
||||||
'local' => [
|
'local' => [
|
||||||
@@ -34,10 +57,9 @@ class StoreStorageCredentialsController
|
|||||||
$driver = 'local' === $request->input('storage.driver') ? 'local' : 's3';
|
$driver = 'local' === $request->input('storage.driver') ? 'local' : 's3';
|
||||||
|
|
||||||
// Storage credentials for storage
|
// Storage credentials for storage
|
||||||
setEnvironmentValue(
|
setEnvironmentValue($drivers[$driver]);
|
||||||
$drivers[$driver]
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// Cache the config
|
||||||
Artisan::call('config:cache');
|
Artisan::call('config:cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
namespace Domain\Settings\DTO;
|
||||||
|
|
||||||
|
use Spatie\DataTransferObject\DataTransferObject;
|
||||||
|
|
||||||
|
class S3CredentialsData extends DataTransferObject
|
||||||
|
{
|
||||||
|
public string $key;
|
||||||
|
public string $secret;
|
||||||
|
public string $region;
|
||||||
|
public string $bucket;
|
||||||
|
public string $endpoint;
|
||||||
|
|
||||||
|
public static function fromRequest($request): self
|
||||||
|
{
|
||||||
|
return new self([
|
||||||
|
'key' => $request->input('storage.key'),
|
||||||
|
'secret' => $request->input('storage.secret'),
|
||||||
|
'region' => $request->input('storage.region'),
|
||||||
|
'bucket' => $request->input('storage.bucket'),
|
||||||
|
'endpoint' => $request->input('storage.endpoint'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,20 @@ namespace Domain\SetupWizard\Controllers;
|
|||||||
|
|
||||||
use Artisan;
|
use Artisan;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use Aws\S3\Exception\S3Exception;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use League\Flysystem\UnableToWriteFile;
|
||||||
|
use Domain\Settings\DTO\S3CredentialsData;
|
||||||
|
use Domain\Settings\Actions\TestS3ConnectionAction;
|
||||||
use Domain\SetupWizard\Requests\StoreEnvironmentSetupRequest;
|
use Domain\SetupWizard\Requests\StoreEnvironmentSetupRequest;
|
||||||
|
|
||||||
class StoreEnvironmentSettingsController extends Controller
|
class StoreEnvironmentSettingsController extends Controller
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TestS3ConnectionAction $testS3Connection,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store environment setup
|
* Store environment setup
|
||||||
*/
|
*/
|
||||||
@@ -15,6 +24,20 @@ class StoreEnvironmentSettingsController extends Controller
|
|||||||
StoreEnvironmentSetupRequest $request,
|
StoreEnvironmentSetupRequest $request,
|
||||||
): Response {
|
): Response {
|
||||||
if (! app()->runningUnitTests()) {
|
if (! app()->runningUnitTests()) {
|
||||||
|
// Test s3 credentials
|
||||||
|
if ($request->input('storage.driver') !== 'local') {
|
||||||
|
try {
|
||||||
|
// connect to the s3
|
||||||
|
($this->testS3Connection)(S3CredentialsData::fromRequest($request));
|
||||||
|
} catch (S3Exception | UnableToWriteFile $error) {
|
||||||
|
return response([
|
||||||
|
'type' => 's3-connection-error',
|
||||||
|
'title' => 'S3 Connection Error',
|
||||||
|
'message' => $error->getMessage(),
|
||||||
|
], 401);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$setup = [
|
$setup = [
|
||||||
'broadcasting' => [
|
'broadcasting' => [
|
||||||
'pusher' => [
|
'pusher' => [
|
||||||
|
|||||||
Reference in New Issue
Block a user