Skip to content
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

Release CF3's support for environment variables and secrets #4149

Merged
merged 14 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove preview flag, add option to disable dotenv support. (#4022)
Preparing for launching dotenv support for CF3.

At launch, CF3 environment variables support will default to picking up dotenv file if any, without need for preview flag.
  • Loading branch information
taeold committed Feb 8, 2022
commit e799549bb4fde7b67e73edd996512349b98ecbb3
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for specifying environment variable of CF3 function using dotenv.
4 changes: 1 addition & 3 deletions src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ module.exports = function (client) {
client.functions = {};
client.functions.config = {};
client.functions.config.clone = loadCommand("functions-config-clone");
if (previews.dotenv) {
client.functions.config.export = loadCommand("functions-config-export");
}
client.functions.config.export = loadCommand("functions-config-export");
client.functions.config.get = loadCommand("functions-config-get");
client.functions.config.set = loadCommand("functions-config-set");
client.functions.config.unset = loadCommand("functions-config-unset");
Expand Down
4 changes: 2 additions & 2 deletions src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function hasUserConfig(config: Record<string, unknown>): boolean {
}

function hasDotenv(opts: functionsEnv.UserEnvsOpts): boolean {
return previews.dotenv && functionsEnv.hasUserEnvs(opts);
return functionsEnv.hasUserEnvs(opts);
}

export async function prepare(
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function prepare(
const runtimeConfig = await getFunctionsConfig(context);

const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
const userEnvOpt = {
const userEnvOpt: functionsEnv.UserEnvsOpts = {
functionsSource: sourceDir,
projectId: projectId,
projectAlias: options.projectAlias,
Expand Down
4 changes: 0 additions & 4 deletions src/functions/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ export function loadUserEnvs({
projectAlias,
isEmulator,
}: UserEnvsOpts): Record<string, string> {
if (!previews.dotenv) {
return {};
}

const envFiles = findEnvfiles(functionsSource, projectId, projectAlias, isEmulator);
if (envFiles.length == 0) {
return {};
Expand Down
2 changes: 0 additions & 2 deletions src/previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface PreviewFlags {
functionsv2: boolean;
golang: boolean;
deletegcfartifacts: boolean;
dotenv: boolean;
artifactregistry: boolean;
}

Expand All @@ -22,7 +21,6 @@ export const previews: PreviewFlags = {
functionsv2: false,
golang: false,
deletegcfartifacts: false,
dotenv: false,
artifactregistry: false,

...(configstore.get("previews") as Partial<PreviewFlags>),
Expand Down
14 changes: 4 additions & 10 deletions src/test/functions/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { sync as rimraf } from "rimraf";
import { expect } from "chai";

import * as env from "../../functions/env";
import { previews } from "../../previews";

describe("functions/env", () => {
describe("parse", () => {
Expand Down Expand Up @@ -248,17 +247,12 @@ FOO=foo
fs.writeFileSync(path.join(sourceDir, filename), data);
}
};
const projectInfo = { projectId: "my-project", projectAlias: "dev" };
const projectInfo: Omit<env.UserEnvsOpts, "functionsSource"> = {
projectId: "my-project",
projectAlias: "dev",
};
let tmpdir: string;

before(() => {
previews.dotenv = true;
});

after(() => {
previews.dotenv = false;
});

beforeEach(() => {
tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), "test"));
});
Expand Down