Skip to content

Commit

Permalink
Apphosting emulator: Clean up secrets when writing to apphosting.loca…
Browse files Browse the repository at this point in the history
…l.yaml (#7964)
  • Loading branch information
mathu97 authored Nov 21, 2024
1 parent c130377 commit 04b288c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/apphosting/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ export async function exportConfig(
});
}

// update apphosting.local.yaml
await localAppHostingConfig.upsertFile(localAppHostingConfigPath);
// remove secrets to avoid confusion as they are not read anyways.
localAppHostingConfig.clearSecrets();
localAppHostingConfig.upsertFile(localAppHostingConfigPath);
logger.info(`Wrote secrets as environment variables to ${APPHOSTING_LOCAL_YAML_FILE}.`);

updateOrCreateGitignore(projectRoot, [APPHOSTING_LOCAL_YAML_FILE]);
Expand Down
15 changes: 15 additions & 0 deletions src/apphosting/yaml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ describe("yaml", () => {
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", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/apphosting/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export class AppHostingYamlConfig {
this._secrets.set(secret.variable, secret);
}

clearSecrets() {
this._secrets.clear();
}

/**
* Merges this AppHostingYamlConfig with another config, the incoming config
* has precedence if there are any conflicting configurations.
Expand Down

0 comments on commit 04b288c

Please sign in to comment.