Skip to content

Commit ccb1056

Browse files
authored
feat: support filtering secrets by branch (#33)
1 parent 2d09ef8 commit ccb1056

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ package = "@netlify/plugin-secrets-manager"
6464
## Context based secrets
6565

6666
The plugin has support for context based secrets, to allow injecting AWS secrets only to builds with a specific deploy context.
67-
To configure the context for a secret, add a secret tag via AWS secrets manager with a name of `NETLIFY_CONTEXT` and value of `production`, `deploy-preview` or `branch-deploy`.
67+
To configure the context for a secret, add a secret tag via AWS secrets manager with a name of `NETLIFY_CONTEXT` and value of `production`, `deploy-preview`, `branch-deploy` or any branch name in your `git` repository.
68+
69+
>To learn more about deploy contexts, visit [Netlify's documentation](https://docs.netlify.com/site-deploys/overview/#deploy-contexts)
6870
6971
As a result, the plugin will inject the AWS secret only to builds with the matching deploy context.
7072

src/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ module.exports = {
6969
NETLIFY_AWS_SECRET_ACCESS_KEY: secretAccessKey,
7070
NETLIFY_AWS_DEFAULT_REGION: region = 'us-east-1',
7171
CONTEXT,
72+
HEAD,
7273
} = process.env
74+
7375
if (!accessKeyId) {
7476
return utils.build.failBuild(`Missing environment variable NETLIFY_AWS_ACCESS_KEY_ID`)
7577
}
@@ -95,12 +97,14 @@ module.exports = {
9597
return
9698
}
9799

98-
// inject only to matching context
99-
if (CONTEXT === context) {
100+
// inject only to matching context/branch
101+
const matchedContext = CONTEXT === context
102+
const matchedBranch = HEAD === context
103+
if (matchedContext || matchedBranch) {
100104
console.log(
101-
`${chalk.bold('Injecting AWS secret')} ${chalk.magenta(`${key}`)} as ${chalk.green(
102-
prefixedKey,
103-
)} to context ${chalk.yellow(context)}`,
105+
`${chalk.bold('Injecting AWS secret')} ${chalk.magenta(`${key}`)} as ${chalk.green(prefixedKey)} to ${
106+
matchedContext ? 'context' : 'branch'
107+
} ${chalk.yellow(context)}`,
104108
)
105109
/* eslint-disable-next-line no-param-reassign */
106110
netlifyConfig.build.environment[prefixedKey] = value

0 commit comments

Comments
 (0)