Răsfoiți Sursa

Merge pull request #3201 from weseek/imprve/4614-4662-create-new-config-use-signedUrl

Imprve/4614 4662 create new config use signed url
Yuki Takei 5 ani în urmă
părinte
comite
8a6b7e29be

+ 17 - 5
src/server/routes/apiv3/app-settings.js

@@ -93,21 +93,24 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *          fileUploadType:
  *          fileUploadType:
  *            type: string
  *            type: string
  *            description: fileUploadType
  *            description: fileUploadType
- *          region:
+ *          s3Region:
  *            type: string
  *            type: string
  *            description: region of AWS S3
  *            description: region of AWS S3
- *          customEndpoint:
+ *          s3CustomEndpoint:
  *            type: string
  *            type: string
  *            description: custom endpoint of AWS S3
  *            description: custom endpoint of AWS S3
- *          bucket:
+ *          s3Bucket:
  *            type: string
  *            type: string
  *            description: AWS S3 bucket name
  *            description: AWS S3 bucket name
- *          accessKeyId:
+ *          s3AccessKeyId:
  *            type: string
  *            type: string
  *            description: accesskey id for authentification of AWS
  *            description: accesskey id for authentification of AWS
- *          secretAccessKey:
+ *          s3SecretAccessKey:
  *            type: string
  *            type: string
  *            description: secret key for authentification of AWS
  *            description: secret key for authentification of AWS
+ *          s3IsEnabledInternalStreamSystem:
+ *            type: boolean
+ *            description: is enable internal stream system for s3 file request
  *          gcsApiKeyJsonPath:
  *          gcsApiKeyJsonPath:
  *            type: string
  *            type: string
  *            description: apiKeyJsonPath of gcp
  *            description: apiKeyJsonPath of gcp
@@ -117,6 +120,9 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *          gcsUploadNamespace:
  *          gcsUploadNamespace:
  *            type: string
  *            type: string
  *            description: name space of gcs
  *            description: name space of gcs
+ *          gcsIsEnabledInternalStreamSystem:
+ *            type: boolean
+ *            description: is enable internal stream system for gcs file request
  *          envGcsApiKeyJsonPath:
  *          envGcsApiKeyJsonPath:
  *            type: string
  *            type: string
  *            description: Path of the JSON file that contains service account key to authenticate to GCP API
  *            description: Path of the JSON file that contains service account key to authenticate to GCP API
