|
|
@@ -1,4 +1,6 @@
|
|
|
-import { ConfigSource } from '@growi/core/dist/interfaces';
|
|
|
+import {
|
|
|
+ ConfigSource, toNonBlankString, toNonBlankStringOrUndefined,
|
|
|
+} from '@growi/core/dist/interfaces';
|
|
|
import { ErrorV3 } from '@growi/core/dist/models';
|
|
|
import { body } from 'express-validator';
|
|
|
|
|
|
@@ -367,6 +369,7 @@ module.exports = (crowi) => {
|
|
|
body('gcsBucket').trim(),
|
|
|
body('gcsUploadNamespace').trim(),
|
|
|
body('gcsReferenceFileWithRelayMode').if(value => value != null).isBoolean(),
|
|
|
+ body('s3Bucket').trim(),
|
|
|
body('s3Region')
|
|
|
.trim()
|
|
|
.if(value => value !== '')
|
|
|
@@ -387,7 +390,6 @@ module.exports = (crowi) => {
|
|
|
}
|
|
|
return true;
|
|
|
}),
|
|
|
- body('s3Bucket').trim(),
|
|
|
body('s3AccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
|
|
|
body('s3SecretAccessKey').trim(),
|
|
|
body('s3ReferenceFileWithRelayMode').if(value => value != null).isBoolean(),
|
|
|
@@ -418,7 +420,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings:
|
|
|
* get:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: getAppSettings
|
|
|
* security:
|
|
|
* - bearer: []
|
|
|
* - accessTokenInQuery: []
|
|
|
@@ -515,7 +516,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/app-setting:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettings
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/app-setting
|
|
|
@@ -576,7 +576,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/site-url-setting:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingSiteUrlSetting
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/site-url-setting
|
|
|
@@ -727,7 +726,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/smtp-setting:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingSmtpSetting
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/smtp-setting
|
|
|
@@ -779,7 +777,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/smtp-test:
|
|
|
* post:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: postSmtpTest
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/smtp-setting
|
|
|
@@ -816,7 +813,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/ses-setting:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingSesSetting
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/ses-setting
|
|
|
@@ -868,7 +864,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/file-upload-settings:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingFileUploadSetting
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/file-upload-setting
|
|
|
@@ -895,42 +890,88 @@ module.exports = (crowi) => {
|
|
|
router.put('/file-upload-setting', loginRequiredStrictly, adminRequired, addActivity, validator.fileUploadSetting, apiV3FormValidator, async(req, res) => {
|
|
|
const { fileUploadType } = req.body;
|
|
|
|
|
|
- const requestParams = {
|
|
|
- 'app:fileUploadType': fileUploadType,
|
|
|
- };
|
|
|
-
|
|
|
- if (fileUploadType === 'gcs') {
|
|
|
- requestParams['gcs:apiKeyJsonPath'] = req.body.gcsApiKeyJsonPath;
|
|
|
- requestParams['gcs:bucket'] = req.body.gcsBucket;
|
|
|
- requestParams['gcs:uploadNamespace'] = req.body.gcsUploadNamespace;
|
|
|
- requestParams['gcs:referenceFileWithRelayMode'] = req.body.gcsReferenceFileWithRelayMode;
|
|
|
+ if (fileUploadType === 'aws') {
|
|
|
+ try {
|
|
|
+ try {
|
|
|
+ toNonBlankString(req.body.s3Bucket);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ throw new Error('S3 Bucket name is required');
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ toNonBlankString(req.body.s3Region);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ throw new Error('S3 Region is required');
|
|
|
+ }
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'app:fileUploadType': fileUploadType,
|
|
|
+ 'aws:s3Region': toNonBlankString(req.body.s3Region),
|
|
|
+ 'aws:s3Bucket': toNonBlankString(req.body.s3Bucket),
|
|
|
+ 'aws:referenceFileWithRelayMode': req.body.s3ReferenceFileWithRelayMode,
|
|
|
+ },
|
|
|
+ { skipPubsub: true });
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'aws:s3CustomEndpoint': toNonBlankStringOrUndefined(req.body.s3CustomEndpoint),
|
|
|
+ 'aws:s3AccessKeyId': toNonBlankStringOrUndefined(req.body.s3AccessKeyId),
|
|
|
+ 'aws:s3SecretAccessKey': toNonBlankStringOrUndefined(req.body.s3SecretAccessKey),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ skipPubsub: true,
|
|
|
+ removeIfUndefined: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ const msg = `Error occurred in updating AWS S3 settings: ${err.message}`;
|
|
|
+ logger.error('Error', err);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-fileUploadType-failed'));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (fileUploadType === 'aws') {
|
|
|
- requestParams['aws:s3Region'] = req.body.s3Region;
|
|
|
- requestParams['aws:s3CustomEndpoint'] = req.body.s3CustomEndpoint;
|
|
|
- requestParams['aws:s3Bucket'] = req.body.s3Bucket;
|
|
|
- requestParams['aws:s3AccessKeyId'] = req.body.s3AccessKeyId;
|
|
|
- requestParams['aws:referenceFileWithRelayMode'] = req.body.s3ReferenceFileWithRelayMode;
|
|
|
+ if (fileUploadType === 'gcs') {
|
|
|
+ try {
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'app:fileUploadType': fileUploadType,
|
|
|
+ 'gcs:referenceFileWithRelayMode': req.body.gcsReferenceFileWithRelayMode,
|
|
|
+ },
|
|
|
+ { skipPubsub: true });
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'gcs:apiKeyJsonPath': toNonBlankStringOrUndefined(req.body.gcsApiKeyJsonPath),
|
|
|
+ 'gcs:bucket': toNonBlankStringOrUndefined(req.body.gcsBucket),
|
|
|
+ 'gcs:uploadNamespace': toNonBlankStringOrUndefined(req.body.gcsUploadNamespace),
|
|
|
+ },
|
|
|
+ { skipPubsub: true, removeIfUndefined: true });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ const msg = `Error occurred in updating GCS settings: ${err.message}`;
|
|
|
+ logger.error('Error', err);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-fileUploadType-failed'));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (fileUploadType === 'azure') {
|
|
|
- requestParams['azure:tenantId'] = req.body.azureTenantId;
|
|
|
- requestParams['azure:clientId'] = req.body.azureClientId;
|
|
|
- requestParams['azure:clientSecret'] = req.body.azureClientSecret;
|
|
|
- requestParams['azure:storageAccountName'] = req.body.azureStorageAccountName;
|
|
|
- requestParams['azure:storageContainerName'] = req.body.azureStorageContainerName;
|
|
|
- requestParams['azure:referenceFileWithRelayMode'] = req.body.azureReferenceFileWithRelayMode;
|
|
|
+ try {
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'app:fileUploadType': fileUploadType,
|
|
|
+ 'azure:referenceFileWithRelayMode': req.body.azureReferenceFileWithRelayMode,
|
|
|
+ },
|
|
|
+ { skipPubsub: true });
|
|
|
+ await configManager.updateConfigs({
|
|
|
+ 'azure:tenantId': toNonBlankStringOrUndefined(req.body.azureTenantId),
|
|
|
+ 'azure:clientId': toNonBlankStringOrUndefined(req.body.azureClientId),
|
|
|
+ 'azure:clientSecret': toNonBlankStringOrUndefined(req.body.azureClientSecret),
|
|
|
+ 'azure:storageAccountName': toNonBlankStringOrUndefined(req.body.azureStorageAccountName),
|
|
|
+ 'azure:storageContainerName': toNonBlankStringOrUndefined(req.body.azureStorageContainerName),
|
|
|
+ }, { skipPubsub: true, removeIfUndefined: true });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ const msg = `Error occurred in updating Azure settings: ${err.message}`;
|
|
|
+ logger.error('Error', err);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-fileUploadType-failed'));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- await configManager.updateConfigs(requestParams, { skipPubsub: true });
|
|
|
-
|
|
|
- const s3SecretAccessKey = req.body.s3SecretAccessKey;
|
|
|
- if (fileUploadType === 'aws' && s3SecretAccessKey != null && s3SecretAccessKey.trim() !== '') {
|
|
|
- await configManager.updateConfigs({ 'aws:s3SecretAccessKey': s3SecretAccessKey }, { skipPubsub: true });
|
|
|
- }
|
|
|
-
|
|
|
await crowi.setUpFileUpload(true);
|
|
|
crowi.fileUploaderSwitchService.publishUpdatedMessage();
|
|
|
|
|
|
@@ -966,7 +1007,7 @@ module.exports = (crowi) => {
|
|
|
return res.apiv3({ responseParams });
|
|
|
}
|
|
|
catch (err) {
|
|
|
- const msg = 'Error occurred in updating fileUploadType';
|
|
|
+ const msg = 'Error occurred in retrieving file upload configurations';
|
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-fileUploadType-failed'));
|
|
|
}
|
|
|
@@ -979,7 +1020,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/questionnaire-settings:
|
|
|
* put:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingQuestionnaireSettings
|
|
|
* security:
|
|
|
* - cookieAuth: []
|
|
|
* summary: /app-settings/questionnaire-settings
|
|
|
@@ -1064,7 +1104,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/v5-schema-migration:
|
|
|
* post:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingV5SchemaMigration
|
|
|
* security:
|
|
|
* - bearer: []
|
|
|
* - accessTokenInQuery: []
|
|
|
@@ -1110,7 +1149,6 @@ module.exports = (crowi) => {
|
|
|
* /app-settings/maintenance-mode:
|
|
|
* post:
|
|
|
* tags: [AppSettings]
|
|
|
- * operationId: updateAppSettingMaintenanceMode
|
|
|
* security:
|
|
|
* - bearer: []
|
|
|
* - accessTokenInQuery: []
|