From eb0a38fd443d3aa913a614699dc3a102b42b1117 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 1 Aug 2022 11:27:27 -0400 Subject: [PATCH] Add --s3_ignore_ssl, better S3 error messages --- config.js | 4 +++- libs/S3.js | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index de014b6..2accc9e 100644 --- a/config.js +++ b/config.js @@ -54,6 +54,7 @@ Options: --s3_signature_version S3 signature version. (default: 4) --s3_acl S3 object acl. (default: public-read) --s3_upload_everything Upload all task results to S3. (default: upload only all.zip archive) + --s3_ignore_ssl Whether to ignore SSL errors while connecting to S3. (default: false) --max_concurrency Place a cap on the max-concurrency option to use for each task. (default: no limit) --max_runtime Number of minutes (approximate) that a task is allowed to run before being forcibly canceled (timeout). (default: no limit) Log Levels: @@ -68,7 +69,7 @@ const allOpts = ["slice","help","config","odm_path","log_level","port","p", "test_skip_dems","test_drop_uploads","test_fail_tasks","test_seconds", "powercycle","token","max_images","webhook","s3_endpoint","s3_bucket", "s3_force_path_style","s3_access_key","s3_secret_key","s3_signature_version", -"s3_acl","s3_upload_everything","max_concurrency","max_runtime"]; +"s3_acl","s3_upload_everything","s3_ignore_ssl","max_concurrency","max_runtime"]; // Support for "-" or "_" style params syntax for (let k in argv){ @@ -138,6 +139,7 @@ config.s3SecretKey = argv.s3_secret_key || fromConfigFile("s3SecretKey", process config.s3SignatureVersion = argv.s3_signature_version || fromConfigFile("s3SignatureVersion", "4") config.s3ACL = argv.s3_acl || fromConfigFile("s3_acl", "public-read") config.s3UploadEverything = argv.s3_upload_everything || fromConfigFile("s3UploadEverything", false); +config.s3IgnoreSSL = argv.s3_ignore_ssl || fromConfigFile("s3IgnoreSSL", false); config.maxConcurrency = parseInt(argv.max_concurrency || fromConfigFile("maxConcurrency", 0)); config.maxRuntime = parseInt(argv.max_runtime || fromConfigFile("maxRuntime", -1)); diff --git a/libs/S3.js b/libs/S3.js index 5672e53..8d18fc3 100644 --- a/libs/S3.js +++ b/libs/S3.js @@ -23,6 +23,7 @@ const glob = require('glob'); const path = require('path'); const logger = require('./logger'); const config = require('../config'); +const https = require('https'); const si = require('systeminformation'); let s3 = null; @@ -34,8 +35,18 @@ module.exports = { initialize: function(cb){ if (config.s3Endpoint && config.s3Bucket){ + if (config.s3IgnoreSSL){ + AWS.config.update({ + httpOptions: { + agent: new https.Agent({ + rejectUnauthorized: false + }) + } + }); + } + const spacesEndpoint = new AWS.Endpoint(config.s3Endpoint); - + const s3Config = { endpoint: spacesEndpoint, signatureVersion: ('v' + config.s3SignatureVersion) || 'v4', @@ -62,7 +73,7 @@ module.exports = { logger.info("Connected to S3"); cb(); }else{ - cb(new Error("Cannot connect to S3. Check your S3 configuration: " + err.code)); + cb(new Error(`Cannot connect to S3. Check your S3 configuration: ${err.message} (${err.code})`)); } }); }else cb(); @@ -115,7 +126,7 @@ module.exports = { }, {partSize, queueSize: concurrency}, err => { if (err){ logger.debug(err); - const msg = `Cannot upload file to S3: ${err.code}, retrying... ${file.retries}`; + const msg = `Cannot upload file to S3: ${err.message} (${err.code}), retrying... ${file.retries}`; if (onOutput) onOutput(msg); if (file.retries < MAX_RETRIES){ file.retries++;