Alibaba OSS support

This commit is contained in:
Peter Papp
2021-06-15 18:37:03 +02:00
parent 3fc11b781b
commit c0da1b0b07
4 changed files with 168 additions and 82 deletions
+7
View File
@@ -41,6 +41,13 @@ MAIL_ENCRYPTION=
MAIL_FROM_ADDRESS="${MAIL_USERNAME}" MAIL_FROM_ADDRESS="${MAIL_USERNAME}"
MAIL_FROM_NAME="${MAIL_USERNAME}" MAIL_FROM_NAME="${MAIL_USERNAME}"
OSS_ACCESS_KEY_ID=
OSS_SECRET_ACCESS_KEY=
OSS_REGION=
OSS_BUCKET=
OSS_ENDPOINT=
OSS_URL=
AWS_ACCESS_KEY_ID= AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY= AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION= AWS_DEFAULT_REGION=
@@ -1,4 +1,5 @@
<?php <?php
namespace App\Http\Controllers\App; namespace App\Http\Controllers\App;
use Schema; use Schema;
@@ -64,7 +65,7 @@ class SetupWizardController extends Controller
*/ */
public function setup_database(StoreDatabaseCredentialsRequest $request) public function setup_database(StoreDatabaseCredentialsRequest $request)
{ {
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
try { try {
// Set temporary database connection // Set temporary database connection
config(['database.connections.test.driver' => $request->connection]); config(['database.connections.test.driver' => $request->connection]);
@@ -84,11 +85,11 @@ class SetupWizardController extends Controller
setEnvironmentValue([ setEnvironmentValue([
'DB_CONNECTION' => $request->connection, 'DB_CONNECTION' => $request->connection,
'DB_HOST' => $request->host, 'DB_HOST' => $request->host,
'DB_PORT' => $request->port, 'DB_PORT' => $request->port,
'DB_DATABASE' => $request->name, 'DB_DATABASE' => $request->name,
'DB_USERNAME' => $request->username, 'DB_USERNAME' => $request->username,
'DB_PASSWORD' => $request->password, 'DB_PASSWORD' => $request->password,
]); ]);
Artisan::call('config:cache'); Artisan::call('config:cache');
@@ -104,7 +105,7 @@ class SetupWizardController extends Controller
// Store setup wizard progress // Store setup wizard progress
Setting::forceCreate([ Setting::forceCreate([
'name' => 'setup_wizard_database', 'name' => 'setup_wizard_database',
'value' => 1, 'value' => 1,
]); ]);
@@ -119,7 +120,7 @@ class SetupWizardController extends Controller
*/ */
public function store_stripe_credentials(StoreStripeCredentialsRequest $request) public function store_stripe_credentials(StoreStripeCredentialsRequest $request)
{ {
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
// Create stripe instance // Create stripe instance
$stripe = Stripe::make($request->secret, '2020-03-02'); $stripe = Stripe::make($request->secret, '2020-03-02');
@@ -134,30 +135,30 @@ class SetupWizardController extends Controller
// Set settings // Set settings
collect([ collect([
[ [
'name' => 'stripe_currency', 'name' => 'stripe_currency',
'value' => $request->currency, 'value' => $request->currency,
], ],
[ [
'name' => 'payments_configured', 'name' => 'payments_configured',
'value' => 1, 'value' => 1,
], ],
[ [
'name' => 'payments_active', 'name' => 'payments_active',
'value' => 1, 'value' => 1,
], ],
])->each(function ($col) { ])->each(function ($col) {
Setting::forceCreate([ Setting::forceCreate([
'name' => $col['name'], 'name' => $col['name'],
'value' => $col['value'], 'value' => $col['value'],
]); ]);
}); });
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
// Set stripe credentials to .env // Set stripe credentials to .env
setEnvironmentValue([ setEnvironmentValue([
'CASHIER_CURRENCY' => $request->currency, 'CASHIER_CURRENCY' => $request->currency,
'STRIPE_KEY' => $request->key, 'STRIPE_KEY' => $request->key,
'STRIPE_SECRET' => $request->secret, 'STRIPE_SECRET' => $request->secret,
'STRIPE_WEBHOOK_SECRET' => $request->webhookSecret, 'STRIPE_WEBHOOK_SECRET' => $request->webhookSecret,
]); ]);
@@ -179,45 +180,45 @@ class SetupWizardController extends Controller
// Get options // Get options
collect([ collect([
[ [
'name' => 'billing_phone_number', 'name' => 'billing_phone_number',
'value' => $request->billing_phone_number, 'value' => $request->billing_phone_number,
], ],
[ [
'name' => 'billing_postal_code', 'name' => 'billing_postal_code',
'value' => $request->billing_postal_code, 'value' => $request->billing_postal_code,
], ],
[ [
'name' => 'billing_vat_number', 'name' => 'billing_vat_number',
'value' => $request->billing_vat_number, 'value' => $request->billing_vat_number,
], ],
[ [
'name' => 'billing_address', 'name' => 'billing_address',
'value' => $request->billing_address, 'value' => $request->billing_address,
], ],
[ [
'name' => 'billing_country', 'name' => 'billing_country',
'value' => $request->billing_country, 'value' => $request->billing_country,
], ],
[ [
'name' => 'billing_state', 'name' => 'billing_state',
'value' => $request->billing_state, 'value' => $request->billing_state,
], ],
[ [
'name' => 'billing_city', 'name' => 'billing_city',
'value' => $request->billing_city, 'value' => $request->billing_city,
], ],
[ [
'name' => 'billing_name', 'name' => 'billing_name',
'value' => $request->billing_name, 'value' => $request->billing_name,
], ],
])->each(function ($col) { ])->each(function ($col) {
Setting::forceCreate([ Setting::forceCreate([
'name' => $col['name'], 'name' => $col['name'],
'value' => $col['value'], 'value' => $col['value'],
]); ]);
}); });
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
Artisan::call('config:cache'); Artisan::call('config:cache');
} }
@@ -247,41 +248,49 @@ class SetupWizardController extends Controller
*/ */
public function store_environment_setup(StoreEnvironmentSetupRequest $request) public function store_environment_setup(StoreEnvironmentSetupRequest $request)
{ {
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
$drivers = [ $drivers = [
'local' => [ 'local' => [
'FILESYSTEM_DRIVER' => 'local', 'FILESYSTEM_DRIVER' => 'local',
], ],
's3' => [ 's3' => [
'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null, 'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null,
'AWS_ACCESS_KEY_ID' => $request->storage['key'] ?? null, 'AWS_ACCESS_KEY_ID' => $request->storage['key'] ?? null,
'AWS_SECRET_ACCESS_KEY' => $request->storage['secret'] ?? null, 'AWS_SECRET_ACCESS_KEY' => $request->storage['secret'] ?? null,
'AWS_DEFAULT_REGION' => $request->storage['region'] ?? null, 'AWS_DEFAULT_REGION' => $request->storage['region'] ?? null,
'AWS_BUCKET' => $request->storage['bucket'] ?? null, 'AWS_BUCKET' => $request->storage['bucket'] ?? null,
], ],
'spaces' => [ 'spaces' => [
'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null, 'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null,
'DO_SPACES_KEY' => $request->storage['key'] ?? null, 'DO_SPACES_KEY' => $request->storage['key'] ?? null,
'DO_SPACES_SECRET' => $request->storage['secret'] ?? null, 'DO_SPACES_SECRET' => $request->storage['secret'] ?? null,
'DO_SPACES_ENDPOINT' => $request->storage['endpoint'] ?? null, 'DO_SPACES_ENDPOINT' => $request->storage['endpoint'] ?? null,
'DO_SPACES_REGION' => $request->storage['region'] ?? null, 'DO_SPACES_REGION' => $request->storage['region'] ?? null,
'DO_SPACES_BUCKET' => $request->storage['bucket'] ?? null, 'DO_SPACES_BUCKET' => $request->storage['bucket'] ?? null,
], ],
'wasabi' => [ 'wasabi' => [
'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null, 'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null,
'WASABI_KEY' => $request->storage['key'] ?? null, 'WASABI_KEY' => $request->storage['key'] ?? null,
'WASABI_SECRET' => $request->storage['secret'] ?? null, 'WASABI_SECRET' => $request->storage['secret'] ?? null,
'WASABI_ENDPOINT' => $request->storage['endpoint'] ?? null, 'WASABI_ENDPOINT' => $request->storage['endpoint'] ?? null,
'WASABI_REGION' => $request->storage['region'] ?? null, 'WASABI_REGION' => $request->storage['region'] ?? null,
'WASABI_BUCKET' => $request->storage['bucket'] ?? null, 'WASABI_BUCKET' => $request->storage['bucket'] ?? null,
], ],
'backblaze' => [ 'backblaze' => [
'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null, 'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null,
'BACKBLAZE_KEY' => $request->storage['key'] ?? null, 'BACKBLAZE_KEY' => $request->storage['key'] ?? null,
'BACKBLAZE_SECRET' => $request->storage['secret'] ?? null, 'BACKBLAZE_SECRET' => $request->storage['secret'] ?? null,
'BACKBLAZE_ENDPOINT' => $request->storage['endpoint'] ?? null, 'BACKBLAZE_ENDPOINT' => $request->storage['endpoint'] ?? null,
'BACKBLAZE_REGION' => $request->storage['region'] ?? null, 'BACKBLAZE_REGION' => $request->storage['region'] ?? null,
'BACKBLAZE_BUCKET' => $request->storage['bucket'] ?? null, 'BACKBLAZE_BUCKET' => $request->storage['bucket'] ?? null,
],
'oss' => [
'FILESYSTEM_DRIVER' => $request->storage['driver'] ?? null,
'OSS_ACCESS_KEY_ID' => $request->storage['key'] ?? null,
'OSS_SECRET_ACCESS_KEY' => $request->storage['secret'] ?? null,
'OSS_ENDPOINT' => $request->storage['endpoint'] ?? null,
'OSS_REGION' => $request->storage['region'] ?? null,
'OSS_BUCKET' => $request->storage['bucket'] ?? null,
], ],
]; ];
@@ -293,11 +302,11 @@ class SetupWizardController extends Controller
// Store credentials for mail // Store credentials for mail
// TODO: add options for mailgun // TODO: add options for mailgun
setEnvironmentValue([ setEnvironmentValue([
'MAIL_DRIVER' => $request->mail['driver'], 'MAIL_DRIVER' => $request->mail['driver'],
'MAIL_HOST' => $request->mail['host'], 'MAIL_HOST' => $request->mail['host'],
'MAIL_PORT' => $request->mail['port'], 'MAIL_PORT' => $request->mail['port'],
'MAIL_USERNAME' => $request->mail['username'], 'MAIL_USERNAME' => $request->mail['username'],
'MAIL_PASSWORD' => $request->mail['password'], 'MAIL_PASSWORD' => $request->mail['password'],
'MAIL_ENCRYPTION' => $request->mail['encryption'], 'MAIL_ENCRYPTION' => $request->mail['encryption'],
]); ]);
@@ -317,61 +326,61 @@ class SetupWizardController extends Controller
// Get options // Get options
collect([ collect([
[ [
'name' => 'app_title', 'name' => 'app_title',
'value' => $request->title, 'value' => $request->title,
], ],
[ [
'name' => 'app_description', 'name' => 'app_description',
'value' => $request->description, 'value' => $request->description,
], ],
[ [
'name' => 'app_logo', 'name' => 'app_logo',
'value' => store_system_image($request, 'logo'), 'value' => store_system_image($request, 'logo'),
], ],
[ [
'name' => 'app_logo_horizontal', 'name' => 'app_logo_horizontal',
'value' => store_system_image($request, 'logo_horizontal'), 'value' => store_system_image($request, 'logo_horizontal'),
], ],
[ [
'name' => 'app_favicon', 'name' => 'app_favicon',
'value' => store_system_image($request, 'favicon'), 'value' => store_system_image($request, 'favicon'),
], ],
[ [
'name' => 'app_og_image', 'name' => 'app_og_image',
'value' => store_system_image($request, 'og_image'), 'value' => store_system_image($request, 'og_image'),
], ],
[ [
'name' => 'app_touch_icon', 'name' => 'app_touch_icon',
'value' => store_system_image($request, 'touch_icon'), 'value' => store_system_image($request, 'touch_icon'),
], ],
[ [
'name' => 'google_analytics', 'name' => 'google_analytics',
'value' => $request->googleAnalytics, 'value' => $request->googleAnalytics,
], ],
[ [
'name' => 'contact_email', 'name' => 'contact_email',
'value' => $request->contactMail, 'value' => $request->contactMail,
], ],
[ [
'name' => 'registration', 'name' => 'registration',
'value' => $request->userRegistration, 'value' => $request->userRegistration,
], ],
[ [
'name' => 'storage_limitation', 'name' => 'storage_limitation',
'value' => $request->storageLimitation, 'value' => $request->storageLimitation,
], ],
[ [
'name' => 'storage_default', 'name' => 'storage_default',
'value' => $request->defaultStorage ?? 5, 'value' => $request->defaultStorage ?? 5,
], ],
])->each(function ($col) { ])->each(function ($col) {
Setting::forceCreate([ Setting::forceCreate([
'name' => $col['name'], 'name' => $col['name'],
'value' => $col['value'], 'value' => $col['value'],
]); ]);
}); });
if (! app()->runningUnitTests()) { if (!app()->runningUnitTests()) {
setEnvironmentValue([ setEnvironmentValue([
'APP_NAME' => Str::camel($request->title), 'APP_NAME' => Str::camel($request->title),
]); ]);
@@ -391,18 +400,18 @@ class SetupWizardController extends Controller
// Validate request // Validate request
// TODO: validator do requestu // TODO: validator do requestu
$request->validate([ $request->validate([
'email' => 'required|string|email|unique:users', 'email' => 'required|string|email|unique:users',
'password' => 'required|string|min:6|confirmed', 'password' => 'required|string|min:6|confirmed',
'name' => 'required|string', 'name' => 'required|string',
'purchase_code' => 'required|string', 'purchase_code' => 'required|string',
'license' => 'required|string', 'license' => 'required|string',
'avatar' => 'sometimes|file', 'avatar' => 'sometimes|file',
]); ]);
// Create user // Create user
$user = User::forceCreate([ $user = User::forceCreate([
'role' => 'admin', 'role' => 'admin',
'email' => $request->email, 'email' => $request->email,
'password' => bcrypt($request->password), 'password' => bcrypt($request->password),
]); ]);
@@ -410,26 +419,26 @@ class SetupWizardController extends Controller
->settings() ->settings()
->create([ ->create([
'storage_capacity' => get_setting('storage_default') ?? 5, 'storage_capacity' => get_setting('storage_default') ?? 5,
'avatar' => store_avatar($request, 'avatar'), 'avatar' => store_avatar($request, 'avatar'),
'name' => $request->name, 'name' => $request->name,
]); ]);
collect([ collect([
[ [
'name' => 'setup_wizard_success', 'name' => 'setup_wizard_success',
'value' => 1, 'value' => 1,
], ],
[ [
'name' => 'license', 'name' => 'license',
'value' => $request->license, 'value' => $request->license,
], ],
[ [
'name' => 'purchase_code', 'name' => 'purchase_code',
'value' => $request->purchase_code, 'value' => $request->purchase_code,
], ],
])->each(function ($col) { ])->each(function ($col) {
Setting::forceCreate([ Setting::forceCreate([
'name' => $col['name'], 'name' => $col['name'],
'value' => $col['value'], 'value' => $col['value'],
]); ]);
}); });
+10
View File
@@ -53,6 +53,16 @@ return [
'visibility' => 'public', 'visibility' => 'public',
], ],
'oss' => [
'driver' => 's3',
'key' => env('OSS_ACCESS_KEY_ID'),
'secret' => env('OSS_SECRET_ACCESS_KEY'),
'region' => env('OSS_REGION'),
'bucket' => env('OSS_BUCKET'),
'endpoint' => env('OSS_ENDPOINT'),
'url' => env('OSS_URL'),
],
's3' => [ 's3' => [
'driver' => 's3', 'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'), 'key' => env('AWS_ACCESS_KEY_ID'),
@@ -172,6 +172,9 @@ export default {
if (this.storage.driver === 'backblaze') if (this.storage.driver === 'backblaze')
this.storage.endpoint = 'https://s3.' + val + '.backblazeb2.com' this.storage.endpoint = 'https://s3.' + val + '.backblazeb2.com'
if (this.storage.driver === 'oss')
this.storage.endpoint = 'https://' + val + '.aliyuncs.com'
}, },
}, },
computed: { computed: {
@@ -189,12 +192,65 @@ export default {
case 'backblaze': case 'backblaze':
return this.backblazeRegions return this.backblazeRegions
break break
case 'oss':
return this.ossRegions
break
} }
}, },
}, },
data() { data() {
return { return {
isLoading: false, isLoading: false,
ossRegions: [
{
label: 'China (Hangzhou)',
value: 'oss-cn-hangzhou',
},
{
label: 'China (Shanghai)',
value: 'oss-cn-shanghai',
},
{
label: 'China (Qingdao)',
value: 'oss-cn-qingdao',
},
{
label: 'China (Beijing)',
value: 'oss-cn-beijing',
},
{
label: 'China (Zhangjiakou)',
value: 'oss-cn-zhangjiakou',
},
{
label: 'China (Hohhot)',
value: 'oss-cn-huhehaote',
},
{
label: 'China (Ulanqab)',
value: 'oss-cn-wulanchabu',
},
{
label: 'China (Shenzhen)',
value: 'oss-cn-shenzhen',
},
{
label: 'China (Heyuan)',
value: 'oss-cn-heyuan',
},
{
label: 'China (Guangzhou)',
value: 'oss-cn-guangzhou',
},
{
label: 'China (Chengdu)',
value: 'oss-cn-chengdu',
},
{
label: 'China (Hong Kong)',
value: 'oss-cn-hongkong',
},
],
wasabiRegions: [ wasabiRegions: [
{ {
label: 'US East 1 (N. Virginia)', label: 'US East 1 (N. Virginia)',
@@ -352,6 +408,10 @@ export default {
label: 'Backblaze B2 Cloud Storage', label: 'Backblaze B2 Cloud Storage',
value: 'backblaze', value: 'backblaze',
}, },
{
label: 'Alibaba Cloud OSS',
value: 'oss',
},
], ],
encryptionList: [ encryptionList: [
{ {