Skip to content

Commit

Permalink
feat(TNLT-000): add support for non-public S3 buckets (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishutchinson authored Jul 28, 2020
1 parent a99a095 commit 2c005ea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
6 changes: 6 additions & 0 deletions src/bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ program
? (config.branch = options.branch)
: (config.branch = 'default');

config.remoteBucketAccess = config.remoteBucketAccess || 'public';

validateConfig(config, options.remote);

if (options.run) config.scenarios = filterToScenario(config, options.run);
Expand Down Expand Up @@ -88,6 +90,8 @@ program
if (options.browser) config.browser = options.browser;
config.branch = 'default';

config.remoteBucketAccess = config.remoteBucketAccess || 'public';

validateConfig(config, options.remote);

if (options.run) config.scenarios = filterToScenario(config, options.run);
Expand Down Expand Up @@ -124,6 +128,8 @@ program
: (config.branch = 'default');

config.remote = options.remote;
config.remoteBucketAccess = config.remoteBucketAccess || 'public';

validateConfig(config, config.remote);

if (options.run) config.scenarios = filterToScenario(config, options.run);
Expand Down
6 changes: 5 additions & 1 deletion src/configValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const mandatoryLocalFields = [
'scenarios',
'browser'
];
const mandatoryRemoteFields = ['remoteBucketName', 'remoteRegion'];
const mandatoryRemoteFields = [
'remoteBucketName',
'remoteRegion',
'remoteBucketAccess'
];

function isValid(missingConfigFields) {
if (missingConfigFields.length > 0) {
Expand Down
9 changes: 3 additions & 6 deletions src/configValidator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('The Config Validator', () => {
it('remote config returns true for valid configs', () => {
const config = {
remoteBucketName: 'aye-spy',
remoteBucketAccess: 'private',
remoteRegion: 'eu-west-1'
};
expect(isRemoteConfigValid(config)).toBe(true);
Expand Down Expand Up @@ -83,19 +84,15 @@ describe('The Config Validator', () => {
it('resolves a correct config', done => {
const config = {
remoteBucketName: 'test',
remoteBucketAccess: 'public',
remoteRegion: 'test',
gridUrl: 'http://selenium.com:4444/wd/hub',
baseline: './e2eTests/generateHtmlReport/baseline',
latest: './e2eTests/generateHtmlReport/latest',
generatedDiffs: './e2eTests/generateHtmlReport/generatedDiffs',
report: './e2eTests/generateHtmlReport/reports',
browser: 'chrome',
scenarios: [
{
url: 'http:/google.com/',
label: 'homepage'
}
]
scenarios: [{ url: 'http:/google.com/', label: 'homepage' }]
};
validateConfig(config, true).then(done);
});
Expand Down
53 changes: 28 additions & 25 deletions src/remoteActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const createRemote = config => {

const params = {
Bucket: config.remoteBucketName,
ACL: 'public-read-write',
ACL:
config.remoteBucketAccess === 'public' ? 'public-read-write' : 'private',
CreateBucketConfiguration: {
LocationConstraint: config.remoteRegion
}
Expand All @@ -37,30 +38,32 @@ const createRemote = config => {
};

const updateRemotePolicy = config => {
AWS.config.update({ region: config.remoteRegion });
const s3 = new AWS.S3();
const Policy = `{
"Version": "2008-10-17",
"Id": "AyeSpyPolicy",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${config.remoteBucketName}/*"
}
]
}`;

const params = {
Bucket: config.remoteBucketName,
Policy
};

s3.putBucketPolicy(params).promise();
if (config.remote && config.remoteBucketAccess === 'public') {
AWS.config.update({ region: config.remoteRegion });
const s3 = new AWS.S3();
const Policy = `{
"Version": "2008-10-17",
"Id": "AyeSpyPolicy",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${config.remoteBucketName}/*"
}
]
}`;

const params = {
Bucket: config.remoteBucketName,
Policy
};

return s3.putBucketPolicy(params).promise();
}
};

function createDeletionParams(filteredResults, config) {
Expand Down

0 comments on commit 2c005ea

Please sign in to comment.