Skip to content

Commit a50f0ee

Browse files
joehanmbleigh
authored andcommitted
Major refactor of functions deploy (firebase#3132)
* Adding onPoll option to operation-poller (firebase#3046) * Adds onPoll option * format and remove only * improved unit test * Typescriptify functionsDeployHelper (firebase#3059) * Typescriptifying and adding CloudFunctionTrigger type * Using funcName instead of func * formats * Typescriptifying gcp.cloudfunctions (firebase#3060) * Typescriptifying functionsConfig (firebase#3063) * Typescriptifying deploymentTool (firebase#3061) * Typescriptifying deploymentTool * Update src/deploymentTool.ts Co-authored-by: Michael Bleigh <[email protected]> Co-authored-by: Michael Bleigh <[email protected]> * Refactoring prepare stage of functions deploy (firebase#3067) * refactoring prepare setp of functions deploy to use typescript, check for failure policies, and parse function triggers * refactoring prepare setp of functions deploy to use typescript, check for failure policies, and parse function triggers * commenting out functionNamesAreValid * formats * refactoring release step of functions deploy to use typescript * Adding logic to build regional deployments * Implementing createDeploymentPlan * First round of PR feedback, removing most usages of lodash * moving function prompts into their own file * seperating out a bunch of code from functionsDeployHelper * Resolves merge conflicts * refactoring release step of functions deploy to use typescript (firebase#3071) * Implements core logic of running function deploys * Typescriptifying prepareFunctionsUpload (firebase#3064) * Typescriptifying prepareFunctionsUpload, and updating filesize package to get types * fixing merge conflict * Implementing createDeploymentPlan (firebase#3081) * refactoring release step of functions deploy to use typescript * Adding logic to build regional deployments * Implementing createDeploymentPlan * First round of PR feedback, removing most usages of lodash * moving function prompts into their own file * seperating out a bunch of code from functionsDeployHelper * round of pr fixes * adresses more pr comments, and adds some todos * cleaning up unused code * Fixing some things that were broken while merging * Fixing up the order of wait and close to ensure that queue promsies actually resolve * Format and clean up typos * refactoring error handling to be cleaner * cleaning up extera newlines * first round of pr fixes * Readding some changes that I accidenttally wiped out during a merge * Switching name to id where appropriate * fixing another bug caused by functionName vs Id * Refactor functions-delete (firebase#3110) * Refactoring functions delete to use tasks, and cleaning up old polling code * Refactoring functions delete to use tasks, and cleaning up old polling code * refactoring to use new error handling * cleanup unused imports * small style fixes * Cleaning up error reporting * Implement validation for changing trigger types, and fixes from bug bash (firebase#3131) * Implement validation for changing trigger types, and fixes from bug bash * more specifc error messages for different permutations of trigger types * fixes package.json Co-authored-by: Michael Bleigh <[email protected]>
1 parent 47c78b7 commit a50f0ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2931
-2100
lines changed

package-lock.json

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
},
8282
"dependencies": {
8383
"@google-cloud/pubsub": "^2.7.0",
84+
"@types/archiver": "^5.1.0",
85+
"@types/filesize": "^5.0.0",
8486
"abort-controller": "^3.0.0",
8587
"archiver": "^5.0.0",
8688
"body-parser": "^1.19.0",
@@ -97,7 +99,7 @@
9799
"exegesis-express": "^2.0.0",
98100
"exit-code": "^1.0.2",
99101
"express": "^4.16.4",
100-
"filesize": "^3.1.3",
102+
"filesize": "^6.1.0",
101103
"fs-extra": "^0.23.1",
102104
"glob": "^7.1.2",
103105
"google-auth-library": "^6.1.3",

src/commands/functions-delete.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/commands/functions-delete.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Command } from "../command";
2+
import * as clc from "cli-color";
3+
import * as cloudfunctions from "../gcp/cloudfunctions";
4+
import * as functionsConfig from "../functionsConfig";
5+
import { deleteFunctions } from "../functionsDelete";
6+
import * as getProjectId from "../getProjectId";
7+
import * as helper from "../functionsDeployHelper";
8+
import { prompt } from "../prompt";
9+
import { requirePermissions } from "../requirePermissions";
10+
import * as utils from "../utils";
11+
12+
export default new Command("functions:delete [filters...]")
13+
.description("delete one or more Cloud Functions by name or group name.")
14+
.option(
15+
"--region <region>",
16+
"Specify region of the function to be deleted. " +
17+
"If omitted, functions from all regions whose names match the filters will be deleted. "
18+
)
19+
.option("-f, --force", "No confirmation. Otherwise, a confirmation prompt will appear.")
20+
.before(requirePermissions, ["cloudfunctions.functions.list", "cloudfunctions.functions.delete"])
21+
.action(async (filters, options) => {
22+
if (!filters.length) {
23+
return utils.reject("Must supply at least function or group name.");
24+
}
25+
26+
const projectId = getProjectId(options);
27+
28+
// Dot notation can be used to indicate function inside of a group
29+
const filterChunks = filters.map((filter: string) => {
30+
return filter.split(".");
31+
});
32+
const config = await functionsConfig.getFirebaseConfig(options);
33+
const appEngineLocation = functionsConfig.getAppEngineLocation(config);
34+
const existingFns = await cloudfunctions.listAllFunctions(projectId);
35+
const functionsToDelete = existingFns.filter((fn) => {
36+
const regionMatches = options.region ? helper.getRegion(fn.name) === options.region : true;
37+
const nameMatches = helper.functionMatchesAnyGroup(fn.name, filterChunks);
38+
return regionMatches && nameMatches;
39+
});
40+
if (functionsToDelete.length === 0) {
41+
return utils.reject(
42+
`The specified filters do not match any existing functions in project ${clc.bold(
43+
projectId
44+
)}.`,
45+
{ exit: 1 }
46+
);
47+
}
48+
49+
const scheduledFnNamesToDelete = functionsToDelete
50+
.filter((fn) => {
51+
return fn.labels?.["deployment-scheduled"] === "true";
52+
})
53+
.map((fn) => fn.name);
54+
const fnNamesToDelete = functionsToDelete.map((fn) => fn.name);
55+
56+
let confirmDeletion = false;
57+
if (!options.force) {
58+
const deleteList = fnNamesToDelete
59+
.map((func) => {
60+
return "\t" + helper.getFunctionLabel(func);
61+
})
62+
.join("\n");
63+
confirmDeletion = await prompt(options, [
64+
{
65+
type: "confirm",
66+
name: "confirm",
67+
default: false,
68+
message:
69+
"You are about to delete the following Cloud Functions:\n" +
70+
deleteList +
71+
"\n Are you sure?",
72+
},
73+
]);
74+
}
75+
if (!confirmDeletion && !options.force) {
76+
return utils.reject("Command aborted.", { exit: 1 });
77+
}
78+
return await deleteFunctions(
79+
fnNamesToDelete,
80+
scheduledFnNamesToDelete,
81+
projectId,
82+
appEngineLocation
83+
);
84+
});

src/deploy/functions/checkIam.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { bold } from "cli-color";
33

44
import { debug } from "../../logger";
55
import * as track from "../../track";
6-
import { getReleaseNames, getFunctionsInfo, getFilterGroups } from "../../functionsDeployHelper";
6+
import { getReleaseNames, getFilterGroups } from "../../functionsDeployHelper";
7+
import { CloudFunctionTrigger } from "./deploymentPlanner";
78
import { FirebaseError } from "../../error";
89
import { testIamPermissions, testResourceIamPermissions } from "../../gcp/iam";
910

@@ -50,18 +51,13 @@ export async function checkServiceAccountIam(projectId: string): Promise<void> {
5051
* @param options The command-wide options object.
5152
* @param payload The deploy payload.
5253
*/
53-
export async function checkHttpIam(
54-
context: { projectId: string; existingFunctions: { name: string }[] },
55-
options: unknown,
56-
payload: { functions: { triggers: { name: string; httpsTrigger?: {} }[] } }
57-
): Promise<void> {
58-
const triggers = payload.functions.triggers;
59-
const functionsInfo = getFunctionsInfo(triggers, context.projectId);
60-
const filterGroups = getFilterGroups(options);
54+
export async function checkHttpIam(context: any, options: any, payload: any): Promise<void> {
55+
const functionsInfo = payload.functions.triggers;
56+
const filterGroups = context.filters || getFilterGroups(options);
6157

6258
const httpFunctionNames: string[] = functionsInfo
63-
.filter((f) => has(f, "httpsTrigger"))
64-
.map((f) => f.name);
59+
.filter((f: CloudFunctionTrigger) => has(f, "httpsTrigger"))
60+
.map((f: CloudFunctionTrigger) => f.name);
6561
const httpFunctionFullNames: string[] = getReleaseNames(httpFunctionNames, [], filterGroups);
6662
const existingFunctionFullNames: string[] = context.existingFunctions.map(
6763
(f: { name: string }) => f.name

src/deploy/functions/createOrUpdateSchedulesAndTopics.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)