-
Notifications
You must be signed in to change notification settings - Fork 17
Major: rework environment configuration of CDK #109
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4273be3
Set up testing
simonrw 8e2c62e
Extract configureEnvironment and update implementation
simonrw b49fc51
Update readme
simonrw 3d5c37f
Add unit tests to CI
simonrw 479fb8c
Stop concurrent test runs
simonrw e30c850
Don't install packages with npm ci
simonrw 04f65b2
Remove weird repo checkout
simonrw c8597b5
Take credentials from the environment
simonrw 316a292
Regression tests allow region configuration
simonrw 58a609a
Add changelog entry
simonrw 56237d4
Propagate region if provided
simonrw dd3aaf1
Add main attribute so package install works
simonrw 06b3bdc
Review changes
simonrw d58ccca
Apply suggestions
simonrw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
name: Unit tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
inputs: | ||
node-version: | ||
required: false | ||
default: "22.x" | ||
|
||
# Only one pull-request triggered run should be executed at a time | ||
# (head_ref is only set for PR events, otherwise fallback to run_id which differs for every run). | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
unit-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js ${{ inputs.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.node-version }} | ||
|
||
- name: Install project | ||
run: | | ||
npm install | ||
|
||
- name: Run tests | ||
run: | | ||
npm run test | ||
|
||
|
This file contains hidden or 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 hidden or 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,109 @@ | ||
const { configureEnvironment, EnvironmentMisconfigurationError } = require("../src"); | ||
|
||
describe("configureEnvironment", () => { | ||
test("empty environment", () => { | ||
const env = {}; | ||
const allowListStr = ""; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "test", | ||
AWS_SECRET_ACCESS_KEY: "test", | ||
AWS_REGION: "us-east-1", | ||
AWS_DEFAULT_REGION: "us-east-1", | ||
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", | ||
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", | ||
}); | ||
}); | ||
|
||
test("custom endpoint url", () => { | ||
const env = { | ||
AWS_ENDPOINT_URL: "http://foo.bar:4567", | ||
AWS_ENDPOINT_URL_S3: "http://foo.bar:4567", | ||
}; | ||
const allowListStr = ""; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "test", | ||
AWS_SECRET_ACCESS_KEY: "test", | ||
AWS_REGION: "us-east-1", | ||
AWS_DEFAULT_REGION: "us-east-1", | ||
AWS_ENDPOINT_URL: "http://foo.bar:4567", | ||
AWS_ENDPOINT_URL_S3: "http://foo.bar:4567", | ||
}); | ||
}); | ||
|
||
test("custom endpoint url without specifying s3 url", () => { | ||
const env = { | ||
AWS_ENDPOINT_URL: "http://foo.bar:4567", | ||
}; | ||
const allowListStr = ""; | ||
expect(() => configureEnvironment(env, allowListStr)).toThrow(EnvironmentMisconfigurationError); | ||
}); | ||
|
||
test("strip extra configuration envars", () => { | ||
const env = { | ||
AWS_PROFILE: "my-profile", | ||
}; | ||
const allowListStr = ""; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "test", | ||
AWS_SECRET_ACCESS_KEY: "test", | ||
AWS_REGION: "us-east-1", | ||
AWS_DEFAULT_REGION: "us-east-1", | ||
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", | ||
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", | ||
}); | ||
}); | ||
|
||
test("allowlist of profile", () => { | ||
const env = { | ||
AWS_PROFILE: "my-profile", | ||
}; | ||
const allowListStr = "AWS_PROFILE"; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "test", | ||
AWS_SECRET_ACCESS_KEY: "test", | ||
AWS_PROFILE: "my-profile", | ||
AWS_REGION: "us-east-1", | ||
AWS_DEFAULT_REGION: "us-east-1", | ||
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", | ||
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", | ||
}); | ||
}); | ||
|
||
test("credentials overriding", () => { | ||
const env = { | ||
AWS_ACCESS_KEY_ID: "something", | ||
AWS_SECRET_ACCESS_KEY: "else", | ||
}; | ||
const allowListStr = "AWS_PROFILE,AWS_SECRET_ACCESS_KEY,AWS_ACCESS_KEY_ID"; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "something", | ||
AWS_SECRET_ACCESS_KEY: "else", | ||
AWS_REGION: "us-east-1", | ||
AWS_DEFAULT_REGION: "us-east-1", | ||
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", | ||
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", | ||
}); | ||
}); | ||
|
||
test("region overriding", () => { | ||
const env = { | ||
AWS_REGION: "eu-central-1", | ||
AWS_DEFAULT_REGION: "eu-central-1", | ||
}; | ||
const allowListStr = "AWS_REGION,AWS_DEFAULT_REGION"; | ||
configureEnvironment(env, allowListStr); | ||
expect(env).toEqual({ | ||
AWS_ACCESS_KEY_ID: "test", | ||
AWS_SECRET_ACCESS_KEY: "test", | ||
AWS_REGION: "eu-central-1", | ||
AWS_DEFAULT_REGION: "eu-central-1", | ||
AWS_ENDPOINT_URL: "http://localhost.localstack.cloud:4566", | ||
AWS_ENDPOINT_URL_S3: "http://s3.localhost.localstack.cloud:4566", | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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 @@ | ||
module.exports = { | ||
testEnvironment: "node", | ||
verbose: true, | ||
coverageDirectory: "coverage", | ||
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}"], | ||
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"], | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: same as above, newest version for that action is
v4