-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable name transformation for environment variables (#111)
- Loading branch information
1 parent
8e3f9d4
commit ff26a0a
Showing
16 changed files
with
1,140 additions
and
1,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Builds | ||
description: Builds the repository and assumes the AWS IAM role for testing | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Install dependencies | ||
run: npm ci | ||
shell: bash | ||
- name: Build the dist folder | ||
run: npm run build | ||
shell: bash | ||
- name: Determine role to assume | ||
id: role-to-assume | ||
run: | | ||
if [ "${{ github.repository_owner }}" == "aws-actions" ]; then | ||
# Use prod role for the PRs running against the main repo | ||
echo "arn=arn:aws:iam::339713045997:role/GithubActionsRole" >> "$GITHUB_OUTPUT" | ||
else | ||
# Use beta role for the PRs running against engineer forks | ||
echo "arn=arn:aws:iam::654654453185:role/GithubActionsRole" >> "$GITHUB_OUTPUT" | ||
fi | ||
shell: bash | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ steps.role-to-assume.outputs.arn }} | ||
aws-region: us-east-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,134 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
tests: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
name: Run Tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Run Unit Tests | ||
run: | | ||
npm ci | ||
npm run test | ||
- name: Codecov | ||
uses: codecov/codecov-action@v4.3.0 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
uppercase-transformation-integration-test: | ||
runs-on: ubuntu-latest | ||
needs: unit-tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build | ||
run: npm run build | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
uses: ./.github/actions/build | ||
- name: Act | ||
uses: ./ | ||
with: | ||
role-to-assume: arn:aws:iam::339713045997:role/GithubActionsRole | ||
aws-region: us-east-1 | ||
- name: Integration Tests Act | ||
name-transformation: uppercase | ||
parse-json-secrets: true | ||
secret-ids: | | ||
SampleSecret1 | ||
/special/chars/secret | ||
0/special/chars/secret | ||
PrefixSecret* | ||
JsonSecret | ||
SAMPLESECRET1_ALIAS, SampleSecret1 | ||
- name: Assert | ||
run: npm run integration-test __integration_tests__/name_transformation/uppercase.test.ts | ||
|
||
lowercase-transformation-integration-test: | ||
runs-on: ubuntu-latest | ||
needs: unit-tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build | ||
uses: ./.github/actions/build | ||
- name: Act | ||
uses: ./ | ||
with: | ||
name-transformation: lowercase | ||
parse-json-secrets: true | ||
secret-ids: | | ||
SampleSecret1 | ||
SAMPLESECRET1_ALIAS, SampleSecret1 | ||
/special/chars/secret | ||
0/special/chars/secret | ||
PrefixSecret* | ||
JsonSecret | ||
SampleSecret1 | ||
/special/chars/secret | ||
0/special/chars/secret | ||
PrefixSecret* | ||
JsonSecret | ||
samplesecret1_alias, SampleSecret1 | ||
- name: Assert | ||
run: npm run integration-test __integration_tests__/name_transformation/lowercase.test.ts | ||
|
||
none-transformation-integration-test: | ||
runs-on: ubuntu-latest | ||
needs: unit-tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build | ||
uses: ./.github/actions/build | ||
- name: Act | ||
uses: ./ | ||
with: | ||
name-transformation: none | ||
parse-json-secrets: true | ||
- name: Integration Tests Assert | ||
run: npm run integration-test | ||
- name: Codecov | ||
uses: codecov/codecov-action@v4 | ||
secret-ids: | | ||
SampleSecret1 | ||
/special/chars/secret | ||
0/special/chars/secret | ||
PrefixSecret* | ||
JsonSecret | ||
SampleSecret1_Alias, SampleSecret1 | ||
- name: Assert | ||
run: npm run integration-test __integration_tests__/name_transformation/none.test.ts | ||
|
||
default-name-transformation-param-integration-test: | ||
runs-on: ubuntu-latest | ||
needs: unit-tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build | ||
uses: ./.github/actions/build | ||
- name: Act | ||
uses: ./ | ||
with: | ||
parse-json-secrets: true | ||
secret-ids: | | ||
SampleSecret1 | ||
/special/chars/secret | ||
0/special/chars/secret | ||
PrefixSecret* | ||
JsonSecret | ||
SAMPLESECRET1_ALIAS, SampleSecret1 | ||
- name: Assert | ||
run: npm run integration-test __integration_tests__/name_transformation/uppercase.test.ts | ||
|
||
default-parse-json-secrets-integration-test: | ||
runs-on: ubuntu-latest | ||
needs: unit-tests | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Build | ||
uses: ./.github/actions/build | ||
- name: Act | ||
uses: ./ | ||
with: | ||
secret-ids: JsonSecret | ||
- name: Assert Default Is No Json Secrets | ||
run: npm run integration-test __integration_tests__/parse_json_secrets.test.ts |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function nameTransformationTest(transform: (secretName: string) => string) { | ||
const dataset = [ | ||
// Standard name qualified test | ||
['SampleSecret1', 'SomeSampleSecret1'], | ||
// Special characters escaping test | ||
['_special_chars_secret', 'SomeSampleSecret2'], | ||
// Secret starting with numerical character escape test | ||
['_0_special_chars_secret', 'SomeSampleSecret3'], | ||
// Prefix matching test | ||
['PrefixSecret1', 'PrefixSecret1Value'], | ||
['PrefixSecret2', 'PrefixSecret2Value'], | ||
// Json value expansion | ||
['JsonSecret_api_user', 'user'], | ||
['JsonSecret_api_key', 'key'], | ||
['JsonSecret_config_active', 'true'], | ||
// Alias test | ||
['SampleSecret1_Alias', 'SomeSampleSecret1'] | ||
].map(([secretName, expectedValue]) => [transform(secretName), expectedValue]); | ||
|
||
test.each(dataset)('Secret with name %s test', (secretName, expectedValue) => { | ||
const secretValue = process.env[secretName]; | ||
expect(secretValue).toBe(expectedValue); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nameTransformationTest } from "../name_transformation.base"; | ||
|
||
describe('Lowercased Transformation Variables Assert', () => { | ||
nameTransformationTest(secretName => secretName.toLowerCase()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nameTransformationTest } from "../name_transformation.base"; | ||
|
||
describe('No Transformation Variables Assert', () => { | ||
nameTransformationTest(secretName => secretName); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nameTransformationTest } from "../name_transformation.base"; | ||
|
||
describe('Uppercased Transformation Variables Assert', () => { | ||
nameTransformationTest(secretName => secretName.toUpperCase()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
describe('parse-json-secrets: false Variables Assert', () => { | ||
it('Has secret name, does not have json keys ', () => { | ||
expect(process.env.JSONSECRET).not.toBeUndefined(); | ||
expect(process.env.JSONSECRET_API_USER).toBeUndefined(); | ||
expect(process.env.JSONSECRET_API_KEY).toBeUndefined(); | ||
expect(process.env.JSONSECRET_CONFIG_ACTIVE).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.