@@ -171,6 +177,7 @@ module.exports = (crowi) => {
       body('gcsApiKeyJsonPath').trim(),
       body('gcsApiKeyJsonPath').trim(),
       body('gcsBucket').trim(),
       body('gcsBucket').trim(),
       body('gcsUploadNamespace').trim(),
       body('gcsUploadNamespace').trim(),
+      body('gcsIsEnabledInternalStreamSystem').if(value => value != null).isBoolean(),
       body('s3Region').trim().if(value => value !== '').matches(/^[a-z]+-[a-z]+-\d+$/)
       body('s3Region').trim().if(value => value !== '').matches(/^[a-z]+-[a-z]+-\d+$/)
         .withMessage((value, { req }) => req.t('validation.aws_region')),
         .withMessage((value, { req }) => req.t('validation.aws_region')),
       body('s3CustomEndpoint').trim().if(value => value !== '').matches(/^(https?:\/\/[^/]+|)$/)
       body('s3CustomEndpoint').trim().if(value => value !== '').matches(/^(https?:\/\/[^/]+|)$/)
@@ -178,6 +185,7 @@ module.exports = (crowi) => {
       body('s3Bucket').trim(),
       body('s3Bucket').trim(),
       body('s3AccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
       body('s3AccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
       body('s3SecretAccessKey').trim(),
       body('s3SecretAccessKey').trim(),
+      body('s3IsEnabledInternalStreamSystem').if(value => value != null).isBoolean(),
     ],
     ],
     pluginSetting: [
     pluginSetting: [
       body('isEnabledPlugins').isBoolean(),
       body('isEnabledPlugins').isBoolean(),
@@ -581,6 +589,7 @@ module.exports = (crowi) => {
       requestParams['gcs:apiKeyJsonPath'] = req.body.gcsApiKeyJsonPath;
       requestParams['gcs:apiKeyJsonPath'] = req.body.gcsApiKeyJsonPath;
       requestParams['gcs:bucket'] = req.body.gcsBucket;
       requestParams['gcs:bucket'] = req.body.gcsBucket;
       requestParams['gcs:uploadNamespace'] = req.body.gcsUploadNamespace;
       requestParams['gcs:uploadNamespace'] = req.body.gcsUploadNamespace;
+      requestParams['gcs:isEnabledInternalStreamSystem'] = req.body.gcsIsEnabledInternalStreamSystem;
     }
     }
 
 
     if (fileUploadType === 'aws') {
     if (fileUploadType === 'aws') {
@@ -589,6 +598,7 @@ module.exports = (crowi) => {
       requestParams['aws:s3Bucket'] = req.body.s3Bucket;
       requestParams['aws:s3Bucket'] = req.body.s3Bucket;
       requestParams['aws:s3AccessKeyId'] = req.body.s3AccessKeyId;
       requestParams['aws:s3AccessKeyId'] = req.body.s3AccessKeyId;
       requestParams['aws:s3SecretAccessKey'] = req.body.s3SecretAccessKey;
       requestParams['aws:s3SecretAccessKey'] = req.body.s3SecretAccessKey;
+      requestParams['aws:isEnabledInternalStreamSystem'] = req.body.s3IsEnabledInternalStreamSystem;
     }
     }
 
 
     try {
     try {
@@ -604,6 +614,7 @@ module.exports = (crowi) => {
         responseParams.gcsApiKeyJsonPath = crowi.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath');
         responseParams.gcsApiKeyJsonPath = crowi.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath');
         responseParams.gcsBucket = crowi.configManager.getConfig('crowi', 'gcs:bucket');
         responseParams.gcsBucket = crowi.configManager.getConfig('crowi', 'gcs:bucket');
         responseParams.gcsUploadNamespace = crowi.configManager.getConfig('crowi', 'gcs:uploadNamespace');
         responseParams.gcsUploadNamespace = crowi.configManager.getConfig('crowi', 'gcs:uploadNamespace');
+        responseParams.gcsIsEnabledInternalStreamSystem = crowi.configManager.getConfig('crowi', 'gcs:isEnabledInternalStreamSystem');
       }
       }
 
 
       if (fileUploadType === 'aws') {
       if (fileUploadType === 'aws') {
@@ -612,6 +623,7 @@ module.exports = (crowi) => {
         responseParams.s3Bucket = crowi.configManager.getConfig('crowi', 'aws:s3Bucket');
         responseParams.s3Bucket = crowi.configManager.getConfig('crowi', 'aws:s3Bucket');
         responseParams.s3AccessKeyId = crowi.configManager.getConfig('crowi', 'aws:s3AccessKeyId');
         responseParams.s3AccessKeyId = crowi.configManager.getConfig('crowi', 'aws:s3AccessKeyId');
         responseParams.s3SecretAccessKey = crowi.configManager.getConfig('crowi', 'aws:s3SecretAccessKey');
         responseParams.s3SecretAccessKey = crowi.configManager.getConfig('crowi', 'aws:s3SecretAccessKey');
+        responseParams.s3IsEnabledInternalStreamSystem = crowi.configManager.getConfig('crowi', 'aws:isEnabledInternalStreamSystem');
       }
       }
 
 
       return res.apiv3({ responseParams });
       return res.apiv3({ responseParams });

+ 12 - 0
src/server/service/config-loader.js

@@ -332,6 +332,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.STRING,
     type:    TYPES.STRING,
     default: null,
     default: null,
   },
   },
+  S3_IS_ENABLED_INTERNAL_STREAM_SYSTEM: {
+    ns:      'crowi',
+    key:     'aws:isEnabledInternalStreamSystem',
+    type:    TYPES.BOOLEAN,
+    default: false,
+  },
   GCS_API_KEY_JSON_PATH: {
   GCS_API_KEY_JSON_PATH: {
     ns:      'crowi',
     ns:      'crowi',
     key:     'gcs:apiKeyJsonPath',
     key:     'gcs:apiKeyJsonPath',
@@ -350,6 +356,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.STRING,
     type:    TYPES.STRING,
     default: null,
     default: null,
   },
   },
+  GCS_IS_ENABLED_INTERNAL_STREAM_SYSTEM: {
+    ns:      'crowi',
+    key:     'gcs:isEnabledInternalStreamSystem',
+    type:    TYPES.BOOLEAN,
+    default: false,
+  },
   GCS_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
   GCS_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
     ns:      'crowi',
     ns:      'crowi',
     key:     'gcs:useOnlyEnvVarsForSomeOptions',
     key:     'gcs:useOnlyEnvVarsForSomeOptions',

+ 1 - 2
src/server/service/file-uploader/aws.js

@@ -73,8 +73,7 @@ module.exports = function(crowi) {
   };
   };
 
 
   lib.canRespond = function() {
   lib.canRespond = function() {
-    // TODO retrieve bool by getConfig
-    return true;
+    return !this.configManager.getConfig('crowi', 'aws:isEnabledInternalStreamSystem');
   };
   };
 
 
   lib.respond = async function(res, attachment) {
   lib.respond = async function(res, attachment) {

+ 1 - 2
src/server/service/file-uploader/gcs.js

@@ -51,8 +51,7 @@ module.exports = function(crowi) {
   };
   };
 
 
   lib.canRespond = function() {
   lib.canRespond = function() {
-    // TODO retrieve bool by getConfig
-    return true;
+    return !this.configManager.getConfig('crowi', 'gcs:isEnabledInternalStreamSystem');
   };
   };
 
 
   lib.respond = async function(res, attachment) {
   lib.respond = async function(res, attachment) {