Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
`Failed to read and/or parse specified policy. Make sure it is valid JSON.`
);
}
}
// check website configuration options
// if redirectAllRequestsTo specified, no other website options can be specified
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration.html
if (options.redirectAllRequestsTo) {
const clientConfigOptions = Object.keys(options);
if (is.inArray('indexDocument', clientConfigOptions)) {
validationErrors.push('indexDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('errorDocument', clientConfigOptions)) {
validationErrors.push('errorDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('routingRules', clientConfigOptions)) {
validationErrors.push('routingRules cannot be specified with redirectAllRequestsTo');
}
if (!is.existy(options.redirectAllRequestsTo.hostName)) {
validationErrors.push(
'redirectAllRequestsTo.hostName is required if redirectAllRequestsTo is specified'
);
}
if (!is.string(options.redirectAllRequestsTo.hostName)) {
validationErrors.push('redirectAllRequestsTo.hostName must be a string');
}
try {
JSON.parse(fs.readFileSync(options.bucketPolicyFile));
} catch (e) {
validationErrors.push(
`Failed to read and/or parse specified policy. Make sure it is valid JSON.`
);
}
}
// check website configuration options
// if redirectAllRequestsTo specified, no other website options can be specified
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration.html
if (options.redirectAllRequestsTo) {
const clientConfigOptions = Object.keys(options);
if (is.inArray('indexDocument', clientConfigOptions)) {
validationErrors.push('indexDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('errorDocument', clientConfigOptions)) {
validationErrors.push('errorDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('routingRules', clientConfigOptions)) {
validationErrors.push('routingRules cannot be specified with redirectAllRequestsTo');
}
if (!is.existy(options.redirectAllRequestsTo.hostName)) {
validationErrors.push(
'redirectAllRequestsTo.hostName is required if redirectAllRequestsTo is specified'
);
}
// check website configuration options
// if redirectAllRequestsTo specified, no other website options can be specified
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-websiteconfiguration.html
if (options.redirectAllRequestsTo) {
const clientConfigOptions = Object.keys(options);
if (is.inArray('indexDocument', clientConfigOptions)) {
validationErrors.push('indexDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('errorDocument', clientConfigOptions)) {
validationErrors.push('errorDocument cannot be specified with redirectAllRequestsTo');
}
if (is.inArray('routingRules', clientConfigOptions)) {
validationErrors.push('routingRules cannot be specified with redirectAllRequestsTo');
}
if (!is.existy(options.redirectAllRequestsTo.hostName)) {
validationErrors.push(
'redirectAllRequestsTo.hostName is required if redirectAllRequestsTo is specified'
);
}
if (!is.string(options.redirectAllRequestsTo.hostName)) {
validationErrors.push('redirectAllRequestsTo.hostName must be a string');
}
if (options.redirectAllRequestsTo.protocol) {
if (!is.string(options.redirectAllRequestsTo.protocol)) {
validationErrors.push('redirectAllRequestsTo.protocol must be a string');
}
}
if (!is.existy(options.redirectAllRequestsTo.hostName)) {
validationErrors.push(
'redirectAllRequestsTo.hostName is required if redirectAllRequestsTo is specified'
);
}
if (!is.string(options.redirectAllRequestsTo.hostName)) {
validationErrors.push('redirectAllRequestsTo.hostName must be a string');
}
if (options.redirectAllRequestsTo.protocol) {
if (!is.string(options.redirectAllRequestsTo.protocol)) {
validationErrors.push('redirectAllRequestsTo.protocol must be a string');
}
if (!is.inArray(options.redirectAllRequestsTo.protocol.toLowerCase(), ['http', 'https'])) {
validationErrors.push('redirectAllRequestsTo.protocol must be either http or https');
}
}
}
if (options.routingRules) {
if (!is.array(options.routingRules)) {
validationErrors.push('routingRules must be a list');
}
options.routingRules.forEach(r => {
if (!is.existy(r.redirect)) {
validationErrors.push('redirect must be specified for each member of routingRules');
}
if (is.existy(r.redirect.replaceKeyPrefixWith) && is.existy(r.redirect.replaceKeyWith)) {
export function enumHandler(value, schema) {
const isValid = is.inArray(value, schema.enum);
if (isValid) return;
const errorText = `Value of ${NAME_PLACEHOLDER} should be within [${schema.enum.toString()}].`;
throwError(value, errorText);
}
export const inArray = (name, value, schema) => ({
isValid: is.inArray(value, schema.inArray),
errorText: `Value of ${name} should be within [${schema.inArray.toString()}].`
});