Skip to content

Commit 3a96a27

Browse files
committed
moved upgrade script of upgrade_bucket_policy to 5.15.6 dir
* The script was misplaced in 5.14.0 dir * Also fixed the script to be idempotent, to avoid failures if a manual fix was applied Signed-off-by: Danny Zaken <[email protected]>
1 parent 7b46193 commit 3a96a27

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/upgrade/upgrade_scripts/5.14.0/upgrade_bucket_policy.js renamed to src/upgrade/upgrade_scripts/5.15.6/upgrade_bucket_policy.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
const util = require('util');
55
const { OP_NAME_TO_ACTION } = require('../../../endpoint/s3/s3_bucket_policy_utils');
6+
const _ = require('lodash');
7+
68

79
function _create_actions_map() {
810
const actions_map = new Map();
@@ -19,27 +21,29 @@ function _create_actions_map() {
1921
async function run({ dbg, system_store, system_server }) {
2022

2123
try {
22-
dbg.log0('Starting bucket policy upgrade...');
24+
console.log('Starting bucket policy upgrade...');
2325
const buckets = [];
2426
const actions_map = _create_actions_map();
2527
for (const bucket of system_store.data.buckets) {
2628
//Do not update if there are no bucket policy.
2729
if (!bucket.s3_policy) continue;
2830

29-
const new_policy = {};
30-
if (bucket.s3_policy.version) new_policy.Version = bucket.s3_policy.version;
31-
32-
new_policy.Statement = bucket.s3_policy.statement.map(statement => ({
33-
Effect: statement.effect === 'allow' ? 'Allow' : 'Deny',
34-
Action: statement.action.map(action => actions_map.get(action)),
35-
Principal: { AWS: statement.principal },
36-
Resource: statement.resource,
37-
Sid: statement.sid
38-
}));
39-
buckets.push({
40-
_id: bucket._id,
41-
s3_policy: new_policy,
42-
});
31+
32+
if (_.isUndefined(bucket.s3_policy.Statement)) {
33+
const new_policy = {};
34+
if (bucket.s3_policy.version) new_policy.Version = bucket.s3_policy.version;
35+
new_policy.Statement = bucket.s3_policy.statement.map(statement => ({
36+
Effect: statement.effect === 'allow' ? 'Allow' : 'Deny',
37+
Action: statement.action.map(action => actions_map.get(action)),
38+
Principal: { AWS: statement.principal },
39+
Resource: statement.resource,
40+
Sid: statement.sid
41+
}));
42+
buckets.push({
43+
_id: bucket._id,
44+
s3_policy: new_policy,
45+
});
46+
}
4347
}
4448

4549
if (buckets.length > 0) {

0 commit comments

Comments
 (0)