refactor: use aws-sdk-js instead of boto (#24863)

* refactor: use js instead of boto for s3put

* replace merge-electron-checksums.py with js, remove boto

* fix auth

* actually pass the env to execute()
This commit is contained in:
Jeremy Rose 2020-08-13 10:25:40 -07:00 committed by GitHub
parent 627467d08a
commit a3581aa992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 159 additions and 139 deletions

38
script/lib/s3put.js Normal file
View file

@ -0,0 +1,38 @@
/* eslint-disable camelcase */
const AWS = require('aws-sdk');
const fs = require('fs');
const path = require('path');
AWS.config.update({ region: 'us-west-2' });
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });
const args = require('minimist')(process.argv.slice(2));
let { bucket, prefix = '/', key_prefix = '', grant, _: files } = args;
if (prefix && !prefix.endsWith(path.sep)) prefix = path.resolve(prefix) + path.sep;
function filenameToKey (file) {
file = path.resolve(file);
if (file.startsWith(prefix)) file = file.substr(prefix.length);
return key_prefix + file.replace(path.sep, '/');
}
let anErrorOccurred = false;
function next (done) {
const file = files.shift();
if (!file) return done();
s3.upload({
Bucket: bucket,
Key: filenameToKey(file),
Body: fs.createReadStream(file),
ACL: grant
}, (err, data) => {
if (err) {
console.error(err);
anErrorOccurred = true;
}
next(done);
});
}
next(() => {
process.exit(anErrorOccurred ? 1 : 0);
});

View file

@ -30,8 +30,6 @@ ELECTRON_DIR = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
)
SRC_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))
BOTO_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'vendor',
'boto'))
NPM = 'npm'
if sys.platform in ['win32', 'cygwin']:
@ -199,33 +197,18 @@ def get_electron_version():
with open(version_file) as f:
return 'v' + f.read().strip()
def boto_path_dirs():
return [
os.path.join(BOTO_DIR, 'build', 'lib'),
os.path.join(BOTO_DIR, 'build', 'lib.linux-x86_64-2.7')
]
def run_boto_script(access_key, secret_key, script_name, *args):
def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
env = os.environ.copy()
env['AWS_ACCESS_KEY_ID'] = access_key
env['AWS_SECRET_ACCESS_KEY'] = secret_key
env['PYTHONPATH'] = os.path.pathsep.join(
[env.get('PYTHONPATH', '')] + boto_path_dirs())
boto = os.path.join(BOTO_DIR, 'bin', script_name)
execute([sys.executable, boto] + list(args), env)
def s3put(bucket, access_key, secret_key, prefix, key_prefix, files):
args = [
execute([
'node',
os.path.join(os.path.dirname(__file__), 's3put.js'),
'--bucket', bucket,
'--prefix', prefix,
'--key_prefix', key_prefix,
'--grant', 'public-read'
] + files
run_boto_script(access_key, secret_key, 's3put', *args)
'--grant', 'public-read',
] + files, env)
def add_exec_bit(filename):