-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for secrets in the App Hosting emulator #8305
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
10 commits
Select commit
Hold shift + click to select a range
701b946
Add support for secrets in the App Hosting emulator
inlined 2746d13
Formatter
inlined e9f69e4
Changelog
inlined d7d275d
Reformat changelog
inlined 9c84b3e
Merge branch 'master' into inlined.fah-emulator-secrets
inlined d5d3ea7
Convert Java-style TS to idiomatic TS to fix bug & reduce fragility
inlined d222f5f
Restore accidentally removed existence check
inlined 7d1ea21
PR feedback
inlined ed359ba
Merge branch 'master' into inlined.fah-emulator-secrets
inlined df0cd69
PR feedback
inlined 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,195 +1,52 @@ | ||||||
| import { expect } from "chai"; | ||||||
| import { AppHostingYamlConfig } from "./yaml"; | ||||||
|
|
||||||
| describe("yaml", () => { | ||||||
| describe("environment variables", () => { | ||||||
| let apphostingYaml: AppHostingYamlConfig; | ||||||
| beforeEach(() => { | ||||||
| apphostingYaml = AppHostingYamlConfig.empty(); | ||||||
| }); | ||||||
|
|
||||||
| it("adds environment variables and retrieves them correctly", () => { | ||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "TEST_1", | ||||||
| value: "value_1", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "TEST_2", | ||||||
| value: "value_2", | ||||||
| }); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.environmentVariables)).to.equal( | ||||||
| JSON.stringify([ | ||||||
| { | ||||||
| variable: "TEST_1", | ||||||
| value: "value_1", | ||||||
| }, | ||||||
| { | ||||||
| variable: "TEST_2", | ||||||
| value: "value_2", | ||||||
| }, | ||||||
| ]), | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| it("overwrites stored environment variable if another is added with same name", () => { | ||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "TEST", | ||||||
| value: "value", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "TEST", | ||||||
| value: "overwritten_value", | ||||||
| }); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.environmentVariables)).to.equal( | ||||||
| JSON.stringify([{ variable: "TEST", value: "overwritten_value" }]), | ||||||
| ); | ||||||
| describe("merge", () => { | ||||||
| it("merges incoming apphosting yaml config with precendence", () => { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically incorrect, no? It's about merging apphosting.local.yaml over apphosting.emulators.yaml over apphosting.yaml |
||||||
| const apphostingYaml = AppHostingYamlConfig.empty(); | ||||||
| apphostingYaml.env = { | ||||||
| ENV_1: { value: "env_1" }, | ||||||
| ENV_2: { value: "env_2" }, | ||||||
| SECRET: { secret: "secret_1" }, | ||||||
| }; | ||||||
|
|
||||||
| const incomingAppHostingYaml = AppHostingYamlConfig.empty(); | ||||||
| incomingAppHostingYaml.env = { | ||||||
| ENV_1: { value: "incoming_env_1" }, | ||||||
| ENV_3: { value: "incoming_env_3" }, | ||||||
| SECRET_2: { value: "incoming_secret_2" }, | ||||||
| }; | ||||||
|
|
||||||
| apphostingYaml.merge(incomingAppHostingYaml); | ||||||
| expect(apphostingYaml.env).to.deep.equal({ | ||||||
| ENV_1: { value: "incoming_env_1" }, | ||||||
| ENV_2: { value: "env_2" }, | ||||||
| ENV_3: { value: "incoming_env_3" }, | ||||||
| SECRET: { secret: "secret_1" }, | ||||||
| SECRET_2: { value: "incoming_secret_2" }, | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| describe("secrets", () => { | ||||||
| let apphostingYaml: AppHostingYamlConfig; | ||||||
| beforeEach(() => { | ||||||
| apphostingYaml = AppHostingYamlConfig.empty(); | ||||||
| }); | ||||||
|
|
||||||
| it("adds environment variables and retrieves them correctly", () => { | ||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST_1", | ||||||
| secret: "value_1", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST_2", | ||||||
| secret: "value_2", | ||||||
| }); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.secrets)).to.equal( | ||||||
| JSON.stringify([ | ||||||
| { | ||||||
| variable: "TEST_1", | ||||||
| secret: "value_1", | ||||||
| }, | ||||||
| { | ||||||
| variable: "TEST_2", | ||||||
| secret: "value_2", | ||||||
| }, | ||||||
| ]), | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| it("overwrites stored environment variable if another is added with same name", () => { | ||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST", | ||||||
| secret: "value", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST", | ||||||
| secret: "overwritten_value", | ||||||
| }); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.secrets)).to.equal( | ||||||
| JSON.stringify([{ variable: "TEST", secret: "overwritten_value" }]), | ||||||
| ); | ||||||
| }); | ||||||
|
|
||||||
| it("should clear secrets when clearSecrets is called", () => { | ||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST", | ||||||
| secret: "value", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "TEST", | ||||||
| secret: "overwritten_value", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.clearSecrets(); | ||||||
| expect(JSON.stringify(apphostingYaml.secrets)).to.equal(JSON.stringify([])); | ||||||
| }); | ||||||
| }); | ||||||
|
|
||||||
| describe("merge", () => { | ||||||
| let apphostingYaml: AppHostingYamlConfig; | ||||||
| beforeEach(() => { | ||||||
| apphostingYaml = AppHostingYamlConfig.empty(); | ||||||
| }); | ||||||
|
|
||||||
| it("merges incoming apphosting yaml config with precendence", () => { | ||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "ENV_1", | ||||||
| value: "env_1", | ||||||
| }); | ||||||
| apphostingYaml.addEnvironmentVariable({ | ||||||
| variable: "ENV_2", | ||||||
| value: "env_2", | ||||||
| }); | ||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "SECRET_1", | ||||||
| secret: "secret_1", | ||||||
| }); | ||||||
| apphostingYaml.addSecret({ | ||||||
| variable: "SECRET_2", | ||||||
| secret: "secret_2", | ||||||
| }); | ||||||
|
|
||||||
| const incomingAppHostingYaml = AppHostingYamlConfig.empty(); | ||||||
| incomingAppHostingYaml.addEnvironmentVariable({ | ||||||
| variable: "ENV_1", | ||||||
| value: "incoming_env_1", | ||||||
| }); | ||||||
| incomingAppHostingYaml.addEnvironmentVariable({ | ||||||
| variable: "ENV_3", | ||||||
| value: "incoming_env_3", | ||||||
| }); | ||||||
| incomingAppHostingYaml.addSecret({ | ||||||
| variable: "SECRET_2", | ||||||
| secret: "incoming_secret_1", | ||||||
| }); | ||||||
| incomingAppHostingYaml.addSecret({ | ||||||
| variable: "SECRET_3", | ||||||
| secret: "incoming_secret_3", | ||||||
| }); | ||||||
|
|
||||||
| apphostingYaml.merge(incomingAppHostingYaml); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.environmentVariables)).to.equal( | ||||||
| JSON.stringify([ | ||||||
| { | ||||||
| variable: "ENV_1", | ||||||
| value: "incoming_env_1", | ||||||
| }, | ||||||
| { | ||||||
| variable: "ENV_2", | ||||||
| value: "env_2", | ||||||
| }, | ||||||
| { | ||||||
| variable: "ENV_3", | ||||||
| value: "incoming_env_3", | ||||||
| }, | ||||||
| ]), | ||||||
| ); | ||||||
|
|
||||||
| expect(JSON.stringify(apphostingYaml.secrets)).to.equal( | ||||||
| JSON.stringify([ | ||||||
| { | ||||||
| variable: "SECRET_1", | ||||||
| secret: "secret_1", | ||||||
| }, | ||||||
| { | ||||||
| variable: "SECRET_2", | ||||||
| secret: "incoming_secret_1", | ||||||
| }, | ||||||
| { | ||||||
| variable: "SECRET_3", | ||||||
| secret: "incoming_secret_3", | ||||||
| }, | ||||||
| ]), | ||||||
| ); | ||||||
| it("conditionally allows secrets to become plaintext", () => { | ||||||
| const apphostingYaml = AppHostingYamlConfig.empty(); | ||||||
| apphostingYaml.env = { | ||||||
| API_KEY: { secret: "api_key" }, | ||||||
| }; | ||||||
|
|
||||||
| const incomingYaml = AppHostingYamlConfig.empty(); | ||||||
| incomingYaml.env = { | ||||||
| API_KEY: { value: "plaintext" }, | ||||||
| }; | ||||||
|
|
||||||
| expect(() => | ||||||
| apphostingYaml.merge(incomingYaml, /* alllowSecretsToBecomePlaintext */ false), | ||||||
| ).to.throw("Cannot convert secret to plaintext in apphosting yaml"); | ||||||
|
|
||||||
| expect(() => | ||||||
| apphostingYaml.merge(incomingYaml, /* alllowSecretsToBecomePlaintext */ true), | ||||||
| ).to.not.throw(); | ||||||
| expect(apphostingYaml.env).to.deep.equal({ | ||||||
| API_KEY: { value: "plaintext" }, | ||||||
| }); | ||||||
| }); | ||||||
| }); | ||||||
Oops, something went wrong.
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.
Can delete this comment