diff --git a/README.md b/README.md index 4dac672..4ae5a4b 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ is unable to be retrieved. Default value: `true`. The following options apply only to the custom section as they are only used in deploy/package CLI operations: +- `enabled` - boolean: If set to false, the plugin is disabled. This is useful for local development. +Default value: `true`. - `skipValidation` - boolean: If set to true, validation of the existence of your secrets in your provider's secret store will not be performed during deployment/packaging operations. Default value: `false`. diff --git a/plugin/index.js b/plugin/index.js index 6f0b10f..2c39065 100644 --- a/plugin/index.js +++ b/plugin/index.js @@ -139,6 +139,14 @@ class ServerlessSecrets { } } + isEnabled () { + return _.get(this.serverless.service, 'custom.serverlessSecrets.enabled', true) + } + + skipValidation () { + return this.options.skipValidation || this.config.options.skipValidation || _.get(this.serverless.service, 'custom.serverlessSecrets.skipValidation', false) + } + setSecret () { let value if (this.options.file) { @@ -196,11 +204,19 @@ class ServerlessSecrets { } cleanupPackageSecrets () { + if (!this.isEnabled()) { + return + } + this.serverless.cli.log(`Cleaning up ${constants.CONFIG_FILE_NAME}`) if (fs.existsSync(constants.CONFIG_FILE_NAME)) fs.unlinkSync(constants.CONFIG_FILE_NAME) } packageSecrets () { + if (!this.isEnabled()) { + return + } + this.deployMode = true this.serverless.cli.log('Serverless Secrets beginning packaging process') this.writeConfigFile() @@ -270,6 +286,10 @@ class ServerlessSecrets { } setIamPermissions () { + if (!this.isEnabled()) { + return + } + let iamRoleStatements = _.get(this.serverless.service, 'provider.iamRoleStatements', null) if (!iamRoleStatements) { _.set(this.serverless.service, 'provider.iamRoleStatements', []) @@ -285,7 +305,7 @@ class ServerlessSecrets { } validateSecrets () { - if (this.deployMode && (this.options.skipValidation || this.config.options.skipValidation)) { + if (this.deployMode && this.skipValidation()) { return Promise.resolve() } this.serverless.cli.log('Validating secrets')