Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new manageResources flag will prevent plugin from creating or configu… #75

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Client {
}

_removeDeployedResources() {
let bucketName;
let bucketName, manageResources;

return this._validateConfig()
.then(() => {
bucketName = this.options.bucketName;
manageResources = this.options.manageResources;
return this.cliOptions.confirm === false
? true
: new Confirm(`Are you sure you want to delete bucket '${bucketName}'?`).run();
Expand All @@ -79,13 +80,23 @@ class Client {
return bucketUtils
.emptyBucket(this.aws, bucketName)
.then(() => {
this.serverless.cli.log(`Removing bucket...`);
return bucketUtils.deleteBucket(this.aws, bucketName);
if (manageResources === false) {
this.serverless.cli.log(
'manageResources has been set to "false". Bucket will not be deleted'
);
} else {
this.serverless.cli.log(`Removing bucket...`);
return bucketUtils.deleteBucket(this.aws, bucketName);
}
})
.then(() => {
this.serverless.cli.log(
`Success! Your files have been removed and your bucket has been deleted`
);
if (manageResources === false) {
this.serverless.cli.log(`Success! Your files have been removed`);
} else {
this.serverless.cli.log(
`Success! Your files have been removed and your bucket has been deleted`
);
}
});
} else {
this.serverless.cli.log(`Bucket does not exist`);
Expand All @@ -110,7 +121,8 @@ class Client {
indexDoc,
errorDoc,
redirectAllRequestsTo,
routingRules;
routingRules,
manageResources;

return this._validateConfig()
.then(() => {
Expand All @@ -127,6 +139,7 @@ class Client {
distributionFolder = this.options.distributionFolder || path.join('client/dist');
clientPath = path.join(this.serverless.config.servicePath, distributionFolder);
bucketName = this.options.bucketName;
manageResources = this.options.manageResources;
headerSpec = this.options.objectHeaders;
orderSpec = this.options.uploadOrder;
indexDoc = this.options.indexDocument || 'index.html';
Expand All @@ -142,13 +155,14 @@ class Client {
deployDescribe.push(
`- Upload all files from '${distributionFolder}' to bucket '${bucketName}'`
);
if (this.cliOptions['config-change'] !== false) {

if (this.cliOptions['config-change'] !== false && manageResources !== false) {
deployDescribe.push(`- Set (and overwrite) bucket '${bucketName}' configuration`);
}
if (this.cliOptions['policy-change'] !== false) {
if (this.cliOptions['policy-change'] !== false && manageResources !== false) {
deployDescribe.push(`- Set (and overwrite) bucket '${bucketName}' bucket policy`);
}
if (this.cliOptions['cors-change'] !== false) {
if (this.cliOptions['cors-change'] !== false && manageResources !== false) {
deployDescribe.push(`- Set (and overwrite) bucket '${bucketName}' CORS policy`);
}

Expand All @@ -173,12 +187,17 @@ class Client {
this.serverless.cli.log(`Deleting all objects from bucket...`);
return bucketUtils.emptyBucket(this.aws, bucketName);
} else {
if (manageResources === false) {
return BbPromise.reject(
`Bucket does not exist, and manageResources has been set to "false". Ensure that bucket exists or that all resources are deployed first`
);
}
this.serverless.cli.log(`Bucket does not exist. Creating bucket...`);
return bucketUtils.createBucket(this.aws, bucketName);
}
})
.then(() => {
if (this.cliOptions['config-change'] === false) {
if (this.cliOptions['config-change'] === false || manageResources === false) {
this.serverless.cli.log(`Retaining existing bucket configuration...`);
return BbPromise.resolve();
}
Expand All @@ -193,17 +212,18 @@ class Client {
);
})
.then(() => {
if (this.cliOptions['policy-change'] === false) {
if (this.cliOptions['policy-change'] === false || manageResources === false) {
this.serverless.cli.log(`Retaining existing bucket policy...`);
return BbPromise.resolve();
}
this.serverless.cli.log(`Configuring policy for bucket...`);
const bucketPolicyFile = this.serverless.service.custom.client.bucketPolicyFile;
const customPolicy = bucketPolicyFile && JSON.parse(fs.readFileSync(bucketPolicyFile));
const customPolicy =
bucketPolicyFile && JSON.parse(fs.readFileSync(bucketPolicyFile));
return configure.configurePolicyForBucket(this.aws, bucketName, customPolicy);
})
.then(() => {
if (this.cliOptions['cors-change'] === false) {
if (this.cliOptions['cors-change'] === false || manageResources === false) {
this.serverless.cli.log(`Retaining existing bucket CORS configuration...`);
return BbPromise.resolve();
}
Expand Down