Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
22 changes: 21 additions & 1 deletion plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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', [])
Expand All @@ -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')
Expand Down